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