ADCON1 = 0x0F; //all inputs are digital
ADCON0 = 0x00;
TRISD = 0xFF; //PORTD is input (keypad)
TRISB = 0x00; //PORTD output(Lcd)
PORTB = 0x00;
PORTD = 0xFF;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Keypad_Init();
UART1_Init(9600);
Soft_UART_Init(&PORTC, 7, 6, 14400, 0);
// Initialization ends
do{
Soft_UART_Read(decision);
}while(1);
Delay_ms(100);
if (decision[3] = 1)
{
PORTA.F3 = 0XFF;
}
else
{
code_rcvd=0;
srand(rand());
id_code = rand()%8999+1000;
UART1_Write_Text("AT+CMGS=");
UART1_Write(0x22);
UART1_Write(0x22); // to send the "
UART1_Write_Text("mob_%s",&decision[2]);
UART1_Write(0x0d); // to send <Enter>
DELAY_MS(200);
UART1_Write_Text("%d",&id_code);
UART1_Write(26); // to send <Ctr+z>
Lcd_Out(1,1, "Enter the code");
do {
kp = 0;
do
kp = Keypad_Key_Click();
while (!kp);
switch (kp) {
case 1: kp = 49; break; // 1
case 2: kp = 50; break; // 2
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
}
// Prepare value for output, transform key to it's ASCII value
code_rcvd = code_rcvd*10+kp;
}while(1);
if(code_rcvd = id_code) // Compare system generated code and entered code
PORTA.F3=0XFF; // Enable Transaction
else
{
PORTA.F1=0XFF; //Enable Alarm
PORTA.F2=0XFF; //Enable Relay for door lock
PORTA.F3=0XFF; //Transaction failed
}
}
}