LCD Busy flag checking idea

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

So I had this idea and I don't have the 'stuff' here at work to try it out and I won't be able to get to it at home for another week and it is killing me to see if it is a valid idea...hence my question here :-) .

I have some working assembler code for a 4 line HD44780 LCD display. It displays "I love Robin" (okay, don't kill me for sucking up to my wife :-) ) and that is the only thing it does. So below are the 2 subroutines I presently use to check the Busy Flag:

; -----------------------------------------------------------------------------
;

RD_BF:					; ReaD Busy Flag

call	RD_LCD_I
sbrc	LCD_data,7		; Is Busy Flag clear?
rjmp	RD_BF			; no, keep checking until it is
ret						; yes, return to calling routine
RD_LCD_I:				; ReaD LCD Instruction (Busy Flag, Address Counter)

ldi	temp,0x07			; PB2(E), PB1(R/W), PB0(RS) = output
out	DDRB,temp
clr	temp				; PORTA = input
out	DDRA,temp
ldi	temp,0x02			; E = 0, R/W = 1, RS = 0
out	PORTB,temp
nop						; 271nS delay (based on 3.69MHz clock)
sbi	PORTB,E				; E = 1
nop						; 271nS delay
nop						; 271nS delay
in	LCD_data,PINA		; LCD_data is used by the calling routine
cbi	PORTB,E				; E = 0
nop						; attempt to meet LCD T_cycle specification
ret

So I was wondering what if you had an application where you couldn't afford to have the AVR continually sitting in a loop waiting for that stupid busy flag to clear. I saw Bob's idea about having a 500uS 'tick' and just writing a character every tick and the hell with the busy flag. That sounded like a good idea but then I got to thinking and wished that the damn HD44780 designer had made the busy flag a signal that could be used to trigger an interrupt on the AVR.

So then I got to thinking about it further and wondered if you could map the E signal to one of the port pins that can also be used as the output of one of the timers. You could connect the Busy flag bit (bit 7 I think) of the data bus to an external interrupt or pin change interrupt pin. Now when you write a character to the LCD you setup your RS and R/W lines appropriately, then setup your timer to output a clock signal to the E line and then enable the external or pin change interrupt line. Now the CPU can go back to doing other stuff instead of waiting for the busy flag. When the busy flag goes low then the CPU is interrupted and now knows it can write another character.

Does the above make any sense? Could it work? I am probably forgetting something stupid. Am I going around my elbow to get to my ass :-) ?

Thanks for any and all replies...even the ones that tell me how stupid I am :-) .
Steve

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
So I was wondering what if you had an application where you couldn't afford to have the AVR continually sitting in a loop waiting for that stupid busy flag to clear.

Then don't contunually sit in a loop waiting for it to clear. Do the important high priority stuff first.

There was a thread here a day or two back where someone had the (bad) idea of waiting for the busy flag to clear immediately after the data was sent to the 44780. A guarannteed waste of CPU cycles. What You want to do is turn 180 from this idea and go as far as You can in the opposite direction.

When You execute other high priority stuff You will effectively have a parallell process in the 44780 working on clearing the busy flag. When all high priority stuff is done then You return to check on the busy flag, and if You'll have to wait at that point then that is the highest prioritized stuff to do.

This wait could of course be so long that a higher priority task surfaces. The solution here could be to just check for the cleared busy flag for a certain amount of time, and then give up if there is a task with higher priority. Now we are quickly moving into tasks, quasi-parallel algorithms, scheduling and what is often called RTOS'es...

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

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]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
When You execute other high priority stuff You will effectively have a parallell process in the 44780 working on clearing the busy flag.

Thanks Johan !! It is amazing how simple this stuff really is...I wonder why I want to make it so difficult (rolling eyes at myself).