aakashjsr
Newbie level 3
- Joined
- Apr 16, 2014
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 38
I am able to execute commands on my lcd when I use delay instead of checking the busy flag but when I check the busy flag,it appears as if an infinite loop has started.Here's the connections for my 4 bit Lcd with the AVR Atmega 16.Thanks a lot in advance
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 ***************************************************************************** PB0-> RS ; PB1->ENABLE ; PB2->R/W ; PB3->NOT CONNECTED PB4-PB7----->DB4-DB7 ***************************************************************************** Code: ***************************************************************************** #define data PORTB #define e PB1 #define rs PB0 #define rw PB2 void lcd_ready() //checks for busy flag { DDRB&=0b00001111; //data lines as read int flag=0; cbi(PORTB,rs); sbi(PORTB,rw); do { pos_pulse(); _delay_us(10); flag=PINB; flag=(flag&0x80); //to store the value of busy flag pos_pulse(); //discard lower nibble _delay_us(10); }while(flag); DDRB=0xff; //resetting data lines as output } void pos_pulse() { cbi(PORTB,e); // eable=0 _delay_us(2); sbi(PORTB,e) ; // eable=1 _delay_us(2); } void neg_pulse() { sbi(PORTB,e); // eable=1 _delay_us(2); cbi(PORTB,e) ; // eable=0 _delay_us(2); } void command(int a) // to receive and send command to LCD { //higher nibble lcd_ready(); data=(a&0xf0); cbi(PORTB,rs); cbi(PORTB,rw); neg_pulse(); //Lower Nibble lcd_ready(); data=((a<<4)&0xf0); cbi(PORTB,rs); cbi(PORTB,rw); neg_pulse(); } void value(int a) //To send Data to the Lcd { //higher nibble lcd_ready(); data=(a&0xf0); sbi(PORTB,rs); cbi(PORTB,rw); neg_pulse(); //Lower Nibble lcd_ready(); data=((a<<4)&0xf0); sbi(PORTB,rs); cbi(PORTB,rw); neg_pulse(); }
Last edited by a moderator: