1
\$\begingroup\$

Below program is written in AVR studio. Connections: PORTD pins 0 to 7 are connected to data lines of LCD i.e. DB0 to DB7 respectively, PORTB.1 connected to RS, PORTB.2 connected to R/W and PORTB.3 connected to EN of 16x2 LCD JHD 162A.

In program PORTD.7 is checked whether it is busy or not.

Characters do not seem to be displaying. Any suggestion or help would be greatly appreciated.

 #include<avr\io.h>

    void lcdcmd(unsigned char value);
    void lcddata(unsigned char value);
    void lcdready();
    void MSDelay(unsigned int time);
    int main()
    {
        DDRD=0xFF;
        DDRB=0xFF;
        PORTB = 0x00;

            lcdcmd(0x38);

            lcdcmd(0x0E);

            lcdcmd(0x01);

            lcdcmd(0x06);

            lcdcmd(0x86);

            lcddata('M');

            lcddata('D');

            lcddata('E');
        while(1);
        return 0;
    }

    void lcdcmd(unsigned char value)
    {
        lcdready();
        PORTD=value;
        PORTB=PORTB & ~(0b00000010); // rs
        PORTB=PORTB & ~(0b00000100); // rw
        PORTB=PORTB & ~(0b00001000); // en
        MSDelay(1);
        PORTB=PORTB | 0b00001000;
        return;
    }

    void lcddata(unsigned char value)
    {
        lcdready();
        PORTD=value;
        PORTB=PORTB & ~(0b00000010); // rs
        PORTB=PORTB & ~(0b00000100); // rw
        PORTB=PORTB & ~(0b00001000); // en
        MSDelay(1);
        PORTB=PORTB | 0b00001000;
        return;
    }

    void lcdready()
    {
        unsigned char temp;
        PORTD = 0x00;
        temp= PORTD | (1<<7);
        PORTD= temp;
        PORTB=PORTB & ~(0b00000010); // rs
        PORTB=PORTB | 0b00000100; // rw
        while(temp==1)
        {
            PORTB=PORTB & ~(0b00001000); // en
            MSDelay(1);
            PORTB=PORTB | 0b00001000;
            temp= PORTD & (1<<7);
        }
        return;
    }

    void MSDelay(unsigned int time)
    {
        unsigned int i,j;
        for(i=0;i<time;i++)
            for(j=0;j<1275;j++);
    }
\$\endgroup\$
1
\$\begingroup\$

As the datasheet for the HD44780U says, you can't check the busy flag until the controller is fully initialized. Use delays before sending 0x30 to the display three times, with durations of 15ms, 4.1ms, and 100us respectively. See the "Initializing by Instruction" section of the HD44780U datasheet for details.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.