XGpio_mSetDataReg(LCD_BASEADDR, 1, inst);
//write data
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, printinst); //set enable
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, inst);
//turn off enable
usleep(10);
WaitForBusyFlag();
// usleep(INST_DELAY);
}
void WriteInst(unsigned long inst1, unsigned long inst2)
{
unsigned long printinst;
printinst = 0x00000040 | inst1;
XGpio_mSetDataReg(LCD_BASEADDR, 1, inst1);
//write data
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, printinst); //set enable
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, inst1);
//turn off enable
usleep(10);
printinst = 0x00000040 | inst2;
XGpio_mSetDataReg(LCD_BASEADDR, 1, printinst); //set enable and data
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, inst2);
//turn off enable
usleep(INST_DELAY);
}
void WriteData8(unsigned long data)
{
unsigned long rs_data, enable_rs_data;
// int busy=true;
rs_data = 0x00000200 | data; //sets rs, data1
enable_rs_data = 0x00000600 | data;
XGpio_mSetDataReg(LCD_BASEADDR, 1, rs_data); //write data, rs
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, enable_rs_data); //set enable, keep data, rs
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, rs_data); //turn off enable
usleep(10);
WaitForBusyFlag();
// usleep(DATA_DELAY);
}
void WriteData(unsigned long data1, unsigned long data2)
{
unsigned long rs_data, enable_rs_data;
// int busy=true;
rs_data = 0x00000020 | data1; //sets rs, data1
enable_rs_data = 0x00000060 | data1;
XGpio_mSetDataReg(LCD_BASEADDR, 1, rs_data); //write data, rs
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, enable_rs_data); //set enable, keep data, rs
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, rs_data); //turn off enable
usleep(10);
rs_data = 0x00000020 | data2; //sets rs, data2
enable_rs_data = 0x00000060 | data2; //sets rs, data2
XGpio_mSetDataReg(LCD_BASEADDR, 1, enable_rs_data); //set enable, rs, data
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, rs_data); //turn off enable
usleep(DATA_DELAY);
}
//==================================================================================
//
//
EXTERNAL FUNCTIONS
//
//==================================================================================
void LCDOn()
{
//printf("DISPLAY ON\r\n");
// WriteInst(0x00000000, 0x0000000E);
WriteInst8(0x0000000E); //display on, cursor on, cursor blink off
}
void LCDOff()
{
// printf("DISPLAY OFF\r\n");
// WriteInst(0x00000000, 0x00000008);
WriteInst8(0x00000008); //display off, cursor off
}
void LCDClear()
{
// printf("DISPLAY CLEAR\r\n");
// WriteInst(0x00000000, 0x00000001);
// WriteInst(0x00000000, 0x00000010);
WriteInst8(0x00000001); //clear display
WriteInst8(0x00000002); //return home
}
void LCDInit()
{
// Sets CHAR LCD Reg to Write Mode
XGpio_mSetDataDirection(LCD_BASEADDR, 1, 0x00000000);
// Zeroes CHAR LCD Reg
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000000);
// LCD INIT
usleep(15000); //After VCC>4.5V Wait 15ms to Init Char LCD
InitInst();
usleep(4100); //Wait 4.1ms
InitInst();
usleep(100); //Wait 100us
InitInst();
InitInst();
// Function Set
// WriteInst(0x00000002, 0x00000002);
WriteInst8(0x00000038);
// Display Off
// WriteInst(0x00000000, 0x00000008);
WriteInst8(0x00000008);
// Display Clear
// WriteInst(0x00000000, 0x00000001);
WriteInst8(0x00000001);
// Entry Mode Set
// WriteInst(0x00000000, 0x00000006);
WriteInst8(0x00000006); //cursor moves right, no shift
// Display On
// WriteInst(0x00000000, 0x0000000E);
WriteInst8(0x0000000E);//display on, cursor on, cursor blink off
}
void LCDEnableDisplayShift()
{
WriteInst8(0x00000007); //cursor moves right, shift enabled
}
void LCDEnableCursorBlink()
{
WriteInst8(0x0000000F);//display on, cursor on, cursor blink on
}
void LCDDisableDisplayShift()
{
WriteInst8(0x00000006); //cursor moves right, no shift
}
void LCDDisableCursorBlink()
{
WriteInst8(0x0000000E);//display on, cursor on, cursor blink off
}
void MoveCursorHome()
{
// WriteInst(0x00000000, 0x00000002);
WriteInst8(0x00000002);
}
void MoveCursorLeft()
{
// WriteInst(0x00000001, 0x00000000);
WriteInst8(0x00000010);
}
void MoveCursorRight()
{
// WriteInst(0x00000001, 0x00000004);
WriteInst8(0x00000014);
}
void LCDSetLine(int line)
{
//line1 = 1, line2 = 2
int i;
if((line - 1))
{
MoveCursorHome();
for(i=0; i<40; i++)
{
MoveCursorRight();
}
}
else
{
MoveCursorHome();
}
}
void LCDPrintChar(char c)
{
// WriteData(((c >> 4) & 0x0000000F), (c & 0x0000000F));
WriteData8(c);
}
void LCDPrintString(char * line1, char * line2)
{
int i=0;
LCDSetLine(1);
评论
查看更多