基于12Cxx系列51单片机简单的时钟万年历程序Word文档下载推荐.docx
《基于12Cxx系列51单片机简单的时钟万年历程序Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《基于12Cxx系列51单片机简单的时钟万年历程序Word文档下载推荐.docx(13页珍藏版)》请在冰豆网上搜索。
sbitlcdrw=P2^6;
//RW
sbitlcdrs=P2^5;
//RS
sbits0=P2^4;
//功能键设置
sbits1=P2^0;
sbits2=P2^1;
sbits3=P2^2;
sbits4=P2^5;
sbits5=P2^3;
sbitD0=P1^0;
voiddelay(uintz)//延时子函数
{
uintx,y;
for(x=1;
x<
=z;
x++)
for(y=1;
y<
=80;
y++);
}
voidLCD_ShuJu(uchardata0)//写数据子函数
{
lcdrs=1;
lcdrw=0;
d0=data0;
delay(5);
lcden=0;
lcden=1;
voidLCD_ZhiLing(ucharcom)//写指令子函数
lcdrs=0;
d0=com;
/******************初始化子函数*******************************/
voidinit()
{
D0=0;
num1=6;
year=2010;
mon=7;
day=31;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
LCD_ZhiLing(0x38);
//显示模式设置
LCD_ZhiLing(0x0c);
//光标设置
LCD_ZhiLing(0x06);
LCD_ZhiLing(0x01);
//清屏
LCD_ZhiLing(0x80+1);
//指针初始化
for(num=0;
num<
14;
num++)//写入初始化数据
{
LCD_ShuJu(table[num]);
//delay(10);
}
LCD_ZhiLing(0x80+0x44);
for(num=0;
8;
num++)
LCD_ShuJu(table1[num]);
voidwrite_sfm(ucharadd,uchardata0)//显示时分秒子函数
ucharshi,ge;
shi=data0/10;
ge=data0%10;
LCD_ZhiLing(0x80+0x40+add);
LCD_ShuJu(0x30+shi);
LCD_ShuJu(0x30+ge);
voidwrite_yr(ucharadd,uchardata0)//显示月日子函数
LCD_ZhiLing(0x80+add);
voidwrite_year(ucharadd,uintdata0)//显示年子函数
ucharshi,ge,bai,qian;
shi=(data0%100)/10;
bai=(data0%1000)/100;
qian=data0/1000;
LCD_ShuJu(0x30+qian);
LCD_ShuJu(0x30+bai);
/************************************时分秒设置子函数******************************/
voidkeyscan()
/*******************************定位功能键扫描*******************************/
P2=0xef;
if(s1==0)
delay(5);
{
s1num++;
while(!
s1);
if(s1num==1)
{
TR0=0;
//关定时器0,时间停止走动
LCD_ZhiLing(0x80+0x40+11);
LCD_ZhiLing(0x0f);
//光标闪烁
}
if(s1num==2)
{
LCD_ZhiLing(0x80+0x40+8);
}
if(s1num==3)
{
LCD_ZhiLing(0x80+0x40+5);
if(s1num==4)
LCD_ZhiLing(0x80+14);
if(s1num==5)
LCD_ZhiLing(0x80+10);
if(s1num==6)
LCD_ZhiLing(0x80+7);
if(s1num==7)
LCD_ZhiLing(0x80+4);
if(s1num==8)//s1按下第四次时时间继续走动,不显示光标
s1num=0;
TR0=1;
LCD_ZhiLing(0x0c);
}
/*******************定位功能键起作用时扫描加时功能键*****************/
if(s1num!
=0)
{
P2=0xef;
if(s2==0)
delay(5);
if(s2==0)
{
while(!
s2);
if(s1num==1)
{sec++;
if(sec==60)sec=0;
write_sfm(10,sec);
LCD_ZhiLing(0x80+0x40+11);
}
if(s1num==2)
{min++;
if(min==60)min=0;
write_sfm(7,min);
LCD_ZhiLing(0x80+0x40+8);
if(s1num==3)
{hour++;
if(hour==24)hour=0;
write_sfm(4,hour);
LCD_ZhiLing(0x80+0x40+5);
}
if(s1num==4)
{
num1++;
if(num1==7)
{
num1=0;
}
LCD_ZhiLing(0x80+12);
for(num=0;
3;
{
LCD_ShuJu(table2[num1][num]);
}LCD_ZhiLing(0x80+14);
if(s1num==5)
{day++;
if(day==32)day=0;
write_yr(9,day);
LCD_ZhiLing(0x80+10);
if(s1num==6)
{mon++;
if(mon==13)mon=0;
write_yr(6,mon);
LCD_ZhiLing(0x80+7);
if(s1num==7)
{year++;
if(year==2101)year=0;
write_year(1,year);
LCD_ZhiLing(0x80+4);
}
}
/*******************定位功能键起作用时扫描减时功能键******************/
if(s1num!
if(s3==0)
if(s3==0)
s3);
{sec--;
if(sec==-1)sec=59;
{min--;
if(min==-1)min=59;
{hour--;
if(hour==-1)hour=23;
if(s1num==4)
num1--;
if(num1==-1)
num1=6;
{day--;
if(day==0)day=31;
{mon--;
if(mon==0)mon=12;
{year--;
if(year==1989)year=2100;
}
/********************************中断处理**************************************/
voidtime0()interrupt1
TH0=(65536-50000)/256;
count++;
if(count==19)
{
count=0;
sec++;
if(sec==60)
sec=0;
min++;
if(min==60)
min=0;
D0=1;
delay(1000);
D0=0;
//整点报时
hour++;
if(hour==24)
hour=0;
day++;
num1++;
if(day==32)
{
day=0;
mon++;
if(mon==13)
{
mon=0;
year++;
if(year==2101)year=0;
write_year(1,year);
}
write_yr(6,mon);
write_yr(9,day);
if(num1==7)
num1=0;
LCD_ZhiLing(0x80+12);
for(num=0;
LCD_ShuJu(table2[num1][num]);
}
write_sfm(4,hour);
write_sfm(7,min);
}
write_sfm(10,sec);
}
/******************************主函数**************************/
voidmain()
init();
while
(1)
keyscan();