Microcontroller › AVR › problem in code of avr keypad coz of which o/p is not coming properly
- This topic has 2 replies, 2 voices, and was last updated 11 years, 7 months ago by Ananth.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
April 22, 2013 at 8:59 am #2287AnanthParticipant// Keypad Program/*LCD DATA port—-PORT Actrl port
PORT B //PORT GIVEN TO LCDctrlk port
PORTD //PORT GIVEN TO KEYPHONErs
PB0rw
PB1en
PB2*/#include<avr/io.h>#include<util/delay.h>#define LCD_DATA PORTA // LCD data port#define ctrl PORTB#define ctrlk PORTD#define en PB2 // enable signal#define rw PB1 // read/write signal#define rs PB0 // register select signal#define c1 PD0#define c2 PD1#define c3 PD2#define r1 PD3#define r2 PD4#define r3 PD5#define r4 PD6//unsigned char arr[10]=”Appin Labs”;void LCD_cmd(unsigned char cmd);void init_LCD(void);void LCD_write(unsigned char data);void col3();void col2();void col1();int main(){//unsigned char arr[10]=’Appin Labs’;//int i;DDRA=0xff; // making LCD_DATA port as output portDDRB=0xFF; // making signal as out putDDRD=0XFF;init_LCD(); // initialization of LCD_delay_ms(50); // delay of 50 milli seconds/**for(i=0;i<10;i++){LCD_write(arr);}*///-=–while(1){ctrlk|=(1<<c1)||(1<<c2)||(1<<c3);ctrlk|=(0<<r1)||(0<<r2)||(0<<r3)||(0<<r4);if(bit_is_clear(PIND,c1)){col1();LCD_cmd(0x02);}else if(bit_is_clear(PIND,c2)){col2();LCD_cmd(0x02);}else{col1();LCD_cmd(0x02);}}//—-return 0;}void init_LCD(void){LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode//_delay_ms(1);LCD_cmd(0x01); // clear LCD//_delay_ms(1);LCD_cmd(0x0E); // cursor ON//_delay_ms(1);LCD_cmd(0x06); // cursor ON//_delay_ms(1);LCD_cmd(0x80); // —8 go to first line and –0 is for 0th position//_delay_ms(1);return;}void LCD_cmd(unsigned char cmd){LCD_DATA=cmd;ctrl =(0<<rs)|(0<<rw)|(1<<en); // RS and RW as LOW and EN as HIGH_delay_ms(1);ctrl =(0<<rs)|(0<<rw)|(0<<en); // RS, RW , LOW and EN as LOW_delay_ms(50);return;}void LCD_write(unsigned char data){LCD_DATA= data;ctrl = (1<<rs)|(0<<rw)|(1<<en); // RW as LOW and RS, EN as HIGH_delay_ms(1);ctrl = (1<<rs)|(0<<rw)|(0<<en); // EN and RW as LOW and RS HIGH_delay_ms(50); // delay to get things executedreturn ;}void col3(){ctrlk|=(1<<r1)|(1<<r2)||(1<<r3)||(1<<r4);ctrlk|=(0<<r1);if(bit_is_clear(PIND,c3)){LCD_write(‘3’);}ctrlk|(1<<r1);//—-ctrlk|=(0<<r2);if(bit_is_clear(PIND,c3)){LCD_write(‘6’);}ctrlk|(1<<r2);//—-ctrlk|=(0<<r3);if(bit_is_clear(PIND,c3)){LCD_write(‘9’);}ctrlk|(1<<r3);//—-ctrlk|=(0<<r4);if(bit_is_clear(PIND,c3)){LCD_write(‘#’);}ctrlk|(1<<r4);//—-}void col2(){ctrlk|=(1<<r1)|(1<<r2)||(1<<r3)||(1<<r4);ctrlk|=(0<<r1);if(bit_is_clear(PIND,c2)){LCD_write(‘2’);}ctrlk|(1<<r1);//—-ctrlk|=(0<<r2);if(bit_is_clear(PIND,c2)){LCD_write(‘5’);}ctrlk|(1<<r2);//—-ctrlk|=(0<<r3);if(bit_is_clear(PIND,c2)){LCD_write(‘8’);}ctrlk|(1<<r3);//—-ctrlk|=(0<<r4);if(bit_is_clear(PIND,c2)){LCD_write(‘0’);}ctrlk|(1<<r4);//—-}void col1(){ctrlk|=(1<<r1)|(1<<r2)||(1<<r3)||(1<<r4);ctrlk|=(0<<r1);if(bit_is_clear(PIND,c1)){LCD_write(‘1’);}ctrlk|(1<<r1);//—-ctrlk|=(0<<r2);if(bit_is_clear(PIND,c1)){LCD_write(‘4’);}ctrlk|(1<<r2);//—-ctrlk|=(0<<r3);if(bit_is_clear(PIND,c1)){LCD_write(‘7’);}ctrlk|(1<<r3);//—-ctrlk|=(0<<r4);if(bit_is_clear(PIND,c1)){LCD_write(‘*’);}ctrlk|(1<<r4);//—-}April 22, 2013 at 9:15 am #9558AJISH ALFREDParticipantHi Ananth,
Tell us exactly what happens at the output, then only we can help you better.
April 22, 2013 at 11:04 am #9562AnanthParticipantHi Ajish,
“2580” is displayed when on lcd screen
When any button is pressed that button is not displayed on LCD screen
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.