Please help me with checking of the busy flag of a lcd in 4bit mode

OP #3619609
Rate this post
• ▲ useful
▼ not useful
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();


}
Guest #3620141
Rate this post
• ▲ useful
▼ not useful
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);
...
OP #3620278
Rate this post
• ▲ useful
▼ not useful
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,

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.