📄 lcd_c.c
字号:
//液晶驱动程序
//时间:2005/4/16
#include<reg51.h>
#define uchar unsigned char
//#define com 0x50
//#define dat 0x61
#define x1 0x52
#define yl 0x53
#define c_code 0x54
#define count 0x55
#define datbus P1
sbit a0=P3^4;
sbit rw=P3^5;
sbit e2=P3^6;
sbit e1=P3^7;
void delay(uchar t)
{uchar i,j;
for(i=0;i<=t;i++)
for(j=0;j<=100;j++);}
void write_l(uchar com) //write left display
{a0=0;
rw=1;
do
{datbus=0xff;
e1=1;
ACC=datbus;
e1=0;
}
while(ACC^7);
rw=0;
datbus=com;
e1=1;
e1=0;
}
void write_r(uchar com) //write right display
{a0=0;
rw=1;
do
{datbus=0xff;
e2=1;
ACC=datbus;
e2=0;
}
while(ACC^7);
rw=0;
datbus=com;
e2=1;
e2=0;}
void write_l_dat(uchar dat)
{
a0=0;
rw=1;
do
{datbus=0xff;
e1=1;
ACC=datbus;
e1=0;
}
while(ACC^7);
a0=1;
rw=0;
datbus=dat;
e1=1;
e1=0;
}
void write_r_dat(uchar dat)
{a0=0;
rw=1;
do
{datbus=0xff;
e2=1;
ACC=datbus;
e2=0;
}
while(ACC^7);
a0=1;
rw=0;
datbus=dat;
e2=1;
e2=0;
}
void read_l_dat(uchar dat)
{
a0=0;
rw=1;
do
{datbus=0xff;
e1=1;
ACC=datbus;
e1=0;
}
while(ACC^7);
a0=1;
datbus=0xff;
e1=0;}
void read_r_dat(uchar dat)
{a0=0;
rw=1;
do
{datbus=0xff;
e2=1;
ACC=datbus;
e2=0;
}
while(ACC^7);
a0=1;
datbus=0xff;
e2=0;
}
void init(void) //init
{write_l(0xe2);
write_r(0xe2);
write_l(0xa4);
write_r(0xa4);
write_l(0xa9);
write_r(0xa9);
write_l(0xa0);
write_r(0xa0);
write_l(0xc0);
write_r(0xc0);
write_r(0xaf);
}
void clear(void)
{uchar pag_addr=0x00;
uchar blank_num;
pag_addr|=0xb8;
write_l(pag_addr);
write_r(pag_addr);
write_l(0x00);
write_r(0x00):
blank_num=0x50;
for(;blank_num>0;blank_num--){
write_l_dat(0x00);
write_r_dat(0x00);
}
}
display()
{}
void main(void)
{ delay(3);
init();
clear();
display();
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -