回复 楼主 wuji4115 的帖子
#include "systemInit.h"
#define uchar unsigned char
#define uint unsigned int
#define lcd_port GPIO_PORTA_BASE //LCD¹¤×÷ģʽÉèÖÿÚ
#define lcd_data GPIO_PORTC_BASE //Êý¾Ý¿Ú
#define lcd_rs GPIO_PIN_5
#define lcd_rw GPIO_PIN_4
#define lcd_en GPIO_PIN_3
void delay(uint xms)
{
uint i,j;
for(j=0;i
for(i=0;i<110;i++);
}
unsigned char lcd_busy()
{
unsigned char result;
GPIOPinWrite(lcd_port,lcd_rs,0x00); //rs=0
GPIOPinWrite(lcd_port,lcd_rw,0xFF); //rw=1
GPIOPinWrite(lcd_port,lcd_en,0xFF); //en=1
GPIOPinTypeGPIOInput(lcd_data,0xFF); //Êý¾Ý¿ÚÉèÖóÉÊä
result=(GPIOPinRead(lcd_data,0x80)&0x80);
GPIOPinWrite(lcd_port,lcd_en,0x00);
return result;
}
void lcd_write_cmd(uchar com)
{
while(lcd_busy());
GPIOPinWrite(lcd_port,lcd_rs,0x00);
GPIOPinWrite(lcd_port,lcd_rw,0x00);
GPIOPinWrite(lcd_port,lcd_en,0x00);
GPIOPinWrite(lcd_data,0xFF,com);
delay(5);
GPIOPinWrite(lcd_port,lcd_en,0xFF);
delay(5);
GPIOPinWrite(lcd_port,lcd_en,0x00);
}
void lcd_write_dat(uchar date)
{
while(lcd_busy());
GPIOPinWrite(lcd_port,lcd_rs,0xFF);
GPIOPinWrite(lcd_port,lcd_rw,0x00);
GPIOPinWrite(lcd_port,lcd_en,0x00);
GPIOPinWrite(lcd_data,0xFF,date);
delay(5);
GPIOPinWrite(lcd_port,lcd_en,0xFF);
delay(5);
GPIOPinWrite(lcd_port,lcd_en,0x00);
}
void lcd_write_string(uchar *str)
{
while(*str!='\0') //δ½áÊø
{
lcd_write_dat(*str++);
delay(5);
}
}
void lcd_pos(uchar x,uchar y) //´ÓµÚXÐеĵÚYλÖÿªÊ¼ÏÔʾ
{
uchar pos;
if(x==1) //µÚÒ»ÐÐ
{ x=0x80;}
else if(x==2) //µÚ¶þÐÐ
{ x=0x90;}
else if(x==3) //µÚÈýÐÐ
{ x=0x88;}
else if(x==4) //µÚËÄÐÐ
{ x=0x98;}
pos=x+y-1; //Ê×µØַΪ0X80
lcd_write_cmd(pos);
}
void lcd_init()
{
//LCD_PSB=1; //²¢Ðз½Ê½
//LCD_RST=1; //²»¸´Î»
lcd_write_cmd(0x30);
delay(5);
lcd_write_cmd(0x0c); //¿ªÏÔʾ£¬²»ÏÔʾ¹â±ê
delay(5);
lcd_write_cmd(0x06); //дһ¸ö×Ö·ûºóµØÖ·Ö¸Õë×Ô¶¯¼Ó1
delay(5);
lcd_write_cmd(0x01); //ÇåÆÁ
delay(5);
}
// Ö÷º¯Êý£¨³ÌÐòÈë¿Ú£©
int main(void)
{
jtagWait(); // ·ÀÖ¹JTAGʧЧ£¬ÖØÒª£¡
clockInit(); // ʱÖÓ³õʼ»¯£º¾§Õñ£¬6MHz
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeGPIOOutput(lcd_port,lcd_rs|lcd_rw|lcd_en);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeGPIOOutput(lcd_data,0xFF);
lcd_init();
for (;;)
{
lcd_pos(1,1);
lcd_write_string("´²Ç°Ã÷Ô¹â");
}
}