基于12Cxx系列51单片机简单的时钟万年历程序.docx

上传人:b****5 文档编号:7363870 上传时间:2023-05-11 格式:DOCX 页数:13 大小:17.21KB
下载 相关 举报
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第1页
第1页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第2页
第2页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第3页
第3页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第4页
第4页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第5页
第5页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第6页
第6页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第7页
第7页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第8页
第8页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第9页
第9页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第10页
第10页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第11页
第11页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第12页
第12页 / 共13页
基于12Cxx系列51单片机简单的时钟万年历程序.docx_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

基于12Cxx系列51单片机简单的时钟万年历程序.docx

《基于12Cxx系列51单片机简单的时钟万年历程序.docx》由会员分享,可在线阅读,更多相关《基于12Cxx系列51单片机简单的时钟万年历程序.docx(13页珍藏版)》请在冰点文库上搜索。

基于12Cxx系列51单片机简单的时钟万年历程序.docx

基于12Cxx系列51单片机简单的时钟万年历程序

#include

#include

#defineucharunsignedchar

#defineuintunsignedint

#defined0P0

ucharcodetable[]="2010-07-31SAT";

ucharcodetable1[]="00:

00:

00";

ucharcodetable2[7][3]={"SUN","MON","TUE","WED","THU","FRI","SAT"}

ucharnum,num1,mon,day,count=0,hour,min,sec,s1num,s2num;

uintyear;

sbitlcden=P2^7;//E

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;delay(5);

lcden=1;delay(5);lcden=0;

}

voidLCD_ZhiLing(ucharcom)//写指令子函数

{

lcdrs=0;lcdrw=0;

d0=com;delay(5);lcden=0;delay(5);

lcden=1;delay(5);lcden=0;

}

/******************初始化子函数*******************************/

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;num<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)//显示月日子函数

{

ucharshi,ge;

shi=data0/10;

ge=data0%10;

LCD_ZhiLing(0x80+add);

LCD_ShuJu(0x30+shi);

LCD_ShuJu(0x30+ge);

}

voidwrite_year(ucharadd,uintdata0)//显示年子函数

{

ucharshi,ge,bai,qian;

LCD_ZhiLing(0x80+add);

ge=data0%10;

shi=(data0%100)/10;

bai=(data0%1000)/100;

qian=data0/1000;

LCD_ZhiLing(0x80+add);

LCD_ShuJu(0x30+qian);

LCD_ShuJu(0x30+bai);

LCD_ShuJu(0x30+shi);

LCD_ShuJu(0x30+ge);

}

/************************************时分秒设置子函数******************************/

voidkeyscan()

{

/*******************************定位功能键扫描*******************************/

P2=0xef;

if(s1==0)

{

delay(5);

if(s1==0)

{

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;num<3;num++)//写入初始化数据

{

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!

=0)

{

P2=0xef;

if(s3==0)

{

delay(5);

if(s3==0)

{

while(!

s3);

if(s1num==1)

{sec--;

if(sec==-1)sec=59;

write_sfm(10,sec);

LCD_ZhiLing(0x80+0x40+11);

}

if(s1num==2)

{min--;

if(min==-1)min=59;

write_sfm(7,min);

LCD_ZhiLing(0x80+0x40+8);

}

if(s1num==3)

{hour--;

if(hour==-1)hour=23;

write_sfm(4,hour);

LCD_ZhiLing(0x80+0x40+5);

}

if(s1num==4)

{

num1--;

if(num1==-1)

{

num1=6;

}

LCD_ZhiLing(0x80+12);

for(num=0;num<3;num++)//写入初始化数据

{

LCD_ShuJu(table2[num1][num]);

}LCD_ZhiLing(0x80+14);

}

if(s1num==5)

{day--;

if(day==0)day=31;

write_yr(9,day);

LCD_ZhiLing(0x80+10);

}

if(s1num==6)

{mon--;

if(mon==0)mon=12;

write_yr(6,mon);

LCD_ZhiLing(0x80+7);

}

if(s1num==7)

{year--;

if(year==1989)year=2100;

write_year(1,year);

LCD_ZhiLing(0x80+4);

}

}

}

}

}

 

/********************************中断处理**************************************/

voidtime0()interrupt1

{

TH0=(65536-50000)/256;

TL0=(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;num<3;num++)//写入初始化数据

{

LCD_ShuJu(table2[num1][num]);

}

}

write_sfm(4,hour);

}

write_sfm(7,min);

}

write_sfm(10,sec);

}

}

/******************************主函数**************************/

voidmain()

{

init();

while

(1)

{

keyscan();

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2