📄 lcd.c
字号:
#include<stdio.h>
//#include<absacc.h>
#include<reg51.h>
sbit rs=P1^7;
sbit rw=P1^6;
sbit en=P1^5;
int i,k=0;
int s=0,ts=0,m=0,tm=0,h=0,th=0;
unsigned char inst[]={0x38,0x01,0x06,0x0c};
unsigned char coded[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
void delay(int i)
{ while(i>0)i--;}
void writeinstruction(unsigned char instructiondata)
{ rs=0;
rw=0;
en=1;
P0=instructiondata;
delay(2);
en=0;
}
void initlcd()
{ writeinstruction(inst[0]);
writeinstruction(inst[1]);
writeinstruction(inst[2]);
writeinstruction(inst[3]);
}
void readdata(unsigned char readdata)
{ rs=1;
rw=0;
en=1;
P0=readdata;
delay(2);
en=0;
}
void display()
{ writeinstruction(0x0C);
writeinstruction(0x8B);
readdata(coded[s]);
s++;
writeinstruction(0x0C);
writeinstruction(0x8A);
readdata(coded[ts]);
if(s==10)
{s=0;ts++;}
writeinstruction(0x0C);
writeinstruction(0x89);
readdata(0x3A);
writeinstruction(0x0C);
writeinstruction(0x88);
readdata(coded[m]);
if(ts==6)
{ts=0;m++;}
writeinstruction(0x0C);
writeinstruction(0x87);
readdata(coded[tm]);
if(m==10)
{m=0;tm++;}
writeinstruction(0x0C);
writeinstruction(0x86);
readdata(0x3A);
writeinstruction(0x0C);
writeinstruction(0x85);
readdata(coded[h]);
if(tm==6)
{tm=0;h++;}
writeinstruction(0x0C);
writeinstruction(0x84);
readdata(coded[th]);
if(h==10)
{h=0;th++;}
if(th==2)
{if(h==4)
{s=ts=m=tm=h=th=0; }
}
writeinstruction(0x0C);
writeinstruction(0xC6);
readdata(0x54);
writeinstruction(0x0C);
writeinstruction(0xC7);
readdata(0x69);
writeinstruction(0x0C);
writeinstruction(0xC8);
readdata(0x6D);
writeinstruction(0x0C);
writeinstruction(0xC9);
readdata(0x65);
}
void main()
{ delay(100);
initlcd();
IE=0x88;
TCON=0x00;
TMOD=0x10;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR1=1;
while(1);
}
void timer1(void)interrupt 4 using 1
{ k++;
if(k==14)
{k=0;display();}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -