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 :) ************************************************** *************************** 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(); }
I think theres something wrong. The second call of pos_pulse, shouldn>t it be neg_pulse? And why is ist commented with ¨discard lower nibble? > void lcd_ready() //checks for busy flag ... > 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); ...
Thanks for the Reply. The 2nd pulse is also +ve because I have read that the Lcd's read operations are +ve edge trigerred where as its write operations are -ve edge trigerred. Since the Lcd is working in the 4 bit mode , the 1st pulse gives us the upper nibble of the register which contains the busy flag and the 2nd pulse gives us the value of lower nibble which doesn't has the busy flag and so its discarded. Please tell me if I am correct. Thanks,
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.