#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
sbit psb=P3^2;
uchar table[]="身体健康每天快乐";
void delay_50us(uint t)
{
uchar j;
for(;t>0;t--)
for(j=19;j>0;j--);
}
void delay_50ms(uint t)
{
uint j;
for(;t>0;t--)
for(j=6245;j>0;j--);
}
void write_12864com(uchar com)
{
rw=0;
rs=0;
delay_50us(1);
P0=com;
e=1;
delay_50us(10);
e=0;
delay_50us(2);
}
void write_12864dat(uchar dat)
{
rw=0;
rs=1;
delay_50us(1);
P0=dat;
e=1;
delay_50us(10);
e=0;
delay_50us(2);
}
void init(void)
{
delay_50ms(2);
write_12864com(0x30);
delay_50us(4);
write_12864com(0x30);
delay_50us(4);
write_12864com(0x0f);
delay_50us(4);
write_12864com(0x01);
delay_50us(240);
write_12864com(0x06);
delay_50us(10);
}
/*void display1(void)
{
uchar i,a;
a=0x10;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<16;i++)
{
write_12864dat(a);
delay_50us(1);
a++;
}
}*/
/*void display2(void)
{
uchar i,a,b;
a=0xBA;
b=0xC0;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<8;i++)
{
write_12864dat(a);
write_12864dat(b);
delay_50us(1);
b++;
}
}*/
void display3(void)
{
uchar i;
write_12864com(0x80);
for(i=0;i<16;i++)
{
write_12864dat(table[i]);
delay_50us(1);
}
}
void main()
{
init();
while(1)
{
display3();
while(1);
}
}
变量直接采用‘0’+a的形式就行,a为你自己设置的变量。
|