我用lpc2114驱动lcd1602,程序如下,烧进单片机后,lcd1602无显示啊,大虾们帮我看下程序的错误所在,谢谢!!!!!!
#include "LPC21xx.h" #include "string.h"
#define RS 0x00001000 //P0.12接RS RW接地 #define E 0x00002000 //P0.13接E
void Delayms(unsigned int count) { unsigned int i; for(i=0;i<count;i++); }
void WriteCommand(unsigned char Com) { IO0SET=(Com<<0x0000000F); IO0CLR=RS; IO0SET=E; IO0CLR=E; //IO0CLR=RW; }
void WriteData(unsigned char Dat) { IO0SET=(Dat<<0x0000000F); IO0CLR=RS; IO0SET=E; IO0CLR=E; //IO0CLR=RW; }
void Init() { Delayms(1000); WriteCommand(0x38); Delayms(400); WriteCommand(0x38); Delayms(400); WriteCommand(0x38); Delayms(2800); WriteCommand(0x38); Delayms(2800); WriteCommand(0x08); Delayms(2800); WriteCommand(0x01); Delayms(2800); WriteCommand(0x06); Delayms(2800); WriteCommand(0x0C); }
void Show_Text(char *Text,char row) { unsigned char i; if(row==0) { WriteCommand(0x80); Delayms(2800); for(i=0;i<strlen(Text);i++) { WriteData(Text); Delayms(2800); } } else { WriteCommand(0xC0); Delayms(2800); for(i=0;i<strlen(Text);i++) { WriteData(Text); Delayms(2800); } } }
void main() {char Text1[16]="NIOS II on DE2"; char Text2[16]="Nice to See You!"; PINSEL0=0x00000000; IO0DIR =0xffffffff; Init(); while(1) { Show_Text(Text1,0); Show_Text(Text2,1); } } |