mon projet est une serrure codée à plusieurs code (30 codes de 8 caractères) .
le brobleme ce que je ne peut pas faire un code en mikro c d'ecrire et de lire ces codes mais je fais un code qui peut ecrire un seul code et a chaque foi si j'ajoute un nouveau code sera ecrite sur l'ancien .
si vous pouvez m'aidez repond moi vite
partie de code
Code:unsigned short int kp ; char code1[20] ,user1[9]; char msg1[20] = "Lock System ",msg2[12] = "Enter Code"; char msg6[15]= "SagemCom" ; char msg3[15] = "Access Granted",msg4[15] = "Access Denied"; char msg5[15] = "Enter New Code"; int i=0,j,cnt; // Keypad module connectionschar char keypadPort at PORTD; // End Keypad module connections // LCD module connections sbit LCD_RS at RC2_bit; sbit LCD_EN at RC3_bit; sbit LCD_D4 at RC4_bit; sbit LCD_D5 at RC5_bit; sbit LCD_D6 at RC6_bit; sbit LCD_D7 at RC7_bit; sbit LCD_RS_Direction at TRISC2_bit; sbit LCD_EN_Direction at TRISC3_bit; sbit LCD_D4_Direction at TRISC4_bit; sbit LCD_D5_Direction at TRISC5_bit; sbit LCD_D6_Direction at TRISC6_bit; sbit LCD_D7_Direction at TRISC7_bit; //End LCD module connection void code_enter() { kp = 0; // Reset key code variable //Wait for key to be pressed and released do //kp= Keypad_Key_Press(); // Store key code in kp variable kp = Keypad_Key_Click(); // Store key code in kp variable while (!kp); // Prepare value for output,transform key to it's ASCII value switch (kp) { case 1: kp = 49; break; // 1 // Uncomment this block for keypad4x4 case 2: kp = 50; break; // 2 l case 3: kp = 51; break; // 3 case 4: kp = 65; break; // A case 5: kp = 52; break; // 4 case 6: kp = 53; break; // 5 case 7: kp = 54; break; // 6 case 8: kp = 66; break; // B case 9: kp = 55; break; // 7 case 10: kp = 56; break; // 8 case 11: kp = 57; break; // 9 case 12: kp = 67; break; // C case 13: kp = 42; break; // * case 14: kp = 48; break; // 0 case 15: kp = 35; break; // # case 16: kp = 68; break; // D } code1[i] = kp; Lcd_Chr(2,i+1,42); // Print * on Lcd i++;} void delay_20ms() { Delay_ms(20); } void code_read() { delay_20ms(); user1[0] = EEPROM_Read(0x00); // Read data from address 0 delay_20ms(); user1[1] = EEPROM_Read(0x01); delay_20ms(); user1[2] = EEPROM_Read(0x02); delay_20ms(); user1[3] = EEPROM_Read(0x03); delay_20ms(); user1[4] = EEPROM_Read(0x04); delay_20ms(); user1[5] = EEPROM_Read(0x05); delay_20ms(); user1[6] = EEPROM_Read(0x06); delay_20ms(); user1[7] = EEPROM_Read(0x07); delay_20ms(); } void code_write() { delay_20ms(); EEPROM_Write(0x00,code1[0]); // Write some data at address 00 delay_20ms(); EEPROM_Write(0x01,code1[1]); delay_20ms(); EEPROM_Write(0x02,code1[2]); delay_20ms(); EEPROM_Write(0x03,code1[3]); delay_20ms(); EEPROM_Write(0x04,code1[4]); delay_20ms(); EEPROM_Write(0x05,code1[5]); delay_20ms(); EEPROM_Write(0x06,code1[6]); delay_20ms(); EEPROM_Write(0x07,code1[7]); } void change_code() { Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Out(1, 1, "Enter New Code"); i=0; code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); code_write(); //code_read(); } void main() { x1: TRISB = 0x00; PORTB=0b11100010; //TRISE = 0x00; TRISA = 0x00; Keypad_Init(); // Initialize Keypad Lcd_Init(); // Initialize Lcd code_read(); if(user1[0] == 0xFF && user1[1] == 0xFF && user1[2] == 0xFF && user1[3] == 0xFF && user1[4] == 0xFF && user1[5] == 0xFF && user1[6] == 0xFF && user1[7] == 0xFF) { EEPROM_Write(0x00,'1'); // Write some data at address 00 delay_20ms(); EEPROM_Write(0x01,'2'); // Write some data at address 02 delay_20ms(); EEPROM_Write(0x02,'3'); // Write some data at address 04 delay_20ms(); EEPROM_Write(0x03,'4'); // Write some data at address 08 delay_20ms(); EEPROM_Write(0x04,'5'); delay_20ms(); EEPROM_Write(0x05,'6'); delay_20ms(); EEPROM_Write(0x06,'A'); delay_20ms(); EEPROM_Write(0x07,'B');} code_read(); Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1, 2,msg1 ); Lcd_Out(2, 4,msg6 ) ; Delay_ms(5000); Lcd_Cmd(_LCD_CLEAR); cnt=0; do { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(2, 3, "Press *"); i = 0; code_enter(); if(code1[0] == 42) { Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Out(1, 1,msg2); delay_ms(500); i = 0; code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); code_enter(); if(code1[0] == '1' && code1[1] == '2' && code1[2] == '3' && code1[3] == '1' && code1[4] == '2' && code1[5] == '3' && code1[6] == 'A' && code1[7] == 'B' ) //check master code { if(code1[8] == 35) { change_code(); } } if(cnt<3 && code1[0] == user1[0] && code1[1] == user1[1] && code1[2] == user1[2] && code1[3] == user1[3] && code1[4] == user1[4] && code1[5] == user1[5] && code1[6] == user1[6] && code1[7] == user1[7] && code1[8] == 35) //compare code with store one { Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Out(1, 1, msg3); PORTB=0b11100100; PORTA=0b00000001; Delay_ms(2000); // 40 SECONDE POUR L'OUVERTURE PORTA=0b00000000; Delay_ms(20); // PORTA=0b00000010; Delay_ms(2000); // 40 SECONDE POUR LA FERMETURE PORTA=0b00000000; Delay_ms(20); goto x1; } else { cnt++; Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1, 1,msg4 ); } if(cnt>=3) { do { PORTB=0b11110001; Delay_ms(60000); goto x1; } while(1); } } } while(1); }
-----