一、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"
評論
查看更多