amitjagtap
Full Member level 5
- Joined
- Jan 10, 2007
- Messages
- 304
- Helped
- 42
- Reputation
- 84
- Reaction score
- 36
- Trophy points
- 1,308
- Activity points
- 3,273
hi all,
I have written code for ibutton access control system using LPC2148. Individually all worked fine.
when integrated, it behaves different. I have tried several changes in that I dont know what thing I am missing.
as per code flow : it should display choice of Registration phase and user access phase, but it is directly jumping to user accress phase without going to registration phase....
Logically code looks ok...
Experts of ARM and Embedded C: please comments on ant loop holes...
I have written code for ibutton access control system using LPC2148. Individually all worked fine.
when integrated, it behaves different. I have tried several changes in that I dont know what thing I am missing.
as per code flow : it should display choice of Registration phase and user access phase, but it is directly jumping to user accress phase without going to registration phase....
Logically code looks ok...
Experts of ARM and Embedded C: please comments on ant loop holes...
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 #include "lcd.h" #include "i2c.h" #include "lpc214x.h" #include "type.h" #include "serial.h" #define UART0_TEXT "\n\r I-BUTTON ACCESS CONTROL SYSTEM" #define PRESCALE 30 // to generate 1us interval-- Each TC will count 1us extern void init_PLL(void); extern void UART0Init( DWORD baudrate ); extern void delay1(unsigned int); unsigned char getKey(void); void initRTC(void); extern void initTimer0(void); unsigned char IBReset(void); void IBWriteBit(unsigned char bit); char IBWriteByte(unsigned char data); unsigned char IBReadBit(void); unsigned char IBReadByte(void); void delayus(unsigned int); char keys[4][4] = { {'1', '2', '3', 'A'}, //1,2,3,4 {'4', '5', '6', 'B'}, //5,6,7,8 {'7', '8', '9', 'C'}, //9,10,11,12 {'*', '0', '#', 'D'} //13,14,15,16 }; int main (void) { char ibuf[8],PIN[4],Read_key[8],Read_PIN[4]; unsigned int k,readibutton_done; char key; char *strng="\t *** \n"; //unsigned int i; init_PLL(); init_lcd(); initRTC(); IODIR0 |= 0x00FF0000; //P1.23 to P1.20 as Output- //P1.16 to P1.19 as Input For Keyboard IOCLR0 |= 0x00FF0000; IODIR0 ^= 0x00F0000; //IOPIN0 ^= 0x000F0000; //0x00FF0000; PINSEL0 = 0x00000005; /* Enable RxD0 and TxD0 & TXD1 & RXD1 */ UART0Init(9600); uart0_puts (UART0_TEXT); uart0_puts (strng); uart0_putc ('\n'); for (k=0;k<8;k++) // Clear The ibutton buffer ibuf[k] = 0; key = 0; i2c_lpc_init(I2C_SPEED_100); // I2c init for EEPROM Speed 100Ksps delay1(5000); lcd_clear(); lcd_putstring(0,"I-BUTTON ACCESS "); lcd_putstring(1," CONTROL SYSTEM"); delay1(8000); while (1) { lcd_clear(); lcd_putstring(0," #-T0 REGISTER "); lcd_putstring(1,"UserAccess-Any "); delay1(8000); while(!(key = getKey())); // wait for key to press //switch(key) // User Registration Phase if (key == '#') { //case '#': //{ lcd_clear(); lcd_putstring(0," REGSTN PHASE "); lcd_putstring(1," HOLD I-BUTTON "); delay1(6000); // Read I-button readibutton_done = 0; while (IBReset()) // if i-button present function returns 1 else /0 - Null { delayus(10000); // wait for 10 ms - to stable the contact bounce IBWriteByte(0x33); // send ROM Read command do { IBWriteByte(0x33); for (k=0;k<8;k++) ibuf[k]=IBReadByte(); // Read 64 bit= 8byte Code } while (ibuf[0]==0); readibutton_done = 1; uart0_puts ("\n \t I-Button Present"); //Debug Message } // End of i-button while while (readibutton_done == 1) { lcd_clear(); lcd_putstring(0," REGSTN PHASE "); lcd_putstring(1,"ENTER PIN -"); // Ask to Enter PIN in Registration phase delay1(6000); while(!(PIN[0] = getKey())); // Read 1st key pressed in PIN[0] & display * on LCD for it lcd_gotoxy(1,12); lcd_putchar('*'); while(!(PIN[1] = getKey())); lcd_gotoxy(1,13); lcd_putchar('*'); while(!(PIN[2] = getKey())); lcd_gotoxy(1,14); lcd_putchar('*'); while(!(PIN[3] = getKey())); lcd_gotoxy(1,15); lcd_putchar('*'); m24xx_write(EEPROM_24XX256, 0 , 0 ,(char *)ibuf , sizeof(ibuf)); // write key 8 bytes to EEPROM from location 0 to 7 m24xx_write(EEPROM_24XX256, 8 , 0 ,(char *)PIN , sizeof(PIN)); // Store 4 digit PIN in EEPROM from 8 to 11 //send key & PIN to host PC uart0_puts("\n\t Registered I-button key & PIN -\t"); for (k=0;k<8;k++) { uart0_putc(ibuf[k]); ibuf[k] = 0; // Clear Key Buffer } uart0_putc('\t'); for (k=0;k<4;k++) { uart0_putc(PIN[k]); PIN[k] = 0; // Clear PIN Buffer } lcd_clear(); lcd_putstring(0," REGSTN DONE "); delay1(50000); key =0; // To activate User Access Phase after registration } // break; } else if (key == '*') //case '*': // User Access Phase { lcd_clear(); lcd_putstring(0," USER ACCESS "); lcd_putstring(1," HOLD I-BUTTON "); delay1(50000); //Read ibutton readibutton_done = 0; while (IBReset()) // if i-button present function returns 1 else /0 - Null { delayus(10000); // wait for 10 ms - to stable the contact bounce IBWriteByte(0x33); // send ROM Read command do { IBWriteByte(0x33); for (k=0;k<8;k++) ibuf[k]=IBReadByte(); // Read 64 bit= 8byte Code } while (ibuf[0]==0); readibutton_done = 1; uart0_puts ("\n \t I-Button Present"); //Debug Message } // End of i-button while m24xx_read(EEPROM_24XX256, 0 , 0 , (char *)Read_key , sizeof(Read_key)); // Read ibutton stored Key if (Read_key != ibuf) // If Read Key form EEPROM and ibutton key not matched { lcd_clear(); lcd_putstring(0,"I-BUTTON UNREGIS"); lcd_putstring(1," NO ACCESS "); delay1(8000); //send Unregistered i-button key to host PC as unauthorized Access uart0_puts("\n\t UnAuthorized Access with Key -\t"); for (k=0;k<8;k++) { uart0_putc(ibuf[k]); ibuf[k] = 0; // Clear Key Buffer } uart0_puts("\n\t UnAuthorized Access at Time -\t"); uart0_putc(YEAR/100); uart0_putc(YEAR%100); uart0_putc (':'); uart0_putc((MONTH)); uart0_putc (':'); uart0_putc(DOM); uart0_putc (':'); uart0_putc(HOUR); uart0_putc (':'); uart0_putc(MIN); uart0_putc (':'); uart0_putc(SEC); } else if (Read_key == ibuf) // if i-button is matched Ask to Enter 4 digit PIN { lcd_clear(); lcd_putstring(0," USER ACCESS "); lcd_putstring(1,"ENTER PIN -"); // Ask to Enter PIN in user Access phase while(!(PIN[0] = getKey())); // Read 1st key pressed in PIN[0] & display * on LCD for it lcd_gotoxy(1,12); lcd_putchar('*'); while(!(PIN[1] = getKey())); lcd_gotoxy(1,13); lcd_putchar('*'); while(!(PIN[2] = getKey())); lcd_gotoxy(1,14); lcd_putchar('*'); while(!(PIN[3] = getKey())); lcd_gotoxy(1,15); lcd_putchar('*'); // Read PIN m24xx_read(EEPROM_24XX256, 8 , 0 , (char *)Read_PIN , sizeof(Read_PIN)); // Read stored PIN from EEPROM if (Read_PIN != PIN) // compare stored PIN and Entered PIN { lcd_clear(); lcd_putstring(0," WRONG PIN "); lcd_putstring(1," NO ACCESS "); delay1(8000); //send Wrong PIN ibutton key to host PC as unauthorized Access uart0_puts("\n\t Wrong PIN with Key -\t"); for (k=0;k<8;k++) { uart0_putc(ibuf[k]); ibuf[k] = 0; // Clear Key Buffer } uart0_puts("\n\t UnAuthorized Access at Time -\t"); uart0_putc(YEAR/100); uart0_putc(YEAR%100); uart0_putc (':'); uart0_putc((MONTH)); uart0_putc (':'); uart0_putc(DOM); uart0_putc (':'); uart0_putc(HOUR); uart0_putc (':'); uart0_putc(MIN); uart0_putc (':'); uart0_putc(SEC); for (k=0;k<4;k++) PIN[k] = 0; } else if (Read_PIN == PIN) { lcd_clear(); lcd_putstring(0," USER ACCESS "); lcd_putstring(1," ACCESS Granted"); delay1(10000); // set GPIO or Buzzer here IODIR1 |=0x02000000; // P1.25 Buzzer is connected IOSET1 |= 0x02000000; // make it high delay1(50000); IOPIN1 ^= 0x02000000; // make it low uart0_puts("\n\t Access Granted to Key -\t"); for (k=0;k<8;k++) { uart0_putc(ibuf[k]); ibuf[k] = 0; // Clear Key Buffer } uart0_puts("\n\t Access Time -\t"); uart0_putc(YEAR/100); uart0_putc(YEAR%100); uart0_putc (':'); uart0_putc((MONTH)); uart0_putc (':'); uart0_putc(DOM); uart0_putc (':'); uart0_putc(HOUR); uart0_putc (':'); uart0_putc(MIN); uart0_putc (':'); uart0_putc(SEC); } } } } ///End of While } ///End of Main /*********************************************** PLL0 Initialization *************************************/ void init_PLL(void) { PLL0CFG = 0x24; // Set multiplier and divider of PLL to give 60.00 MHz .... 4:0 - MUL Value => 4+1=5, 6:5 - Divide Value = 1+1= 2 PLL0CON = 0x01; // Enable the PLL -- Bit 0 = PLL Enable PLL0FEED = 0xAA; // Update PLL registers with feed sequence PLL0FEED = 0x55; while (!(PLL0STAT & 0x00000400)); // test Bit 10 = Lock bit PLL0CON = 0x03; // Connect the PLL --- Bit 1= PLL Connect, Both bits 0 & 1 should be 1 to use PLL PLL0FEED = 0xAA; //Update PLL registers PLL0FEED = 0x55; VPBDIV = 0x02; //Set the VLSI peripheral bus (APB or PCLK) to 30.000MHz return; } /*********************************************** RTC Initialization *************************************/ // Initialize RTC - Current time values should be added void initRTC(void) { // ILR = 0x01; // CIIR = 0x01; // Enable Interrupt on Sec increment CCR = 0x10; // 0 - To write the time value, bit 4 = '1' to select source as Ext 32.786 KHz // Write the current time and calander date SEC = 45; MIN = 15; HOUR = 2; DOM = 31; DOW = 6; DOY = 365; MONTH = 4; YEAR = 2014; CCR = 0x11; // Enable the RTC counters } void delay1(unsigned int count) { unsigned int i,j; for(i=0;i<count;i++) { for(j=0;j<2000;j++); } } /*********************************************** Keypad Read Function *************************************/ unsigned char getKey(void) { //while(1) //{ IOCLR0 |= 0x00F00000; IOSET0 |= 0x00100000; if(((IOPIN0 &0x000F0000)>>16) == 0x08) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x08) delayus(10000); return(keys[3][0]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x04) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x04) delayus(10000); return(keys[2][0]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x02) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x02) delayus(10000); return(keys[1][0]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x01) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x01) delayus(10000); return(keys[0][0]); } IOCLR0 |= 0x00100000; IOSET0 |= 0x00200000; if(((IOPIN0 &0x000F0000)>>16) == 0x08) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x08) delayus(10000); return(keys[3][1]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x04) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x04) delayus(10000); return(keys[2][1]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x02) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x02) delayus(10000); return(keys[1][1]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x01) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x01) delayus(10000); return(keys[0][1]); } IOCLR0 |= 0x00200000; IOSET0 |= 0x00400000; if(((IOPIN0 &0x000F0000)>>16) == 0x08) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x08) delayus(10000); return(keys[3][2]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x04) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x04) delayus(10000); return(keys[2][2]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x02) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x02) delayus(10000); return(keys[1][2]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x01) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x01) delayus(10000); return(keys[0][2]); } IOCLR0 |= 0x00400000; IOSET0 |= 0x00800000; if(((IOPIN0 &0x000F0000)>>16) == 0x08) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x08) delayus(10000); return(keys[3][3]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x04) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x04) delayus(10000); return(keys[2][3]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x02) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x02) delayus(10000); return(keys[1][3]); } else if(((IOPIN0 &0x000F0000)>>16) == 0x01) { delayus(10000); while (((IOPIN0 &0x000F0000)>>16) == 0x01) delayus(10000); return(keys[0][3]); } else return 0; // } }
Attachments
Last edited by a moderator: