Example #1
0
void display(uint8_t *column)
{
    uint8_t i;
    uint8_t seq;

    seq = 0x01;
        
	PORTA=l[bila.x+2];
	PORTD=l[bila.y+2];
	_delay_ms(PERIOD /(nrCol+1));

    for (i = 0; i < nrCol; i++)
    {

        PORTA = seq;
        PORTD = column[i];
		_delay_ms(PERIOD /(nrCol+1));

        seq = seq << 1;
    }

	if (go==1) {
		beep_once(_B_TIME);
		go=0;
		}
}
//============================================================================================
//	main function
//============================================================================================
void main(void)
{
	ADCON1=0b00000110;	//set all portA pins as digital I/O
	TRISA=0b11001111;   //clear bit 4&5 portA as output and set the rest as input
	TRISB=0b00000000;   //set portB as output
	TRISD=0b00000000;   //set portD as output
	TRISC=0b11110000;   //set bit4-7 portC as input(connected to 4 row of keypad)
	TRISE=0b00000000; 	//set portE as output

	PORTC=0;
	PORTD=0;
	RELAY=0;
	BUZZER=0;
	LED_YELLOW=0;
	LED_RED=0;

	send_config(0b00001001);                //clear display at lcd
	send_config(0b00000010);                //Lcd Return to home
	send_config(0b00000110);                //entry mode-cursor increase 1
	send_config(0b00001100);                //diplay on, cursor off and cursor blink off
	send_config(0b00111000);                //function
	
	lcd_clr();                          //clear LCD
	delay(1000);                        //delay
	lcd_goto(0);                        //initial display
	send_string("PLEASE ENTER");        //Display "PLEASE ENTER" on lcd
	lcd_goto(20);                       //Display on 2nd line
	send_string("6-DIGIT PASSWORD");    //Display "6-DIGIT PASSWORD" on lcd

	
	while(1)
	{                   //keypad scanning algorithm
			clearrow1();		//Clear 1st output pin and set the others
			scancolumn1();	//scan column 1-4
			clearrow2();		//Clear 2nd output pin and set the others
			scancolumn2();	//scan column
			clearrow3();		//Clear 3rd output pin and set the others
			scancolumn3();	//scan column
			clearrow4();		//Clear 4th output pin and set the others
			scancolumn4();	//scan column
			
	if(password_count==6)	
	{
            password_count=0;
            if((keyin_char[0]==stalled_char[0])&&(keyin_char[1]==stalled_char[1])&&
                (keyin_char[2]==stalled_char[2])&&(keyin_char[3]==stalled_char[3])&&
		(keyin_char[4]==stalled_char[4])&&(keyin_char[5]==stalled_char[5]))	//compare the keyin value with stalled value to test whether password is correct
                    {
                        lcd_clr();				//clear lcd
			lcd_goto(0);
			send_string("SUCCESS!");		//display SUCCESS
			LED_YELLOW=1;               //yellow light on
			RELAY=1;                    //relay on
			beep_once();                //beep one time
			while(1);                   //infinity loop
				}
	else
	{
            lcd_clr();						//clear lcd
            lcd_goto(0);
            send_string("ERROR!");//display ERROR!
            LED_RED=1;						//red light on
            beep_twice();					//beep two time
            while(1);             //infinity loop
                        }
			}
	}
}