文档详情

51单片机实现万年历程序.doc

发布:2017-09-16约1.69万字共17页下载文档
文本预览下载声明
51单片机实现万年历 利用AT89S52单片机的P0口来和另外几个口来控制1602液晶的显示和P1口还有其它口来控制ds12887时钟芯片。设置四个按键,1个定义为时间设置功能键,一个定义为闹钟设置功能键,另外两个用来调节时间的增减。 原理图: pcb图: 源程序: #includereg52.h #define uint unsigned int #define uchar unsigned char sbit beep=P2^0;//蜂鸣器控制口 sbit timeadd=P2^1;//调节时间加 sbit timesub=P2^2;//调节时间减 sbit timeclk=P2^3;//闹钟设定键 sbit timefun=P2^4;//时间设定键 sbit lcdrs=P2^5;//液晶的命令和数据控制口 sbit ledrw=P2^6;//液晶的写数据口 sbit lcden=P2^7;//液晶显示模块的使能端 sbit timeds=P3^3;//时钟芯片地址闸 sbit timerw=P3^4;//时钟芯片读写 sbit timeas=P3^5;//时钟芯片地址闸 sbit timeen=P3^6;//时钟芯片片选 uchar code table[]=20??-??-?? week ; uchar code table1[]=???? :??:??;//要显示的字符串 char num,shi,fen,miao,nian=2000,yue,ri,week,numfun,anumfun,flag,flag1; uchar leap; void delay(uint x){ ?? uchar i,j; ?? for(i=x;i0;i--) ??????for(j=110;j0;j--); } void didi() { ?? beep=0; ?? delay(1000); ?? beep=1; ?? delay(1000); } void write_com(uchar com){ ?? lcdrs=0; ?? P0=com; ?? delay(5); ?? lcden=1; ?? delay(20); ?? lcden=0; } void write_date(uchar date){ ?? lcdrs=1; ?? P0=date; ?? delay(5); ?? lcden=1; ?? delay(20); ?? lcden=0; } void write_sfm(uchar add,uchar date){ ?? uchar shi,ge; ?? shi=date/10; ?? ge=date%10; ?? write_com(0x80+0x40+add); ?? write_date(0x30+shi); ?? write_date(0x30+ge); } void write_nyr(uchar add,uchar date){ ?? uchar shi,ge; ?? shi=date/10; ?? ge=date%10; ?? write_com(0x80+add); ?? write_date(0x30+shi); ?? write_date(0x30+ge); } void write_zhou(uchar add,uchar date) { ?? write_com(0x80+add); ?? write_date(0x30+date); } void write_ds(uchar add,uchar date){ ?? timeen=0; ?? timeas=1; ?? timeds=1; ?? timerw=1; ?? P1=add; ?? timeas=0; ?? timerw=0; ?? P1=date; ?? timerw=1; ?? timeas=1; ?? timeen=1;?????????? } uchar read_ds(uchar add){ ?? uchar ds_date; ?? timeas=1; ?? timeds=1; ?? timerw=1; ?? timeen=0; ?? P1=add; ?? timeas=0; ?? timeds=0; ?? P1=0xff; ?? ds_date=P1; ?? timeds=1; ?? timeas=1; ?? timeen=1; ?? return ds_date; } void keyscan()
显示全部
相似文档