// usec delay timer during initialization, important to change if
// clock speed changes
#define INIT_DELAY 10000
#define INST_DELAY 1000 //usec delay timer between instructions
#define DATA_DELAY 1000 //usec delay timer between data
/*
#------------------------------------------------------------------------------
# IO Pad Location Constraints / Properties for Character LCD GPIO
#------------------------------------------------------------------------------
Net Char_LCD_GPIO_IO<0> LOC = AA5 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_E
Net Char_LCD_GPIO_IO<1> LOC = V7 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_RS
Net Char_LCD_GPIO_IO<2> LOC = W6 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_RW
Net Char_LCD_GPIO_IO<3> LOC = AD7 | IOSTANDARD=LVCMOS33 |TIG | PULLDOWN; #LCD_D7
Net Char_LCD_GPIO_IO<4> LOC = AC7 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_D6
Net Char_LCD_GPIO_IO<5> LOC = AC5 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_D5
Net Char_LCD_GPIO_IO<6> LOC = AB6 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_D4
Net Char_LCD_GPIO_IO<7> LOC = AC4 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_D3
Net Char_LCD_GPIO_IO<8> LOC = AB5 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_D2
Net Char_LCD_GPIO_IO<9> LOC = AB7 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_D1
Net Char_LCD_GPIO_IO<10> LOC = Y8 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN; #LCD_D0
*/
//==============================================================================
//
//
INTERNAL FUNCTIONS
//
//==============================================================================
void WaitForBusyFlag(void)
{
Xuint32 LCD_Status;
XGpio_mSetDataDirection(LCD_BASEADDR, 1, 0xFFFFF8FF);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000100);
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000500);
usleep(10);
LCD_Status = XGpio_mReadReg(LCD_BASEADDR, 1);
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000100);
usleep(10);
//xil_printf("\r\nLCD status = 0x%X", LCD_Status);
while (LCD_Status & 0x00000080){
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000100);
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000500);
usleep(10);
LCD_Status = XGpio_mReadReg(LCD_BASEADDR, 1);
//xil_printf("\r\nLCD status = 0x%X", LCD_Status);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000100);
usleep(10);
}
//set LCD data to output again
XGpio_mSetDataDirection(LCD_BASEADDR, 1, 0xFFFFF800);
}
void InitInst(void)
{
Xuint32 LCD_Status;
/* 4-bit mode
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000003); //function set 4-bit mode,
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000043); //set enable and data
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000003);
usleep(INIT_DELAY);
*/
XGpio_mSetDataDirection(LCD_BASEADDR, 1, 0xFFFFF800);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x0000003C);//function set, 8-bit mode, 2 lines, 8 X 11 dots
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x0000043C); //set enable and data
usleep(10);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x0000003C);
//read the Busy Flag
XGpio_mSetDataDirection(LCD_BASEADDR, 1, 0xFFFFF8FF);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000100);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000500);
LCD_Status = XGpio_mReadReg(LCD_BASEADDR, 1);
//xil_printf("\r\nLCD status = 0x%X", LCD_Status);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000100);
while (LCD_Status & 0x00000080){
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000100);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000500);
LCD_Status = XGpio_mReadReg(LCD_BASEADDR, 1);
//xil_printf("\r\nLCD status = 0x%X", LCD_Status);
XGpio_mSetDataReg(LCD_BASEADDR, 1, 0x00000100);
}
//set LCD data to output again
XGpio_mSetDataDirection(LCD_BASEADDR, 1, 0xFFFFF800);
}
//write instruction on 8 bits
void WriteInst8(unsigned long inst)
{
unsigned long printinst;
XGpio_mSetDataDirection(LCD_BASEADDR, 1, 0xFFFFF800);
printinst = 0x00000400 | inst;
评论
查看更多