//============================================================================
void LC7981_Instruction_And_Data_Write(ubyte instruction, ubyte data)
{
//Aim at the instruction register
PORTG=PG_E_LO|PG_RW_LO|PG_RS_HI|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Meet the control setup time (90nS)
_delay_cycles(1);
//Start the write pulse
PORTG=PG_E_HI|PG_RW_LO|PG_RS_HI|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Put the data on the LCD's pins.
PORTA=instruction;
//Meet the "data setup time, write" (220nS)
_delay_cycles(2);
//End the write pulse, clocking the data into the command register.
//Aim at the data register.
PORTG=PG_E_LO|PG_RW_LO|PG_RS_LO|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Writing to the command register is "fast" so we do not have to
//worry about checking busy flag, etc.
//Meet the control setup time (90nS)
_delay_cycles(1);
//Start the write pulse
PORTG=PG_E_HI|PG_RW_LO|PG_RS_LO|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Put the data on the LCD's pins.
PORTA=data;
//Meet the "data setup time, write" (220nS)
_delay_cycles(2);
//End the write pulse, clocking the data into the command register.
PORTG=PG_E_LO|PG_RW_LO|PG_RS_LO|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Writing to the data register starts some execution, and the busy
//flag will go high. However, since this function is only called
//during initialization, and to setup the address before full-screen
//updates, we will just delay a tad instead of messing with waiting
//for the busy bit.
//Max execution time (assuming 400KHz osc) should be around 25uS.
_delay_cycles(500);
}
//============================================================================
// Takes about 13.3mS (288 KB/S) reading busy flag
void UpdateLCD(void)
{
register ubyte
row,col,timeout;
//Reset the address to position 0
LC7981_Instruction_And_Data_Write(0x0A,0x00); //Cursor low address setting
LC7981_Instruction_And_Data_Write(0x0B,0x00); //Cursor high address setting
//Give the "Write Data" command.
//Aim at the instruction register
PORTG=PG_E_LO|PG_RW_LO|PG_RS_HI|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Meet the control setup time (90nS)
_delay_cycles(1);
//Start the write pulse
PORTG=PG_E_HI|PG_RW_LO|PG_RS_HI|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Put the data on the LCD's pins.
PORTA=0x0C; //"Write Display Data" instruction
//Meet the "data setup time, write" (220nS)
_delay_cycles(2);
//End the write pulse, clocking the data into the command register.
//Aim at the data register.
PORTG=PG_E_LO|PG_RW_LO|PG_RS_HI|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Writing to the command register is "fast" so we do not have to
//worry about checking busy flag, etc.
for(row=0;row<=127;row++)
for(col=0;col<=29;col++)
{
//Load the data into the port A output latches
PORTA=display[row][col];
//We need to check the busy flag before writing. Make port A input
DDRA= 0x00;
//Tell the controller we will want the busy flag on DB7
PORTG=PG_E_LO|PG_RW_HI|PG_RS_HI|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Set out timeout count, which will also meet the
//control setup time (90nS)
timeout=255;
//Start the read pulse
PORTG=PG_E_HI|PG_RW_HI|PG_RS_HI|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Meet the data delay time (read) (140nS)
_delay_cycles(1);
//Wait for DB7 (busy) to drop, or timeout.
while((PINA&0x80)&&timeout--);
//End the read pulse, set the lines up for a write.
PORTG=PG_E_LO|PG_RW_LO|PG_RS_LO|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Make port A output, the latch is already loaded with display[row][col]
//This also meets the control setup time (90nS)
DDRA= 0xFF;
//Start the write pulse
PORTG=PG_E_HI|PG_RW_LO|PG_RS_LO|PG_RES_NOT_HI|PG_CS_NOT_LO;
//Meet the "data setup time, write" (220nS)
_delay_cycles(2);
//End the write pulse, clocking the data into the command register.
PORTG=PG_E_LO|PG_RW_LO|PG_RS_LO|PG_RES_NOT_HI|PG_CS_NOT_LO;
}
}
//============================================================================