1. 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.
    Dismiss Notice

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

Discussion in 'AVR' started by aakashjsr, Apr 16, 2014.

  1. aakashjsr

    aakashjsr New Member

    Joined:
    Apr 16, 2014
    Messages:
    2
    Likes:
    0
    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:************************************************** ***************************
    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: Apr 16, 2014
  2. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,306
    Likes:
    914
    Location:
    Rochdale UK
    I used the busy flag in 4 bit mode in tutorial 6 in the tutorials in my signature..
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. aakashjsr

    aakashjsr New Member

    Joined:
    Apr 16, 2014
    Messages:
    2
    Likes:
    0

    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 :) :)
     

Share This Page