本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include <reg52.h>
#include <absacc.h>
#define LCD_WR_COM XBYTE[0x8000]
#define LCD_RD_BF XBYTE[0x8001]
#define LCD_WR_RAM XBYTE[0x8002]
#define LCD_RD_RAM XBYTE[0x8003]
sbit led1 = P1^3;
sbit L=P1^2;
unsigned char x,y;
unsigned char code LCD_DATA[16] =
{
'0','1','2','3','4','5','6','7','8','9','a','v','c','e','e','-'
};
unsigned char shi,fen,miao;
void msDelay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<111;j++); //111
}
void wait(void)
{
while((LCD_RD_BF & 0x80) == 0x80);
}
void init_lcd(void)
{
LCD_WR_COM = 0x3c; // Set Function, 2 line, 8 bit data, 5x8
wait();
LCD_WR_COM = 0x0f; // Set Switch, display ON
wait();
LCD_WR_COM = 0x01; // Clear display
wait();
LCD_WR_COM = 0x06; // Set Mode,
wait();
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void write_data(unsigned char a)
{
LCD_WR_RAM = a;
wait();
}
void display(unsigned char temp, unsigned char s)
{
x=s/10;
y=s%10;
LCD_WR_COM = temp + 0x80;
write_data(LCD_DATA[x]);
msDelay(1);
LCD_WR_COM=x+0x01+0x80;
write_data(LCD_DATA[y]);
}
void timer0(void)interrupt 1
{
unsigned int aa=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==20)
{
aa=0;
miao++;
if(miao==59)
{
miao=0;
fen++;
if(fen==59)
{
fen=0;
shi++;
if(shi==23)
{
shi=0;
}
display(0x00,shi);
}
display(0x03,fen);
}
display(0x06,miao);
}
}
void main()
{
led1=0;
init_lcd();
} |