No diagram of how the PIC16F877A was actually connected: the only special things were the ceramic resonator that I used to keep it at a specific frequency (the PIC16F877A unfortunately does not have an internal clock) and the diode that I used to share pins with the ICSP circuitry.
This article concerns the code for the calculator I built.
By now a lot of features of my code should be recognizable. The initialization of the system is generally the same, both of the LCD display as well as the rest of the system. The code starts defining icons used on the display: the HD44780 allows user definable characters, and here they are defined and read. Then there is the keymap, which maps the scanlines of the keyboard to actual values. After initialization, the following steps happen:
1. Day and month are read by sending their locations in the DS1302 and calling TIMERead which retrieves that value.
2. In the birthday loop ROMretrieveword is used to retrieve the next birthday, which is then compared with the current date to see if the name associated with this birthday should be displayed.
3. After this done it waits for a random key to be pressed, indicating that the birthdays have been viewed. After this the birthdays are not displayed until the calculator is turned off and on again.
4. At this point it reaches the MainLoop where the menu is displayed and the user can use a key to select an item from the menu. The menu has groups of 3, representing the lines on the keypad. This interface has failed in all my user tests, but it works for me. You might want to find a better organization, though. The menu options are 1 to display the time, 2 to set the time, 3 to use the calculator and 4 to use the address book.
The addressbook starts at MainContacts:
1. The LCD display is cleared.
2. ROMretrieveword is used to skip the birthday.
3. If this was the last contact, go back to the main menu.
4. Display the first line of the contact (which is the name).
5. Wait for a key press.
6. If it is 2, skip the next parts of the address and continue at 2.
7. Show rest of address and return to main menu.
The calculator starts at MainCalculator. The menu works the same as the main menu. Some of the keys on the keyboard (backspace, +, +/- and =) have short cuts. At any point # can be used to access a menu with additional features. The most remarkable aspect of the calculator is the method of storage: the numbers are stored as they would be displayed, in the decimal system. All calculations are done using the decimal system as well, using the mechanisms that are taught to children. Not efficient in either memory and space, but quite readable and very easy to convert between keyboard input and display, which was my biggest concern.
A few other routines that require mentioning are the keypad read routine, which always checks for *. If * is pressed, the system jumps to the main menu, regardless of what state it is in. This is a very useful shortcut for the user, but is a good example of how code should not be written. Another aspect of the keypad that is interesting is how it debounces. The other interesting aspect is the way data is stored. The data is not stored in an external memory, like with the GPS system, but
uses the main memory of the PIC16F877A. It has 8K of 14 bit wide memory, and using clever tricks we can store 12K of address data and birthdays in this memory. I wrote a separate JAVA program to cover this address compression.
1 opmerking:
Peace be with you
Een reactie posten