本帖最后由 lyh123456 于 2011-3-9 19:20 编辑
写了一个基于LPC2132的1602液晶驱动程序,但是在proteus仿真里总是不显示,请高手帮忙看看啊!
程序如下:
#include <LPC213X.H>
void delay1us()
{
unsigned long i;
i=80;
while(i--);
}
void delay1ms(unsigned char z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=1500;y>0;y--);
}
#define Rs (1<<0)
#define Rw (1<<1)
#define En (1<<2)
#define lcddate (0xff<<8) //液晶数据位
unsigned char num;
const unsigned char table1[]={"PICE:0000.0 "}; //显示初始内容
const unsigned char table2[]={"FP:00.0DI:000.0"};
void write_com(unsigned char com) //写命令
{
delay1ms(40);
IO0SET|=Rs;
delay1us();
IO0SET|=Rw;
delay1us();
IO0CLR|=lcddate;
delay1us();
IO0SET|=com;
delay1us();
IO0SET|=En;
delay1us();
IO0CLR|=En;
delay1us();
}
void write_date(unsigned char dat) //写数据
{
delay1ms(40);
IO0SET|=Rs;
delay1us();
IO0SET|=Rw;
delay1us();
IO0CLR|=lcddate;
IO0SET|=dat;
delay1us();
IO0SET|=En;
delay1us();
IO0CLR|=En;
delay1us();
}
void lcddisplay(unsigned char x,unsigned char y,const unsigned char *str)
{
switch(x)
{
case 0:
write_com(0x80+y);break;
case 1:
write_com(0xc0+y);break;
}
while(*str)
{
write_date(*str);
str++;
}
}
void GPIO_Init(void) //IO初始化
{
PINSEL0=0x00000000;
PINSEL1=0x00000000;
IO0DIR|=0xffff;
IO0SET|=0xffff;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_date(table1[num]);
delay1ms(5);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_date(table2[num]);
delay1ms(5);
}
}
int main(void)
{
GPIO_Init();
while(1);
} |