各位大侠,我编了个1602液晶显示的程序,用ATMEL89S52工作正常,换成STC12C5A08S2就无法工作。很奇怪,求解。有图有真相,谢谢!!
程序附上:
#include <AT89X52.H>
#define uchar unsigned char
#define uint unsigned int
#define dat_delay 200
#define dat_port P0 //1602液晶数据接口,由跳线跳接
#define com_port P2 //1602液晶控制接口,由跳线跳接
sbit led=P1^3;
sbit rs=com_port^6;
sbit rw=com_port^5;
sbit lcden=com_port^4;
uchar table1[]="SIMPLE SN51A_1.1";
uchar table2[]="GOOD LUCK TO YOU";
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void delay1(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=600;b>0;b--);
}
void write_com(uchar com) ////1602液晶控制函数
{
rs=0;
rw=0;
// lcden=0;
dat_port=com;
delay(dat_delay );
lcden=1;
delay(dat_delay );
lcden=0;
}
void write_date(uchar dat) ////1602液晶写数据函数
{
rs=1;
rw=0;
dat_port=dat;
// lcden=0;
delay(dat_delay );
lcden=1;
delay(dat_delay );
lcden=0;
}
void init1602() //1602液晶初始化函数
{
write_com(0x38); //液晶显示方式设置
delay(dat_delay );
// write_com(0x0f); //光标开 闪烁
write_com(0x0c); //光标不开 不闪烁
delay(dat_delay );
write_com(0x06); //数据指针顺序设置
delay(dat_delay );
write_com(0x01); //液晶屏幕清屏命令
delay(dat_delay );
}
void main()
{
uchar a=0;
init1602(); //初始化1602液晶
//1602液晶显示器地址:第一行从0X80开始--0X81-0X82---...0X8F
// :第二行从0XC0开始--0XC1-0XC2---...0XCF
led=0;
write_com(0x80);//从第一行第一个字符显示"IMPLE SN51A_1.1"
delay(dat_delay );//#define dat_delay 200
for(a=0;a<16;a++)
{
write_date(table1[a]);
delay(dat_delay );
}
write_com(0xc0);//从第二行第一个字符显示"GOOD LUCK TO YOU"
delay(dat_delay );
for(a=0;a<16;a++)
{
write_date(table2[a]);
delay(dat_delay );
}
delay1(300);
for(a=0;a<40;a++) //循环移位//左移16之后再移3个空位从右边出来
{
write_com(0x18); //左移位指令
delay1(20);
}
while(1);
} |