Programming the PIC
In order to make the PIC do what you want it to do, it has to be programmed. First the assembler code needs to be written, then it needs to be compiled and uploaded to the PIC.
 
Below you will find the steps taken in our assembler code for making the Smartcard reader read the bank card number from a bank card. To understand what some of these steps mean in detail, previous sections of this website need to be read first.
Assembler
Documentation & Sources
 
Assembler Source Code
Assembler Code: list of operations in error-free conditions
  1. I.Initialisation
  2.  
  3. 1.All variables that are used in the program are declared and assigned addresses.
  4. 2.Ports A, B and C are configured as in- or output.
  5. A0: Card Inserted (switch contact of the card reader)
  6. A1: RST signal for the Smartcard
  7. A2: I/O port for the Smartcard
  8. A3: Signal to the door (open or closed)
  9. B0-B7: Data ports for LCD screen
  10. C0-C3: Not used
  11. C4: Register Select for LCD screen
  12. C5: Enable Signal for LCD screen
  13. C6-C7: For serial connection with computer
  14. 3.Initialise Serial Connection, baud rate set to 2400
  15. 4.Initialise LCD screen: 8 bit mode, 2 lines, cursor hidden, clear screen
  16. 5.Put welcome message on LCD screen
  17.  
  18.  
  19. II.Card Session
 
  1. The cardreader is now ready to receive a card and read its contents.
  2.  
  3. a.Begin Card session
  4.  
  5. 1.Put “Please insert card” message in LCD screen
  6. 2.Start a new card session: wait for card to be inserted
  7. 3.When inserted, clear all variables and initialise parameters and ports
  8. 4.Check if the I/O line is set to High by card, or reject the card (wrong side error)
  9. 5.If the I/O line is High, send the Reset signal to the Smartcard
  10. 6.Write “In progress” to LCD Screen
  11.  
  12. b.Answer to Reset
  13.  
  14. 1.Wait for the ATR to begin
  15. 2.Receive the ATR
  16. 3.ATR verification
  17.  
  18. c.Acquire Bank Card Number
  19.  
  20. 1.Write progress bar on LCD screen
  21. 2.Select root DF
  22. 3.Select purse EF
  23. 4.Read purse file binary content
  24. 5.Extract Bank Card Number from the purse file content
  25.  
  26. d.Verification of Bank Card Number
  27.  
  28. 1.Transmit Bank Card Number on serial port
  29. 2.Wait for access data from computer
  30. 3.Verify access data (contains user name and access allowed/denied info)
  31. 4.Allow or disallow the user to enter
  32. on allow: print welcome message on LCD screen, including the user’s name from the database, open the door for about 5 seconds and ask the user to remove card on LCD screen
  33. on denied: write “Access Denied, remove card” to LCD screen
  34.  
  35. e.End Card Session
  36.  
  37. 1.Wait for Card removal
  38. 2.On card removal, go to §II (Card session)
 
Note: The above list of operations assumes that there are no errors in sending or receiving data from the card, as well as sending and receiving data from the serial connection. Also it contains no detail on how exactly the transfer of bytes from the card to the PIC is done and vice versa. For details on this, we refer to the .asm code file which is available at the top of this page. Some notions of assembler coding will be required to understand the code.