• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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

Thread starter #1
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:
Thread starter #4
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 :) :)
 

Latest threads

EE World Online Articles

Loading

 
Top