I began writing a simple routine for reading and writing smartcards into the PIC EEPROM memory, when i decided to make it more fancy. I planned to use only 2 buttons, but eventually i need all 3 buttons for the operations. The 4 SMD LEDs are used for the EEPROM card memory positions. So, let's name the buttons and the LEDs:
During prototyping, i soldered the 5-wire strip for the ICSP. Button 1 is the mode selection button. With this button you can scroll through the 2 main modes: the add card mode and the delete card mode. Button 2 is the memory selection button. By pressing this button you can scroll through the 4 memory positions. Finally, button 3 is the enter.
There is also another LED, a bi-color red-green LED. This LED is not mounted on the PCB because it must be visible to the operator. This LED turns GREEN if the correct card is inserted into the slot, and turns RED if a wrong card is in the slot. Additionally, this LED takes active part during memory operations.
The memory operations
1. Add Card
To go into the Add Card mode, press button 1 for some 3 seconds. The bi-color LED turns GREEN and the first free memory is indicated via the 4 memory LEDs. If there is no free memory position, then the 4 LEDs will flash some times and the controller will return to the standby mode. When in Add Mode, press the button 2 to scroll through the free memory positions, and select the one you want to store the card. Then, put the card into the slot and press button 3 for 1 second. If the card is valid, the memory LEDs will run an animation and the card will be stored into the selected memory position. You can only add new cards into empty memory positions. At any time you can exit this mode by pressing button 1 for 2 seconds.
2. Delete Card
To go into the Delete Mode, press button 1 for some 3 seconds to go into the Add Mode, and keep it pressed for another 2 seconds. The bi-color LED will switch from GREEN to RED indicating that you are in the Delete Mode. The first occupied EEPROM memory is then indicated via the 4 memory LEDs. If all four EEPROM memories are empty, the memory LEDs will flash some times and the controller will return to the standby mode. While in Delete Mode, use the button 2 to scroll through the occupied EEPROM memory positions. Select the one you want to delete an press button 3 for 1 second. The memory LEDs will run an animation to indicate that this memory position is now cleared. You can only delete memory positions which have already one card stored. At any time you can exit this mode by pressing button 1 for 2 seconds.
3. Memory Status
You can see which memory positions are occupied by entering the Memory Status mode. To do so, just press button 2 for 2 seconds while in stand by mode. The bi-color LED will flash in a fast rate indicating that you are in the Memory Status mode. Then, the memory status will appear on the 4 memory LEDs. If one memory position is occupied, the corresponding LED will light.
4. Clear the complete EEPROM memory
I added this operation mainly for debugging reasons, but it might be useful during normal operation as well. This operation clears all 4 memory positions. First go into the Memory Status mode by pressing button 2 for 2 seconds. Then, press button 3 simultaneously for another 3 seconds, without releasing button 2. The 4 memory LEDs will flash and the bi-color LED will then flash RED in a fast rate, indicating that you're about to clear the EEPROM memory. If you keep the two buttons pressed for another 3 seconds, then the memory LEDs will run an animation indicating that the EEPROM memory is not empty.
Here is the video of the Smartcard reader and how it works...
The PIC program
So, here is the assembly listing and the hex file for the PIC. I use the PIC 16F1939:
Version 2: Supports the serial interface for the ADG714 board
Version 1: Supports only the relay switch