一、XPS中的设置
1.在XPS添加一个XPS General Purpose IO,并将其命名为“Char_LCD”。
注:这里的命名有一定的规则,将其命名为“Char_LCD”,是因为在后来的C程序中调用LCD基地址的时候使用的名字为“XPAR_CHAR_LCD_BASEADDR”,如果将这个命名为其他的(比如XX),那么在下面的lcd.h中也要将
#define LCD_BASEADDR XPAR_CHAR_LCD_BASEADDR
这一句中的"CHAR_LCD"改成对应的名称。
2.配置Char_LCD中Channel 1的GPIO Data Channel Width为11并在Ports中设置为Connected to External Ports。
3.在System.ucf加入相应的管教约束,这里提供Genesys Digilent开发板中对应的管脚约束,管脚的名称自然而言和上面使用的名称对应。
#Char_LCD constraints
#Char_LCD_GPIO_IO_pin<0> corresponds to LCD_E
#Char_LCD_GPIO_IO_pin<1> corresponds to LCD_RS
#Char_LCD_GPIO_IO_pin<2> corresponds to LCD_RW
#Char_LCD_GPIO_IO_pin<3> corresponds to LCD_D7, <4> to LCD_D6... <10> to LCD_D0
Net Char_LCD_GPIO_IO_pin<0> LOC = AA5 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<1> LOC = V7 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<2> LOC = W6 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<3> LOC = AD7 | IOSTANDARD=LVCMOS33 |TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<4> LOC = AC7 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<5> LOC = AC5 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<6> LOC = AB6 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<7> LOC = AC4 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<8> LOC = AB5 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<9> LOC = AB7 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
Net Char_LCD_GPIO_IO_pin<10> LOC = Y8 | IOSTANDARD=LVCMOS33 | TIG | PULLDOWN;
二、SDK中的代码模板
1.将lcd.h、lcd.c、sleep.h和sleep.c添加到工程的src文件夹中,并在需要调用LCD的代码中添加
#include "lcd.h"
2.在使用LCD之前需要进行初始化,添加下面代码:
LCDOff();
LCDClear();
LCDOn();
LCDInit();
3.需要在LCD中显示时,调用下面函数
LCDPrintString(First_Line, Second_Line; //First_Line和Second_Line都是char*类型
附件:博文中提到文件的源代码:
1.lcd.h
/*******************************************************************************
*
*
XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
*
SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
*
XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
*
AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
*
OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS
*
IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
*
AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
*
FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY
*
WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
*
IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
*
REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
*
INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*
FOR A PARTICULAR PURPOSE.
*
*
(c) Copyright 2007 Xilinx, Inc.
*
All rights reserved.
*
******************************************************************************/
#ifndef LCD_H
#define LCD_H
//=====================
// TEST FUNCTIONS
//=====================
void LCDTest();
void LCDTestMenu();
void LCDTestInput(char ch);
//=====================
// EXTERNAL FUNCTIONS
//=====================
#define LCD_BASEADDR XPAR_CHAR_LCD_BASEADDR //根据需要修改这里
void LCDOn();
void LCDOff();
void LCDClear();
void LCDInit();
void LCDEnableDisplayShift();
void LCDEnableCursorBlink();
void LCDDisableDisplayShift();
void LCDDisableCursorBlink();
void MoveCursorHome();
void MoveCursorRight();
void MoveCursorLeft();
void LCDSetLine(int line);
void LCDPrintChar(char c);
void LCDPrintString(char * line1, char * line2);
//=====================
// INTERNAL FUNCTIONS
//=====================
void InitInst(void);
void WriteInst(unsigned long inst1, unsigned long inst2);
void WriteData(unsigned long data1, unsigned long data2);
void WriteInst8(unsigned long inst);
void WriteData8(unsigned long data);
#endif
2.lcd.c
/******************************************************************************
*
*
XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
*
AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND
*
SOLUTIONS FOR XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE,
*
OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
*
APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION
*
THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
*
AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
*
FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY
*
WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
*
IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
*
REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
*
INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*
FOR A PARTICULAR PURPOSE.
*
*
(c) Copyright 2007 Xilinx Inc.
*
All rights reserved.
*
******************************************************************************/
#include
#include "sleep.h"
#include "xgpio_l.h"
#include "xparameters.h"
#include "lcd.h"
评论
查看更多