///password wrong function void wrong_password(void) { lcd_clear(); lcd_new_msg_first_line(); printf(" Incorrect"); lcd_new_msg_second_line(); printf(" Password"); Delay_ms(2000); switch(change_request_flag) { //if old password was entered wrong case 1: lcd_clear(); lcd_new_msg_first_line(); printf(" Enter Old"); lcd_new_msg_second_line(); printf(" Password:"******" Confirm New"); lcd_new_msg_second_line(); printf(" Password:"); break; } }
//Overall system initialize function void sys_init(void) { //rows are output & columns are input ADCON1|=0x0F; TRISA=0x0F; TRISE&=0xFC; TRISC=0xF9; //lcd control pins TRISD=0x00; //lcd data bus TRISB=0xFA; //button, LED and door lock actuator //initilize LEDs key_press_indicator=0; door_control=0; //door is locked by default lcd_init(); //initialize LCD printf(" Enter"); lcd_new_msg_second_line(); printf(" Password:"); eeprom_init(); //initialize eeprom //read password from eeprom for(unsigned char i=0; i<password_length; i++) { password[i]=eeprom_rd(i); } }
//weather display function void disp_weather(void) { temp=temp_acquire(); //get temp data lcd_clear(); printf(" Temp: %d C", temp); //custom character for Celsius symbol lcd_cmd_transmit(0x40); //go to CGRAM location 0 //send custom character data; CGRAM location increments by 1 automatically with each write lcd_data_transmit(0x06); lcd_data_transmit(0x09); lcd_data_transmit(0x09); lcd_data_transmit(0x06); lcd_data_transmit(0x00); lcd_data_transmit(0x00); lcd_data_transmit(0x00); lcd_data_transmit(0x00); //the above code makes one custom character; we can make & store 7 more like this in the LCD at any given time //switch back to DDRAM lcd_cmd_transmit(0x8B); lcd_cmd_transmit(0x06); //display custom character at location 0x40; sending 0x01 displays character at location 0x41 & so on lcd_data_transmit(0x00); lcd_new_msg_second_line(); printf("Weather: "); for(unsigned char i=0; i<6; i++) { lcd_data_transmit(weather[i]); } }
//Password change function void password_change(void) { if(change_request==0) { Delay_ms(20); if(change_request==0) { //if password change request is received if(change_request_flag==0) { change_request_flag=1; lcd_clear(); lcd_new_msg_first_line(); printf(" Enter Old"); lcd_new_msg_second_line(); printf(" Password:"******" Enter"); lcd_new_msg_second_line(); printf(" Password:"); } button_press_count=0; Delay_ms(250); } } }
//password entry complete check function void password_entry_complete_check(void) { if(button_press_count>=password_length) { password_check(); //verify password entered button_press_count=0; if(change_request_flag==0) { lcd_clear(); lcd_new_msg_first_line(); printf(" Enter"); lcd_new_msg_second_line(); printf(" Password:"); } } }
//password right function void correct_password(void) { /* *change_request_flag=0 -> normal operation *change_request_flag=1 -> password change request; old password entered *change_request_flag=2 -> new password entered *change_request_flag=3 -> new password confirmed */ //transmit correct password message as required if(change_request_flag!=2) { lcd_clear(); lcd_new_msg_first_line(); printf(" Correct"); lcd_new_msg_second_line(); printf(" Password"); Delay_ms(2000); } switch(change_request_flag) { //welcome_message sent only if password change request was not given & user is simply trying to enter case 0: lcd_clear(); lcd_new_msg_first_line(); printf(" Welcome"); lcd_new_msg_second_line(); printf(" Home"); //unlock the door door_control=1; Delay_ms(5000); door_control=0; break; //ask for new password case 1: lcd_clear(); lcd_new_msg_first_line(); printf(" Enter New"); lcd_new_msg_second_line(); printf(" Password:"******" Confirm New"); lcd_new_msg_second_line(); printf(" Password:"); change_request_flag++; break; //new password entering process is finished; reset request flag & remove old password completely from the system case 3: for(unsigned char i=0; i<password_length; i++) { eeprom_wr(i, password[i]); } change_request_flag=0; break; } }
//time display function void disp_time(void) { lcd_clear(); //compensate for some glitches due to single digits if(time[0]<=9 && time[1]>9) { printf(" 0%d:%d", time[0], time[1]); } else if(time[0]>9 && time[1]<=9) { printf(" %d:0%d", time[0], time[1]); } else if(time[0]<=9 && time[1]<=9) { printf(" 0%d:0%d", time[0], time[1]); } else { printf(" %d:%d", time[0], time[1]); } lcd_new_msg_second_line(); switch(time[2]) { case 1: printf("Sun, "); break; case 2: printf("Mon, "); break; case 3: printf("Tue, "); break; case 4: printf("Wed, "); break; case 5: printf("Thu, "); break; case 6: printf("Fri, "); break; case 7: printf("Sat, "); break; default: asm("NOP"); } switch(time[4]) { case 1: printf("Jan "); break; case 2: printf("Feb "); break; case 3: printf("Mar "); break; case 4: printf("Apr "); break; case 5: printf("May "); break; case 6: printf("Jun "); break; case 7: printf("Jul "); break; case 8: printf("Aug "); break; case 9: printf("Sep "); break; case 10: printf("Oct "); break; case 11: printf("Nov "); break; case 12: printf("Dec "); break; default: asm("NOP"); } printf("%d,", time[3]); printf("20%d", time[5]); }