You are on page 1of 7

1/20/2018 Is simple C or ASM LCD Busy Flag check function | AVR Freaks

Signup
Login

What are you interes Entire Site Search

Is simple C or ASM LCD Busy Flag


check function
Log in or register to post comments Go To Last Post 7 posts / 0 new

Author Message

Posted by Brewski: Fri. Feb 24, 2012 - #1


12:39 AM
Brewski

Fivestar widget

Total votes: 0

Level: Wannabe I have written my own HD44780 display functions that do everything I
Joined: Tue. Feb 27, 2001
Posts: 89 View posts want to do except it usees delays to compensate for the AVR being
Location: Huntington, WV much faster than the LCD. Everything in my code so far seems to
work solidly in both 8-bit and 4-bit mode.

I would like to replace the delays with a function that can be called
that waits for the Busy Flag to clear and/or possibly returns the BF.

If it returned the reading of the BF and my own code would use it to


delay the program until it clears or display the BF reading on a PORT
Pin or something else with it.

All the code I have seen so far needs a lot of other code to set this
up and execute. So long as the function knows the data port and the
three control pins this should be a simple function.
I'm thinking this could be the simple function:
Change the data port DDRx from output to input.
Clear the LCD RS pin and Set R/W pin.
Set the LCD E pin .
Read the LCD data port, PINx.
Clear the LCD E pin.
Change the data port DDRx back to output.

http://www.avrfreaks.net/forum/simple-c-or-asm-lcd-busy-flag-check-function 1/7
1/20/2018 Is simple C or ASM LCD Busy Flag check function | AVR Freaks

(Changing back to DDR out could be done elsewhere. However. this is


the only place I believe I would ever read from the LCD so by putting
it back to output I would not have to make sure of the direction many
other times in code.)

I have seen code before that I'm sure does this. I have gone over it
but understanding it was beyond me.

Mike

Tags:
AVR Microcontrollers, megaAVR and tinyAVR

Top
Log In / Register to post comments

dksmall Posted by dksmall: Fri. Feb 24, 2012 - #2


12:44 AM

Total votes: 0

Level: Raving Lunatic


Joined: Mon. Apr 16, Post what you have tried so far. If you have written everything you
2001 described above, then this one more routine should not be that
Posts: 3643 View posts
Location: Phoenix, difficult.
Arizona

Top
Log In or Register to post comments

Posted by lincoln: Fri. Feb 24, 2012 - #3


01:03 AM
lincoln

Total votes: 0

Level: Hangaround
Joined: Thu. Jul 21, 2011 #ifdef LCD_CHECK_BUSY
Posts: 158 View posts void waitForLcd(void) {
Location: San jose, CA,
USA // adapted form http://www.8051projects.net/lcd-interf

LCD_DATA_DDR = 0x00; // set data bus to input


LCD_CTRL_PORT &= ~_BV(LCD_RS); // clear rs
LCD_CTRL_PORT |= _BV(LCD_RW); // set read
LCD_CTRL_PORT |= _BV(LCD_E); // set enable
while (LCD_DATA_PIN & 0x80) {

http://www.avrfreaks.net/forum/simple-c-or-asm-lcd-busy-flag-check-function 2/7
1/20/2018 Is simple C or ASM LCD Busy Flag check function | AVR Freaks

LCD_CTRL_PORT &= ~_BV(LCD_E);


LCD_CTRL_PORT |= _BV(LCD_E);
}
LCD_CTRL_PORT &= ~_BV(LCD_E);
LCD_CTRL_PORT &= ~_BV(LCD_RW); // clear write flag
LCD_DATA_DDR = 0xFF; // set data bus to output
}

#else
void waitForLcd(void) {
_delay_us(50);
}

#endif

link

i am a NOOO00B!!

Don’t let that undermine what I just said.

Top
Log In or Register to post comments

Posted by danni: Fri. Feb 24, 2012 - #4


08:09 AM
danni

Total votes: 0

On my experience LCD output with delay cost no noticeable CPU-load.


So implementing busy test would only cost more code and wires, but
has not advantages.
Level: Raving Lunatic
Joined: Wed. Sep 5, 2001
Posts: 2992 View posts You should rethink your program flow, if you use the LCD 1000 times
to often,
so the user was unable to read every new value and see only
annoying flicker on the LCD.
A new value every 200-500ms was an ergonomic user friendly rate.

Peter

Top
Log In or Register to post comments

http://www.avrfreaks.net/forum/simple-c-or-asm-lcd-busy-flag-check-function 3/7
1/20/2018 Is simple C or ASM LCD Busy Flag check function | AVR Freaks

JohanEkdahl Posted by JohanEkdahl: Fri. Feb 24, #5


2012 - 08:16 AM

Total votes: 0

Regardless of if the only read you do is to check the busy flag it still
Level: 10k+ Postman makes sense to divide this into two separate pieces:
Joined: Wed. Mar 27,
2002
Posts: 26837 View posts - A function that reads a byte from the LCD module, and
Location: Lund, Sweden - A function that checks the busy flag.

