Now that we can identify the patterns we have to have a way of storing them. There are essentially three things I want to do:

  • store a dot

  • store a dash

  • reset the storage

I have decided to implement each of these actions with an individual function. While this is probably not the most efficient way of writing the program it is clearer than most, and is the reason why I am doing it this way. There is very often a trade off between clarity of code and speed and efficiency. In this case speed is not a problem and I doubt our program will end up filling the memory of the PICmicro, so I am going to write the code this way. In fact it is only on very rare occasions that I will bend the code away from clarity to wring the last ounce of performance out of a system.

The reset function sets the length and pattern variables to 0 for the start of a new morse item. Note that I am using global variables for the length and pattern, this is because I want all the functions to be able to access them.

When I store a dot or dash I shift the existing pattern to the left to make room for the new item. This "building up a final pattern" is something we saw when we were reading in a decimal number for our lock.