这是图和原理图:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^4;//位定义
sbit rw=P2^5;
sbit e=P2^6;
uchar table1[]=" whh";
uchar table2[]="LCD1602 test ok!";
void delay_50us(uint t) //延时函数,在12兆赫兹的晶振频率下50us的延时
{
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_com(uchar com)//写指令
{
e=0;
rs=0;
rw=0;
P0=com;
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void write_data(uchar dat)//输入数据
{
e=0;
rs=1;
rw=0;
P0=dat; //送数据
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void init(void)
{
delay_50us(300); //延时15ms,换算15ms等于300us
write_com(0x38);
delay_50us(100);
write_com(0x38);
delay_50us(100);//延时5ms
write_com(0x38);
write_com(0x38);
write_com(0x08);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
}
void main()
{
uchar j;
init();
write_com(0x80);
for(j=0;j<16;j++)
{
write_data(table1[j]);
delay_50us(10);
}
write_com(0x80+0x40);
for(j=0;j<16;j++)
{
write_data (table2[j]);
delay_50us(10);
}
while(1);
}
程序没做好,我确定!
一周热门 更多>