Sketchy:

uint8_t LCD_ReadAddressBusy()
{
//...
}

int LcdBusy()
{
while (LcdReadAddressBusy & 0x80);
}

Do not worry about the extra level of function calls now. Care about
efficiency of the code later. Get it to work first.

As of January 15, 2018, Site fix-up work has begun! Now do your part and
report any bugs or deficiencies
here(http://www.avrfreaks.net/forum/consolidating-site-errors-
and-deficiencies).

No guarantees, but if we don't report problems they won't get much of a


chance to be fixed! Details/discussions at link given just above.

"Some questions have no answers."[C Baird] "There comes a point where the
spoon-feeding has to stop and the independent thinking has to start." [C
Lawson] "There are always ways to disagree, without being disagreeable."[E
Weddington] "Words represent concepts. Use the wrong words, communicate the
wrong concept." [J Morin] "Persistence only goes so far if you set yourself up
for failure." [Kartman]

Top
Log In or Register to post comments

Posted by pidkits: Fri. Feb 24, 2012 - #6


01:29 PM

http://www.avrfreaks.net/forum/simple-c-or-asm-lcd-busy-flag-check-function 4/7
1/20/2018 Is simple C or ASM LCD Busy Flag check function | AVR Freaks

pidkits
Total votes: 0

This code works for me in 4-bit mode:

Level: New Member // 4-bit parallel interface


Joined: Mon. Sep 6, 2010
Posts: 18 View posts #define _DB_PORT PORTB
#define _DB_DDR DDRB
#define _DB7 PB3 // DB bits must be on same port, but not n
#define _DB6 PB2
#define _DB5 PB1
#define _DB4 PB0
#define _DB_PIN PINB

#define _BF 7 // busy flag is bit 7


#define _DB_BITS (( 1 << _DB7 ) | ( 1 << _DB6 ) | ( 1 << _D

#define tick() _delay_us(1)


#ifndef bitRead
#define bitRead(x,n) ((x>>n)&0x01) // returns value of bit x
#endif

// read the busy flag and address counter from the LCD
// returns 6 bit address plus busy flag (in bit 7)
static uint8_t lcd_readByte() { // 58 uS at 1MHz
uint8_t d,b;
lcd_RW_high(); // RW = 1 to read
tick();
lcd_EN_high(); // EN = 1 to enable read
tick();
b = _DB_PIN; // read pins while EN is high
lcd_EN_low();
tick();
d = ( bitRead(b,_DB4) << 4 ); // high nibble
d |= ( bitRead(b,_DB5) << 5 );
d |= ( bitRead(b,_DB6) << 6 );
d |= ( bitRead(b,_DB7) << 7 );
lcd_EN_high();
tick();
b = _DB_PIN; // read pins while EN is high
lcd_EN_low();
tick();
d |= ( bitRead(b,_DB4) << 0 ); // low nibble
d |= ( bitRead(b,_DB5) << 1 );
d |= ( bitRead(b,_DB6) << 2 );
d |= ( bitRead(b,_DB7) << 3 );
lcd_RW_low(); // clear the RW flag
return d; // contains a full byte read from the LCD
}

http://www.avrfreaks.net/forum/simple-c-or-asm-lcd-busy-flag-check-function 5/7
1/20/2018 Is simple C or ASM LCD Busy Flag check function | AVR Freaks

// waits until busy flag is cleared


static void lcd_waitBusy() {
lcd_RS_low(); // RS = 0 for instruction register
_DB_DDR &= ~_DB_BITS; // set DB pins for input
tick();
while( lcd_readByte() & (1<<_BF) ); // repeat until b
}

Jim

Top
Log In or Register to post comments

theusch Posted by theusch: Fri. Feb 24, 2012 - #7


03:01 PM

Total votes: 0

This very recent thread has some discussion:


Level: 10k+ Postman http://www.avrfreaks.net/index.p...
Joined: Mon. Feb 19,
2001 (http://www.avrfreaks.net/index.php?
Posts: 37353 View posts
Location: Wisconsin USA name=PNphpBB2&file=viewtopic&t=117364&highlight=lcd+bus

And the forum search uncovers similar past threads.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Top
Log In or Register to post comments

Jump To
--megaAVR and tinyAVR

©2015 Atmel Corporation

Privacy(http://www.atmel.com/About/privacy.aspx)
Contact(http://www.atmel.com/About/contact/distributors/default.aspx?
contactType=Online%20Directory)
Site Use Terms(http://www.atmel.com/About/legal.aspx)

http://www.avrfreaks.net/forum/simple-c-or-asm-lcd-busy-flag-check-function 6/7
1/20/2018 Is simple C or ASM LCD Busy Flag check function | AVR Freaks

Cookies(http://www.atmel.com/About/cookies.aspx)

http://www.avrfreaks.net/forum/simple-c-or-asm-lcd-busy-flag-check-function 7/7

You might also like