RDM630 RFID Module with I2C LCD

Dependencies:   mbed

Committer:
TimV
Date:
Sat May 22 20:19:03 2010 +0000
Revision:
0:b2f4150fe624

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TimV 0:b2f4150fe624 1 #include "mbed.h"
TimV 0:b2f4150fe624 2 //
TimV 0:b2f4150fe624 3 DigitalOut led1(LED1);
TimV 0:b2f4150fe624 4 DigitalOut led2(LED2);
TimV 0:b2f4150fe624 5 DigitalOut led3(LED3);
TimV 0:b2f4150fe624 6 DigitalOut led4(LED4);
TimV 0:b2f4150fe624 7 Serial RFID (p28,p27);
TimV 0:b2f4150fe624 8 I2C LCD (p9,p10);
TimV 0:b2f4150fe624 9 Serial pc (USBTX,USBRX);
TimV 0:b2f4150fe624 10 int LCD_address = 0x50; // I2C address of AL202C display
TimV 0:b2f4150fe624 11 int LCD_command = 0xFE; // Sets "command" for display
TimV 0:b2f4150fe624 12 int LCD_option = 0x00; // Used to pass value of display command ie Clear_Display
TimV 0:b2f4150fe624 13 int LCD_col = 0; // holder for column value 1 - 16
TimV 0:b2f4150fe624 14 int LCD_row = 0; // holder for row value 1 - 2
TimV 0:b2f4150fe624 15 //
TimV 0:b2f4150fe624 16 // Functions to be included in display library
TimV 0:b2f4150fe624 17 //**************************************************************************************
TimV 0:b2f4150fe624 18 //* Auto Scroll ON
TimV 0:b2f4150fe624 19 //**************************************************************************************
TimV 0:b2f4150fe624 20 void LCD_auto_scroll_On(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 21 {
TimV 0:b2f4150fe624 22 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 23 LCD_option = 0x51; // Auto Scroll On
TimV 0:b2f4150fe624 24 char cmd[2];
TimV 0:b2f4150fe624 25 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 26 cmd[1] = LCD_option; // 0x51
TimV 0:b2f4150fe624 27 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 28 }
TimV 0:b2f4150fe624 29 //
TimV 0:b2f4150fe624 30 //**************************************************************************************
TimV 0:b2f4150fe624 31 //* Auto Scroll OFF
TimV 0:b2f4150fe624 32 //**************************************************************************************
TimV 0:b2f4150fe624 33 void LCD_auto_scroll_Off(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 34 {
TimV 0:b2f4150fe624 35 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 36 LCD_option = 0x52; // Auto Scroll Off
TimV 0:b2f4150fe624 37 char cmd[2];
TimV 0:b2f4150fe624 38 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 39 cmd[1] = LCD_option; // 0x52
TimV 0:b2f4150fe624 40 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 41 }
TimV 0:b2f4150fe624 42 //
TimV 0:b2f4150fe624 43 //**************************************************************************************
TimV 0:b2f4150fe624 44 //* Clear Screen
TimV 0:b2f4150fe624 45 //**************************************************************************************
TimV 0:b2f4150fe624 46 void LCD_clear_screen(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 47 {
TimV 0:b2f4150fe624 48 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 49 LCD_option = 0x58; // Clear Screen
TimV 0:b2f4150fe624 50 char cmd[2];
TimV 0:b2f4150fe624 51 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 52 cmd[1] = LCD_option; // 0x58
TimV 0:b2f4150fe624 53 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 54 }
TimV 0:b2f4150fe624 55 //
TimV 0:b2f4150fe624 56 //**************************************************************************************
TimV 0:b2f4150fe624 57 //* Auto Line Wrap ON
TimV 0:b2f4150fe624 58 //**************************************************************************************
TimV 0:b2f4150fe624 59 void LCD_line_wrap_On(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 60 {
TimV 0:b2f4150fe624 61 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 62 LCD_option = 0x43; // Auto Line Wrap On
TimV 0:b2f4150fe624 63 char cmd[2];
TimV 0:b2f4150fe624 64 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 65 cmd[1] = LCD_option; // 0x43
TimV 0:b2f4150fe624 66 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 67 }
TimV 0:b2f4150fe624 68 //
TimV 0:b2f4150fe624 69 //**************************************************************************************
TimV 0:b2f4150fe624 70 //* Auto Line Wrap OFF
TimV 0:b2f4150fe624 71 //**************************************************************************************
TimV 0:b2f4150fe624 72 void LCD_line_wrap_Off(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 73 {
TimV 0:b2f4150fe624 74 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 75 LCD_option = 0x44; // Auto Line Wrap Off
TimV 0:b2f4150fe624 76 char cmd[2];
TimV 0:b2f4150fe624 77 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 78 cmd[1] = LCD_option; // 0x44
TimV 0:b2f4150fe624 79 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 80 }
TimV 0:b2f4150fe624 81 //
TimV 0:b2f4150fe624 82 //**************************************************************************************
TimV 0:b2f4150fe624 83 //* Go Home
TimV 0:b2f4150fe624 84 //**************************************************************************************
TimV 0:b2f4150fe624 85 void LCD_go_home(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 86 {
TimV 0:b2f4150fe624 87 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 88 LCD_option = 0x48; // Go Home
TimV 0:b2f4150fe624 89 char cmd[2];
TimV 0:b2f4150fe624 90 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 91 cmd[1] = LCD_option; // 0x48
TimV 0:b2f4150fe624 92 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 93 }
TimV 0:b2f4150fe624 94 //
TimV 0:b2f4150fe624 95 //**************************************************************************************
TimV 0:b2f4150fe624 96 //* Move Cursor Forward
TimV 0:b2f4150fe624 97 //**************************************************************************************
TimV 0:b2f4150fe624 98 void LCD_cursor_forward(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 99 {
TimV 0:b2f4150fe624 100 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 101 LCD_option = 0x4D; // Move Cursor Forward
TimV 0:b2f4150fe624 102 char cmd[2];
TimV 0:b2f4150fe624 103 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 104 cmd[1] = LCD_option; // 0x4D
TimV 0:b2f4150fe624 105 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 106 }
TimV 0:b2f4150fe624 107 //
TimV 0:b2f4150fe624 108 //**************************************************************************************
TimV 0:b2f4150fe624 109 //* Move Cursor Backward
TimV 0:b2f4150fe624 110 //**************************************************************************************
TimV 0:b2f4150fe624 111 void LCD_cursor_backward(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 112 {
TimV 0:b2f4150fe624 113 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 114 LCD_option = 0x4C; // Move Cursor Backward
TimV 0:b2f4150fe624 115 char cmd[2];
TimV 0:b2f4150fe624 116 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 117 cmd[1] = LCD_option; // 0x4C
TimV 0:b2f4150fe624 118 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 119 }
TimV 0:b2f4150fe624 120 //
TimV 0:b2f4150fe624 121 //**************************************************************************************
TimV 0:b2f4150fe624 122 //* Cursor Underline ON
TimV 0:b2f4150fe624 123 //**************************************************************************************
TimV 0:b2f4150fe624 124 void LCD_underline_on(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 125 {
TimV 0:b2f4150fe624 126 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 127 LCD_option = 0x4A; // Cursor Underline On
TimV 0:b2f4150fe624 128 char cmd[2];
TimV 0:b2f4150fe624 129 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 130 cmd[1] = LCD_option; // 0x4A
TimV 0:b2f4150fe624 131 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 132 }
TimV 0:b2f4150fe624 133 //
TimV 0:b2f4150fe624 134 //**************************************************************************************
TimV 0:b2f4150fe624 135 //* Cursor Underline OFF
TimV 0:b2f4150fe624 136 //**************************************************************************************
TimV 0:b2f4150fe624 137 void LCD_underline_off(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 138 {
TimV 0:b2f4150fe624 139 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 140 LCD_option = 0x4B; // Cursor Underline Off
TimV 0:b2f4150fe624 141 char cmd[2];
TimV 0:b2f4150fe624 142 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 143 cmd[1] = LCD_option; // 0x4B
TimV 0:b2f4150fe624 144 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 145 }
TimV 0:b2f4150fe624 146 //
TimV 0:b2f4150fe624 147 //**************************************************************************************
TimV 0:b2f4150fe624 148 //* Cursor Blinking Block ON
TimV 0:b2f4150fe624 149 //**************************************************************************************
TimV 0:b2f4150fe624 150 void LCD_blink_on(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 151 {
TimV 0:b2f4150fe624 152 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 153 LCD_option = 0x53; // Cursor Blinking Block On
TimV 0:b2f4150fe624 154 char cmd[2];
TimV 0:b2f4150fe624 155 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 156 cmd[1] = LCD_option; // 0x53
TimV 0:b2f4150fe624 157 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 158 }
TimV 0:b2f4150fe624 159 //
TimV 0:b2f4150fe624 160 //**************************************************************************************
TimV 0:b2f4150fe624 161 //* Cursor Blinking Block OFF
TimV 0:b2f4150fe624 162 //**************************************************************************************
TimV 0:b2f4150fe624 163 void LCD_blink_off(int LCD_command, int LCD_option)
TimV 0:b2f4150fe624 164 {
TimV 0:b2f4150fe624 165 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 166 LCD_option = 0x54; // Cursor Blinking Block Off
TimV 0:b2f4150fe624 167 char cmd[2];
TimV 0:b2f4150fe624 168 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 169 cmd[1] = LCD_option; // 0x54
TimV 0:b2f4150fe624 170 LCD.write(LCD_address, cmd, 2); // Send command element
TimV 0:b2f4150fe624 171 }
TimV 0:b2f4150fe624 172 //
TimV 0:b2f4150fe624 173 //**************************************************************************************
TimV 0:b2f4150fe624 174 //* Set Cursor Position
TimV 0:b2f4150fe624 175 //**************************************************************************************
TimV 0:b2f4150fe624 176 void LCD_cursor_position(int LCD_command, int LCD_option, int LCD_col, int LCD_row)
TimV 0:b2f4150fe624 177 {
TimV 0:b2f4150fe624 178 LCD_command = 0xFE; // command designator
TimV 0:b2f4150fe624 179 LCD_option = 0x47; // Cursor Blinking Block Off
TimV 0:b2f4150fe624 180 char cmd[4];
TimV 0:b2f4150fe624 181 cmd[0] = LCD_command; // 0xFE
TimV 0:b2f4150fe624 182 cmd[1] = LCD_option; // 0x47
TimV 0:b2f4150fe624 183 cmd[2] = LCD_col; // Valid = 1 - 16
TimV 0:b2f4150fe624 184 cmd[3] = LCD_row; // Valid = 1 - 2
TimV 0:b2f4150fe624 185 LCD.write(LCD_address, cmd, 4); // Send command elements
TimV 0:b2f4150fe624 186 }
TimV 0:b2f4150fe624 187 //
TimV 0:b2f4150fe624 188 //************************************************************************
TimV 0:b2f4150fe624 189 // LCD Write First Row Init Function
TimV 0:b2f4150fe624 190 //************************************************************************
TimV 0:b2f4150fe624 191 void LCD_First_Row(int LCD_address)
TimV 0:b2f4150fe624 192 {
TimV 0:b2f4150fe624 193 char letters[17];
TimV 0:b2f4150fe624 194 letters[0] = 'D';
TimV 0:b2f4150fe624 195 letters[1] = 'i';
TimV 0:b2f4150fe624 196 letters[2] = 's';
TimV 0:b2f4150fe624 197 letters[3] = 'p';
TimV 0:b2f4150fe624 198 letters[4] = 'l';
TimV 0:b2f4150fe624 199 letters[5] = 'a';
TimV 0:b2f4150fe624 200 letters[6] = 'y';
TimV 0:b2f4150fe624 201 letters[7] = '.';
TimV 0:b2f4150fe624 202 letters[8] = '.';
TimV 0:b2f4150fe624 203 letters[9] = '.';
TimV 0:b2f4150fe624 204 letters[10] = '.';
TimV 0:b2f4150fe624 205 letters[11] = ' ';
TimV 0:b2f4150fe624 206 letters[12] = 'R';
TimV 0:b2f4150fe624 207 letters[13] = 'e';
TimV 0:b2f4150fe624 208 letters[14] = 'a';
TimV 0:b2f4150fe624 209 letters[15] = 'd';
TimV 0:b2f4150fe624 210 letters[16] = 'y';
TimV 0:b2f4150fe624 211 LCD.write(LCD_address, letters, 17); // Send data elements
TimV 0:b2f4150fe624 212 }
TimV 0:b2f4150fe624 213 //
TimV 0:b2f4150fe624 214 //************************************************************************
TimV 0:b2f4150fe624 215 // LCD Write Second Row Init Function
TimV 0:b2f4150fe624 216 //************************************************************************
TimV 0:b2f4150fe624 217 void LCD_Second_Row(int LCD_address)
TimV 0:b2f4150fe624 218 {
TimV 0:b2f4150fe624 219 char letters[17];
TimV 0:b2f4150fe624 220 letters[0] = 'R';
TimV 0:b2f4150fe624 221 letters[1] = 'F';
TimV 0:b2f4150fe624 222 letters[2] = 'I';
TimV 0:b2f4150fe624 223 letters[3] = 'D';
TimV 0:b2f4150fe624 224 letters[4] = ' ';
TimV 0:b2f4150fe624 225 letters[5] = 'M';
TimV 0:b2f4150fe624 226 letters[6] = 'o';
TimV 0:b2f4150fe624 227 letters[7] = 'd';
TimV 0:b2f4150fe624 228 letters[8] = 'u';
TimV 0:b2f4150fe624 229 letters[9] = 'l';
TimV 0:b2f4150fe624 230 letters[10] = 'e';
TimV 0:b2f4150fe624 231 letters[11] = ' ';
TimV 0:b2f4150fe624 232 letters[12] = 'R';
TimV 0:b2f4150fe624 233 letters[13] = 'e';
TimV 0:b2f4150fe624 234 letters[14] = 'a';
TimV 0:b2f4150fe624 235 letters[15] = 'd';
TimV 0:b2f4150fe624 236 letters[16] = 'y';
TimV 0:b2f4150fe624 237 LCD.write(LCD_address, letters, 17); // Send data elements
TimV 0:b2f4150fe624 238 }
TimV 0:b2f4150fe624 239 //
TimV 0:b2f4150fe624 240 //************************************************************************
TimV 0:b2f4150fe624 241 // LCD Write First Row2 Init Function
TimV 0:b2f4150fe624 242 //************************************************************************
TimV 0:b2f4150fe624 243 void LCD_First2_Row(int LCD_address)
TimV 0:b2f4150fe624 244 {
TimV 0:b2f4150fe624 245 char letters[17];
TimV 0:b2f4150fe624 246 letters[0] = 'S';
TimV 0:b2f4150fe624 247 letters[1] = 'c';
TimV 0:b2f4150fe624 248 letters[2] = 'a';
TimV 0:b2f4150fe624 249 letters[3] = 'n';
TimV 0:b2f4150fe624 250 letters[4] = ' ';
TimV 0:b2f4150fe624 251 letters[5] = 'T';
TimV 0:b2f4150fe624 252 letters[6] = 'a';
TimV 0:b2f4150fe624 253 letters[7] = 'g';
TimV 0:b2f4150fe624 254 letters[8] = '.';
TimV 0:b2f4150fe624 255 letters[9] = '.';
TimV 0:b2f4150fe624 256 letters[10] = '.';
TimV 0:b2f4150fe624 257 letters[11] = '.';
TimV 0:b2f4150fe624 258 letters[12] = '.';
TimV 0:b2f4150fe624 259 letters[13] = '.';
TimV 0:b2f4150fe624 260 letters[14] = '.';
TimV 0:b2f4150fe624 261 letters[15] = '.';
TimV 0:b2f4150fe624 262 letters[16] = ' ';
TimV 0:b2f4150fe624 263 LCD.write(LCD_address, letters, 17); // Send data elements
TimV 0:b2f4150fe624 264 }
TimV 0:b2f4150fe624 265 //
TimV 0:b2f4150fe624 266 //************************************************************************
TimV 0:b2f4150fe624 267 // LCD Write Second2 Row Init Function
TimV 0:b2f4150fe624 268 //************************************************************************
TimV 0:b2f4150fe624 269 void LCD_Blank_Row(int LCD_address)
TimV 0:b2f4150fe624 270 {
TimV 0:b2f4150fe624 271 char letters[17];
TimV 0:b2f4150fe624 272 letters[0] = 0x20; //
TimV 0:b2f4150fe624 273 letters[1] = 0x20; //
TimV 0:b2f4150fe624 274 letters[2] = 0x20; //
TimV 0:b2f4150fe624 275 letters[3] = 0x20; //
TimV 0:b2f4150fe624 276 letters[4] = 0x20; //
TimV 0:b2f4150fe624 277 letters[5] = 0x20; //
TimV 0:b2f4150fe624 278 letters[6] = 0x20; //
TimV 0:b2f4150fe624 279 letters[7] = 0x20; //
TimV 0:b2f4150fe624 280 letters[8] = 0x20; //
TimV 0:b2f4150fe624 281 letters[9] = 0x20; //
TimV 0:b2f4150fe624 282 letters[10] = 0x20; //
TimV 0:b2f4150fe624 283 letters[11] = 0x20; //
TimV 0:b2f4150fe624 284 letters[12] = 0x20; //
TimV 0:b2f4150fe624 285 letters[13] = 0x20; //
TimV 0:b2f4150fe624 286 letters[14] = 0x20; //
TimV 0:b2f4150fe624 287 letters[15] = 0x20; //
TimV 0:b2f4150fe624 288 letters[16] = 0x20; //
TimV 0:b2f4150fe624 289 LCD.write(LCD_address, letters, 17); // Send data elements
TimV 0:b2f4150fe624 290 }
TimV 0:b2f4150fe624 291 void setup()
TimV 0:b2f4150fe624 292 {
TimV 0:b2f4150fe624 293 led1 = 1;
TimV 0:b2f4150fe624 294 }
TimV 0:b2f4150fe624 295 //
TimV 0:b2f4150fe624 296 //**************************************************************************************
TimV 0:b2f4150fe624 297 //* Read RFID Tag *
TimV 0:b2f4150fe624 298 //**************************************************************************************
TimV 0:b2f4150fe624 299 //* *
TimV 0:b2f4150fe624 300 //**************************************************************************************
TimV 0:b2f4150fe624 301 //* This code is from the book Practical Arduino by Jonathon Oxer and Hugh Blemings *
TimV 0:b2f4150fe624 302 //* Other than as noted, I have reproduced it as written and with the authors *
TimV 0:b2f4150fe624 303 //* comments and explanations. *
TimV 0:b2f4150fe624 304 //**************************************************************************************
TimV 0:b2f4150fe624 305 void loop()
TimV 0:b2f4150fe624 306 {
TimV 0:b2f4150fe624 307 pc.baud(9600);
TimV 0:b2f4150fe624 308 RFID.baud(9600);
TimV 0:b2f4150fe624 309 int val = 0; // this should hold the character read from the reader
TimV 0:b2f4150fe624 310 int checksum = 0; // this is checked against a calculated checksum
TimV 0:b2f4150fe624 311 int bytesRead = 0; // counter if number of bytes read (2 characters per)
TimV 0:b2f4150fe624 312 int tempByte = 0; // storage for character retreived
TimV 0:b2f4150fe624 313 int tagBytes[6]; // or 12 characters. 5 bytes is tag value 1 is for checksum
TimV 0:b2f4150fe624 314 char tagValue[11]; // the actual tag information +1 for adding null at string end
TimV 0:b2f4150fe624 315 led2=1;
TimV 0:b2f4150fe624 316 LCD_clear_screen(LCD_command, LCD_option);
TimV 0:b2f4150fe624 317 wait(1);
TimV 0:b2f4150fe624 318 LCD_First_Row(LCD_address);
TimV 0:b2f4150fe624 319 LCD_col = 1;
TimV 0:b2f4150fe624 320 LCD_row = 2;
TimV 0:b2f4150fe624 321 LCD_cursor_position(LCD_command, LCD_option, LCD_col, LCD_row);
TimV 0:b2f4150fe624 322 wait(0.5);
TimV 0:b2f4150fe624 323 pc.printf("RFID Module Ready \n\r");
TimV 0:b2f4150fe624 324 wait(0.5);
TimV 0:b2f4150fe624 325 LCD_Second_Row(LCD_address);
TimV 0:b2f4150fe624 326 wait(2);
TimV 0:b2f4150fe624 327 LCD_clear_screen(LCD_command, LCD_option);
TimV 0:b2f4150fe624 328 wait(1);
TimV 0:b2f4150fe624 329 LCD_First2_Row(LCD_address);
TimV 0:b2f4150fe624 330 wait(0.5);
TimV 0:b2f4150fe624 331 while(1)
TimV 0:b2f4150fe624 332 {
TimV 0:b2f4150fe624 333 if (RFID.readable())
TimV 0:b2f4150fe624 334 {
TimV 0:b2f4150fe624 335 val = RFID.getc();
TimV 0:b2f4150fe624 336 if (val == 2)
TimV 0:b2f4150fe624 337 {
TimV 0:b2f4150fe624 338 bytesRead = 0;
TimV 0:b2f4150fe624 339 for (bytesRead = 0; bytesRead < 12; bytesRead++)
TimV 0:b2f4150fe624 340 {
TimV 0:b2f4150fe624 341 val = RFID.getc();
TimV 0:b2f4150fe624 342 if ((val == 0x0D) || (val == 0x0A) || (val == 0x03) || (val == 0x02))
TimV 0:b2f4150fe624 343 {
TimV 0:b2f4150fe624 344 break;
TimV 0:b2f4150fe624 345 }
TimV 0:b2f4150fe624 346 if (bytesRead < 10)
TimV 0:b2f4150fe624 347 {
TimV 0:b2f4150fe624 348 tagValue[bytesRead] = val;
TimV 0:b2f4150fe624 349 }
TimV 0:b2f4150fe624 350 if ((val >= '0') && (val <= '9'))
TimV 0:b2f4150fe624 351 {
TimV 0:b2f4150fe624 352 val = val - '0';
TimV 0:b2f4150fe624 353 }
TimV 0:b2f4150fe624 354 else if ((val >= 'A') && (val <= 'F'))
TimV 0:b2f4150fe624 355 {
TimV 0:b2f4150fe624 356 val = 10 + val - 'A';
TimV 0:b2f4150fe624 357 }
TimV 0:b2f4150fe624 358 if (bytesRead & 1 == 1)
TimV 0:b2f4150fe624 359 {
TimV 0:b2f4150fe624 360 tagBytes[bytesRead >> 1] = (val | (tempByte << 4));
TimV 0:b2f4150fe624 361 // It then checks if it has reached the checksum byte, and if so calculates the checksum
TimV 0:b2f4150fe624 362 if (bytesRead >> 1 != 5)
TimV 0:b2f4150fe624 363 {
TimV 0:b2f4150fe624 364 checksum ^= tagBytes[bytesRead >> 1];
TimV 0:b2f4150fe624 365 };
TimV 0:b2f4150fe624 366 // This part of the code then deals with the first of a pair of hex digits by simply
TimV 0:b2f4150fe624 367 // putting the value directly into a variable. This value will then be shifted 4 bits to
TimV 0:b2f4150fe624 368 // the left on the next loop through by the code above.
TimV 0:b2f4150fe624 369 }
TimV 0:b2f4150fe624 370 else
TimV 0:b2f4150fe624 371 {
TimV 0:b2f4150fe624 372 tempByte = val;
TimV 0:b2f4150fe624 373 };
TimV 0:b2f4150fe624 374 // The program them increments the counter that tracks how many bytes have been read and
TimV 0:b2f4150fe624 375 // reaches the end of the loop, going back to the start to check if it has finished reading
TimV 0:b2f4150fe624 376 // all the digits yet.
TimV 0:b2f4150fe624 377 }
TimV 0:b2f4150fe624 378 // The program checks if 12 bytes have been read, indicating that it has a complete read and
TimV 0:b2f4150fe624 379 // can move on to comparing the acquired value with its list of authorized tags.
TimV 0:b2f4150fe624 380 if (bytesRead == 12)
TimV 0:b2f4150fe624 381 {
TimV 0:b2f4150fe624 382 pc.printf("Tag Value: %s\n\r", tagValue);
TimV 0:b2f4150fe624 383 LCD_col = 1;
TimV 0:b2f4150fe624 384 LCD_row = 2;
TimV 0:b2f4150fe624 385 LCD_cursor_position(LCD_command, LCD_option, LCD_col, LCD_row);
TimV 0:b2f4150fe624 386 wait(0.5);
TimV 0:b2f4150fe624 387 LCD.write(LCD_address, tagValue, 10);
TimV 0:b2f4150fe624 388 }
TimV 0:b2f4150fe624 389 }
TimV 0:b2f4150fe624 390 }
TimV 0:b2f4150fe624 391 }
TimV 0:b2f4150fe624 392 }
TimV 0:b2f4150fe624 393 //
TimV 0:b2f4150fe624 394 int main()
TimV 0:b2f4150fe624 395 {//a->
TimV 0:b2f4150fe624 396 pc.printf("mbed Serial Terminal \n\r");
TimV 0:b2f4150fe624 397 setup();
TimV 0:b2f4150fe624 398 while (1)
TimV 0:b2f4150fe624 399 {
TimV 0:b2f4150fe624 400 loop();
TimV 0:b2f4150fe624 401 }
TimV 0:b2f4150fe624 402 }//a<-