Hi guys,
I'm kinda stuck with this code, it compiles without errors but I can't debugg it to know why it is not executing the part where it accepts passwords during simulation on proteus.
What's it supposed to do? Turn off LEDs on port A when passcode is inputed. I've attached the proteus simulation project for your info. Thanks in advance.
I'm kinda stuck with this code, it compiles without errors but I can't debugg it to know why it is not executing the part where it accepts passwords during simulation on proteus.
What's it supposed to do? Turn off LEDs on port A when passcode is inputed. I've attached the proteus simulation project for your info. Thanks in advance.
Code:
unsigned short kp, pwd[4], l01, l02, l03, l04, l05, l06, pchk;
int i;
char keypadPort at PORTD;
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
void enter(){
do {
i = 0;
kp = 0;
do
kp = Keypad_Key_Click();
while (!kp);
switch (kp) {
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
case 1: kp = 49; break;
}
pwd[i] = kp;
i++;
} while(1);
}
void main(){
Keypad_Init();
ADCON1 = 7;
CMCON = 7;
TRISA = 0x00;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,"LINEMAN");
Lcd_Out(2,1,"PROTECTION");
Delay_ms(100);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Initializing...");
Delay_ms(500);
pchk = EEPROM_Read(0x00);
Delay_ms(100);
if(pchk == 0x00){
EEPROM_Write(0x01,0x01);
EEPROM_Write(0x02,0x01);
EEPROM_Write(0x03,0x01);
EEPROM_Write(0x04,0x02);
EEPROM_Write(0x05,0x02);
EEPROM_Write(0x06,0x02);
Delay_ms(500);
}
l01 = EEPROM_Read(0x01);
l02 = EEPROM_Read(0x02);
l03 = EEPROM_Read(0x03);
l04 = EEPROM_Read(0x04);
l05 = EEPROM_Read(0x05);
l06 = EEPROM_Read(0x06);
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"LINE 1: ON");
PORTA.B0 = 1;
PORTA.B2 = 1;
PORTA.B3 = 0;
Lcd_Out(2,1,"LINE 2: ON");
PORTA.B1 = 1;
PORTA.B4 = 1;
PORTA.B5 = 0;
enter();
enter();
enter();
enter();
if(pwd[0]==42 && pwd[1]==42 && pwd[2]==49 && pwd[3]==35){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Enter Old L1 Pwd");
enter();
enter();
enter();
enter();
if(pwd[0]==l01 && pwd[1]==l02 && pwd[2]==l03 && pwd[3]==35){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Enter New L1 Pwd");
enter();
enter();
enter();
enter();
Delay_ms(500);
EEPROM_Write(0x01,pwd[0]);
EEPROM_Write(0x02,pwd[1]);
EEPROM_Write(0x03,pwd[2]);
EEPROM_Write(0x00,0x01);
Delay_ms(500);
}
}
if(pwd[0]==42 && pwd[1]==42 && pwd[2]==50 && pwd[3]==35){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Enter Old L2 Pwd");
enter();
enter();
enter();
enter();
if(pwd[0]==l04 && pwd[1]==l05 && pwd[2]==l06 && pwd[3]==35){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Enter New L2 Pwd");
enter();
enter();
enter();
enter();
Delay_ms(500);
EEPROM_Write(0x04,pwd[0]);
EEPROM_Write(0x05,pwd[1]);
EEPROM_Write(0x06,pwd[2]);
EEPROM_Write(0x00,0x01);
Delay_ms(500);
}
}
if(pwd[0]==l01 && pwd[1]==l02 && pwd[2]==l03 && pwd[3]==35){
Lcd_Out(1,1,"LINE 1: OFF");
PORTA.B0 = 0;
PORTA.B2 = 0;
PORTA.B3 = 1;
}
if(pwd[0]==l04 && pwd[1]==l05 && pwd[2]==l06 && pwd[3]==35){
Lcd_Out(1,1,"LINE 2: OFF");
PORTA.B1 = 0;
PORTA.B4 = 0;
PORTA.B5 = 1;
}
while(1);
}