Professional Documents
Culture Documents
h> #define pad PORTC #define r1 PC0 #define r2 PC1 #define r3 PC2 #define r4 PC3 #define c1 PC4 #define c2 PC5 #define c3 PC6 #define c4 PC7 #define data_port PORTA #define control_port PORTB #define RS PB0 #define RW PB1 #define EN PB2 //LCD data port
void lcd_cmd(unsigned char ); void LCD_Init(void); void lcd_write(unsigned char); void lcd_cursor(unsigned char ,unsigned char ); void initial( unsigned char ); unsigned char key_detect(); unsigned char check1(void); unsigned char check2(void); unsigned char check3(void); unsigned char check4(void); unsigned char enter_UID();
void port_init() {
DDRA = 0xFF; DDRB = 0x0F; DDRC = 0x0F; pad = 0xF0; DDRD = 0xFF;
//GSM
LCD_Init(); return; } void LCD_Init() { lcd_cmd(0x38); _delay_ms(1); lcd_cmd(0x01); _delay_ms(1); lcd_cmd(0x0E); _delay_ms(1); lcd_cmd(0x80); _delay_ms(1); return; }
//LCD Initialise()
//clear LCD
//cursor ON
control_port =(0<<RS)|(0<<RW)|(1<<EN); _delay_ms(1); control_port =(0<<RS)|(0<<RW)|(0<<EN); _delay_ms(50); return; } /* void lcd_data( unsigned char data ) { data_port = data; control_port|=(1<<RS); control_port&=~(1<<RW); control_port|=(1<<E); // delay_ms(20); control_port&=~(1<<E); return; }
*/ void lcd_write(unsigned char data) { data_port = data; control_port = (1<<RS)|(0<<RW)|(1<<EN); _delay_ms(100); control_port = (1<<RS)|(0<<RW)|(0<<EN); // making EN and RW as LOW and RS HIGH _delay_ms(100); // give a 10 milli second delay to get thigs executed return ; } void lcd_string( unsigned char col, unsigned char row, unsigned char *str) pionter *str //take address vaue of the string in // making RW as LOW and RS, EN as HIGH //TO DISPLAY THE CHARACTERS(DATA) ON LCD
//TO DISPLAY THE STRING OF CHARACTERS ON LCD { lcd_cursor( row, col ); //to set cursor at a particular pos ON LCD
while( *str ) { // loop will go on till the NULL charaters is soon in string lcd_write( *str++ ); } return; } void lcd_cursor( unsigned char row, unsigned char column ) LINE2(ROW2) { switch(row) { case 1: lcd_cmd( 0x80+column-1); break; case 2: lcd_cmd( 0xC0+column-1); break; default: break; } return; } //0X80=LINE1 //TO SET THE CURSOR ON LINE1(ROW) OR // sending data on LCD byte by byte
//0XC0=LINE2
}bankdb;*/
unsigned char main() { unsigned char value; unsigned char sel; port_init(); lcd_string(1,1,"1:with ATM card"); lcd_string(1,2,"2:w/o ATM card"); while(1) { PORTC=0xF0; value=PINC; if(value!=0xF0) { lcd_cmd(0x01); value = check1(); break; } } //set all the input to one //get the PORTC value in variable "value" //if any key is pressed value changed
//
lcd_cmd(0x01); switch( sel ) { // case 1: LCD_Init(); lcd_string(1,1,"default"); break; case 2: // LCD_Init(); lcd_string(1,1,"enter UID"); return; //enter_UID(); //verify_UID(); //enter_pass(); //verify_pass(); // break; default: break; } } /* while(1) { PORTC=0xF0; value=PINC; if(value!=0xF0) { check1(); check2(); check3(); check4(); } } */ //set all the input to one //get the PORTD value in variable "value" //if any key is pressed value changed
unsigned char key_detect() { unsigned char value, sel; while(1) { PORTC=0xF0; //set all the input to one
value=PINC; if(value!=0xF0) { sel = check1(); sel = check2(); sel = check3(); sel = check4(); break; } } return sel; } /*switch( sel ) { case 1:
//get the PORTD value in variable "value" //if any key is pressed value changed
LCD_Init(); lcd_string(1,1,"default"); break; case 2: LCD_Init(); lcd_string(1,1,"enter UID"); enter_UID(); //verify_UID(); //enter_pass(); //verify_pass(); // break; default: break; } } }*/ unsigned char check1(void) { unsigned char x; pad=0b11111011; //pad &= (0<<r3); _delay_us(10); if(bit_is_clear(PINC,c1)) { // // LCD_Init(); lcd_cmd(0x01);
else if(bit_is_clear(PINC,c3)) { // lcd_cmd(0x01); lcd_write('3'); x = 3; /*if(x != 3) { check2(); }*/ } // lcd_write('3'); return x; } unsigned char check2(void) { // lcd_cmd(0x01); unsigned char x; pad=0b11111101; //pad &= (0<<r2); _delay_us(10); if(bit_is_clear(PINC,c1)) { // lcd_cmd(0x01); lcd_write('4'); x = 4; return x; } // lcd_write('4'); else if(bit_is_clear(PINC,c2)) {
//
//
//
// }
lcd_write('6'); return x;
unsigned char check3(void) { // lcd_cmd(0x01); unsigned char x; //DDRC = 0xf0; pad =0b11111110; //pad &= (0<<r1); _delay_us(10); if(bit_is_clear(PINC,c1)) { // lcd_cmd(0x01); lcd_write('7'); x = 7; return x; } // lcd_write('7'); else if(bit_is_clear(PINC,c2)) { // lcd_cmd(0x01); lcd_write('8'); x = 8; return x; } // lcd_write('8'); else if(bit_is_clear(PINC,c3))
{ // lcd_cmd(0x01); lcd_write('9'); x = 9; /*if(x != 9) { check4(); }*/ } // } unsigned char check4(void) { // lcd_cmd(0x01); unsigned char x; pad =0b11110111; //pad &= (0<<r4); _delay_us(10); if(bit_is_clear(PINC,c1)) { // lcd_cmd(0x01); lcd_write('*'); x = '*'; return x; } // lcd_write('*'); else if(bit_is_clear(PINC,c2)) { // lcd_cmd(0x01); lcd_write('0'); x = 0; return x; } // lcd_write('0'); else if(bit_is_clear(PINC,c3)) { // lcd_cmd(0x01); lcd_write('#'); x = '#'; } // } lcd_write('#'); return x; lcd_write('9'); return x;
unsigned char enter_UID() { lcd_cmd(0x01); unsigned char uid[4]; unsigned char cnt=0; unsigned char v;//, i, value;
while(1) { v = key_detect(); uid[cnt] = v; cnt++; if(cnt == 4) { break; } //lcd_string(cnt,1,uid); //cnt++; } /*while(1) { PORTC=0xF0; value=PINC; if(value!=0xF0) { i = check1(); //i = check2(); //i = check3(); //i = check4(); } }*/ //uid = i; lcd_cmd(0x01); _delay_ms(100); lcd_string(1,1,uid); /* v = uid[0]; lcd_write(v); _delay_ms(100); v = uid[1]; lcd_write(v); _delay_ms(100); v = uid[2]; lcd_write(v); _delay_ms(100); v = uid[3]; //set all the input to one //get the PORTD value in variable "value" //if any key is pressed value changed