Please Help me with reading the busy flag of LCD in 4 bit mode

Status
Not open for further replies.

aakashjsr

New Member
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:************************************************** ***************************
C:
#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:
I don't have time to go through your code right now, but I found this short and well documented example. Maybe this will help you find what is wrong with your code:
**broken link removed**
 
I used the busy flag in 4 bit mode in tutorial 6 in the tutorials in my signature..
 
Thanks a Lot,the documentation of the code provided really helped.I would really appreciate if in your free time you could go through my code and point out the mistake.Thanks Again
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…