显现成果:
芯片晶振11.0592
#include
#define uchar unsigned char
#define uint unsigned int
#define dataport P0 //数据口
sbit CS1=P2^4; //左显引脚
sbit CS2=P2^3; //右显引脚
sbit RST=P2^2; //复位引脚
sbit rs=P2^7; //数据或指令寄存器引脚
sbit rw=P2^6; //读或写操作引脚
sbit en=P2^5; //读写时能引脚
void delay(unsigned long v); //延时
void wcode(uchar c,uchar csl,uchar csr); //写指令
void wdata(uchar c,uchar csl,uchar csr); //写数据
void set_startline(uchar i); //设置起始行
void set_xy(uchar x,uchar y); //设置X,Y方向
void dison_off(uchar k); //显现器开或关
void reset();//复位
void lcd_init(); //显现器初始化
void lw(uchar x,uchar y,uchar dd); //将数据写入左右半屏
void display_hz(uchar xx,uchar yy,uchar n,uchar fb); //显现汉字函数
uchar code hz[]; //汉字字摸
uchar code asc[];//数字字摸
uchar hour1,hour0;
uchar minute1,minute0;
uchar sec1,sec0;
uchar hour=0,minute=0,sec=0;
uchar osc=0;
void Timer0(void)//设定定时器0 50ms
{
TMOD = 0x01;
TH0 = 0x3C;
TL0 = 0x0B0;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void time0init()interrupt 1 //定时器中止履行,时,分,秒核算
{
TR0=0;
osc++;
if(osc==20){sec++;osc=0;}
if(sec==60){minute++; sec=0;}
if(minute==60){hour++;minute=0;}
if(hour==24){hour=0;}
hour1=hour/10;
hour0=hour%10;
minute1=minute/10;
minute0=minute%10;
sec1=sec/10;
sec0=sec%10;
TH0=0x3c;
TL0=0x0B0;
EA=1;
ET0=1;
TF0=0;
TR0=1;
}
#include “12864hh.h”
void main(void)
{
lcd_init();
delay(1000);
Timer0();
while(1)
{
display_hz(2,0,0,0);
display_hz(4,0,1,0);
display_hz(6,0,2,0);
display_hz(8,0,3,0);
display_hz(10,0,4,0);
display_hz(0,4,5,0);
display_hz(6,4,6,0);
display_hz(12,4,7,0);
display_asc(2,4,hour1,0);
display_asc(3,4,hour0,0);
display_asc(8,4,minute1,0);
display_asc(9,4,minute0,0);
display_asc(14,4,sec1,0);
display_asc(15,4,sec0,0);
}
delay(60000);
}