#include<reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit e=P1^2;
sbit rs=P1^4;
sbit rw=P1^3;
sbit psb=P1^5;
void write_com(uchar com1);
void write_data(uchar data1);
void xianshi(void);
void init(void);
void delay(uint t)
{
uint j;
for(;t>0;t--)
for(j=19;j>0;j--);
}
void main(void)
{
init();
while(1);
{
xianshi();
while(1);
}
}
void write_com(uchar com1)//写指令
{
rw=1;
rs=0;
delay(2) ;
P2=com1;
e=1;
delay(10);
e=0;
delay(10);
}
void write_data(uchar data1)//写数据
{
rw=1;
rs=1;
delay(2) ;
P2 = data1;
e=1;
delay(10);
e = 0;
delay(3) ;
}
void init(void)
{
delay(3);
write_com(0x30);
delay(5);
write_com(0x30);
delay(5);
write_com(0x0f);
delay(4);
write_com(0x01);
delay(240);
write_com(0x06);
delay(10);
}
void xianshi(void)
{
uchar i;
uchar a;
a=0x10;
write_com(0x80);
delay(2);
for (i=0;i<16;i++)
{
write_data(a);
delay(2);
a++;
}
}
-
一周热门 更多>