菜鸟求大神指点lcd1602四总线驱动的,感激不尽!
时间:10-02
整理:3721RD
点击:
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;
void init();
void delay(uint x);
void writecom(uchar com);
void writedata(uchar date);
uchar table1[]=" 1236595262 ";
uchar table2[]=" 1234567890 ";
void main()
{
uint i,j=0;
init();
writecom(0x80+0x08);
writedata(table1[5]);
delay(10);
writecom(0x80+0x4a);
writedata(table2[5]);
while(1);
}
void init()
{
// delay(15);
writecom(0x28);
// delay(5);
writecom(0x28);
// delay(5);
writecom(0x28);
writecom(0x08);
writecom(0x01);
writecom(0x06);
writecom(0x0c);
// writecom(0x0c);
}
void writecom(uchar com)
{
uchar temp;
e=0;
rs=0;
rw=0;
temp=com&0xf0; //高四位
P1&=0x0f;
P1 |=temp;
// delay(10);
e=1;
// delay(15);
e=0;
temp=(com<<4)&0xf0;
P1&=0x0f;
P1 |=temp;
delay(15);
e=1;
delay(30);
e=0;
}
void writedata(uchar date)
{
uchar temp;
e=0;
rs=1;
rw=0;
temp=date&0xf0;
P1&=0x0f;
P1 |=temp;
// delay(10);
e=1;
// delay(15);
e=0;
temp=(date<<4)&0xf0;
P1&=0x0f;
P1 |=temp;
delay(15);
e=1;
delay(30);
e=0;
}
void delay(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
#define uint unsigned int
#define uchar unsigned char
sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;
void init();
void delay(uint x);
void writecom(uchar com);
void writedata(uchar date);
uchar table1[]=" 1236595262 ";
uchar table2[]=" 1234567890 ";
void main()
{
uint i,j=0;
init();
writecom(0x80+0x08);
writedata(table1[5]);
delay(10);
writecom(0x80+0x4a);
writedata(table2[5]);
while(1);
}
void init()
{
// delay(15);
writecom(0x28);
// delay(5);
writecom(0x28);
// delay(5);
writecom(0x28);
writecom(0x08);
writecom(0x01);
writecom(0x06);
writecom(0x0c);
// writecom(0x0c);
}
void writecom(uchar com)
{
uchar temp;
e=0;
rs=0;
rw=0;
temp=com&0xf0; //高四位
P1&=0x0f;
P1 |=temp;
// delay(10);
e=1;
// delay(15);
e=0;
temp=(com<<4)&0xf0;
P1&=0x0f;
P1 |=temp;
delay(15);
e=1;
delay(30);
e=0;
}
void writedata(uchar date)
{
uchar temp;
e=0;
rs=1;
rw=0;
temp=date&0xf0;
P1&=0x0f;
P1 |=temp;
// delay(10);
e=1;
// delay(15);
e=0;
temp=(date<<4)&0xf0;
P1&=0x0f;
P1 |=temp;
delay(15);
e=1;
delay(30);
e=0;
}
void delay(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}