Mike - K8LH
Well-Known Member
LCD writes and their associated inter-write delays can eat up a lot of time when writing lots of characters to the display. One method I came up with to avoid some of this overhead in 'main' is to update one character at a time on the LCD from a 32 byte display buffer using an ISR. Writing to the LCD in main is simply a matter of placing characters in the display buffer (very fast) while the display is updated entirely in the background. Also, driving a switch and/or encoder matrix using the LCD RS and D4..D7 lines becomes a simple ISR task since the ISR has complete control of LCD write operations.
Regards, Mike
Regards, Mike
Code:
char lcd[33] = { " lcd buffer demo HH:MM:SS" };
#define line1 0
#define line2 16
Code:
void interrupt() // 500 usec (1000 cycle) interrupts
{ static char line = 0xC0; //
static char bndx = 0; //
pir1.TMR2IF = 0; // clear TMR2 interrupt flag
if(line & 0x80) // if "new line"
PutCMD(line ^= 0x40); // toggle DDRAM address (0xC0 or 0x80)
else // not "new line" so
PutDAT(lcd[bndx++]); // refresh display, bump index
bndx &= 31; // pseudo %32, 0..31 inclusive
if((bndx & 15) == 0) // if new line (0 or 16)
line ^= 0x80; // toggle b7 pseudo "new line" flag
}
//
Last edited: