调了一下午的12864,总是什么都不显示。希望有人能够给看看程序有没有问题。多谢了。
#include<reg52.h>
#include<stdlib.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit LCD_EN=P2^4;
sbit LCD_RW=P2^2;
sbit LCD_RS=P2^3;
sbit LCD_RET=P2^5;
sbit LCD_CS1=P2^0;
sbit LCD_CS2=P2^1;
uchar dis1[10];
uchar code dis2[]={"www.21ic.com"};
uchar code dis3[]={"单片机学习网"};
uchar code dis4[]={"------------"};
void delay1ms(uint xms)//延时1ms
{
uint i,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--);
}
void write_cmd(uchar cmd)//写指令
{
LCD_RS=0;
LCD_RW=0;
LCD_EN=0;
P0=cmd;
delay1ms(5);
LCD_EN=1;
delay1ms(5);
LCD_EN=0;
}
void write_dat(uchar dat)//写显示数据
{
LCD_RS=1;
LCD_RW=0;
LCD_EN=0;
P0=dat;
delay1ms(5);
LCD_EN=1;
delay1ms(5);
LCD_EN=0;
}
void lcd_pos(uchar X,uchar 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;
write_cmd(X+Y);
}
void makerand() //产生随机数
{
uint ran;
ran=rand();
dis1[0]=ran/10000+0x30;
dis1[1]=ran%10000/1000+0x30;
dis1[2]=ran%1000/100+0x30;
dis1[3]=ran%100/10+0x30;
dis1[4]=ran%10+0x30;
ran=rand();
dis1[5]=ran/10000+0x30;
dis1[6]=ran%10000/1000+0x30;
dis1[7]=ran%1000/100+0x30;
dis1[8]=ran%100/10+0x30;
dis1[9]=ran%10+0x30;
}
void lcd_init(void)//初始化
{
LCD_RET=0;
delay1ms(50);
LCD_RET=1;
write_cmd(0x30);
delay1ms(5);
write_cmd(0x30);
delay1ms(5);
write_cmd(0x0c);
delay1ms(5);
write_cmd(0x01);
delay1ms(5);
}
void main()
{
uchar i;
lcd_init();
lcd_pos(2,0);
i=0;
while(dis2!='\0')
{
write_dat(dis2);
i++;
}
lcd_pos(3,0);
i=0;
while(dis3!='\0')
{
write_dat(dis3);
i++;
}
lcd_pos(4,0);
i=0;
while(dis4!='\0')
{
write_dat(dis4);
i++;
}
while(1)
{
lcd_pos(1,0);
makerand();
for(i=0;i<10;i++)
{write_dat(dis1[1]);}
}
} |