1、 display(a0, a1, a2, a3, a4, a5, a6, a7); / 显示 chuli(); aloutput(); if(stoptime)stoptimes(); if(starttime)starttimes(); if(!settime)timerup(); if(saveiic)iicsave(); if(readiic)iicread(); if(function=1|function_al!=0)reset=0; delay1ms_c.cuchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,
2、0x6f,0x00,0x40,0xb8,0xf4;/ 09, OFF, - , h. , L./*显示子程序*void display(uchar a7,uchar a6,uchar a5,uchar a4,uchar a3,uchar a2,uchar a1,uchar a0) P0=tablea0; P1=0xfe; delay(2); P0=tablea1; P1=0xfd; P0=tablea2; P1=0xfb; P0=tablea3; P1=0xf7; P0=tablea4; P1=0xef; P0=tablea5; P1=0xdf; P0=tablea6; P1=0xbf; P0
3、=tablea7; P1=0x7f;/*将数送至缓冲单元,当shan的标志位为1时,再根据此时的此时的功能标示,对该位熄灭*void send() if(function_al=0) /time a0=sec%10; a1=sec/10; a2=11; a3=min%10; a4=min/10; a5=11; a6=hour%10; a7=hour/10; if(function_al!=0) /al a0=alfunction_al-1.s%10; a1=alfunction_al-1.s/10; a3=alfunction_al-1.m%10; a4=alfunction_al-1.m/1
4、0; a6=alfunction_al-1.alon+add; a7=function_al; if(shan=1&next=0&(function_al!=0|function!=0) a0=10,a1=10;a2=10;a3=10,a4=10;a5=10;a6=10,a7=10; next=1& next=2& a3=10,a4=10;next=3& a6=10,a7=10;void display(uchar a7,uchar a6,uchar a5,uchar a4,uchar a3,uchar a2,uchar a1,uchar a0);void send();void delay(
5、uint count);#define AT24C02 0xa0 /AT24C02 地址bit ISendStr(unsigned char sla,unsigned char suba,unsigned char *s,unsigned char no);bit IRcvStr(unsigned char sla,unsigned char suba,unsigned char *s,unsigned char no);uchar reset,t0,t1,sec,min,hour,function,a0,a1,a2,a3,a4,a5,a6,a7;uchar function_al,next,
6、stop;uchar add=11,pDat24;bit shan,stoptime,starttime,settime,saveiic,readiic;structuchar alon; uchar m; uchar s; al8; /8 AL 结构数组void resets() init_ds1302(); al0.m=8; al0.s=3; al0.alon=1; al1.m=12; al1.s=0; al1.alon=2; al2.m=13; al2.s=33; al2.alon=1; /al3.m=17; al3.s=30; al3.alon=2; /al4.m=18; al4.s=
7、3; al4.alon=1; /al5.m=21; al5.s=0; al5.alon=2; /al6.m=0; al6.s=0; al6.alon=1; /al7.m=8; al7.s=0; al7.alon=2; saveiic=1;void iicsave() /保存数据 uchar i;EA=0;2; pDati+0=ali.s; pDati+2=ali.m; pDati+4=ali.alon; ISendStr(AT24C02, 0 , &pDat0, 6); delay(20); for(i=2;4; pDati+4=ali.s; pDati+6=ali.m; pDati+8=al
8、i.alon; saveiic=0;EA=1;void iicread() /读取数据 IRcvStr(AT24C02, 0 , & ali.s=pDati+0; ali.m=pDati+2; ali.alon=pDati+4; delay(20); ali.s=pDati+4; ali.m=pDati+6; ali.alon=pDati+8; readiic=0;void stoptimes() write_ds1302(0x8e,0x00);/WP写保护关 write_ds1302(0x80,0x80|(sec/10)*16+(sec%10);/stop 秒 write_ds1302(0x
9、8e,0x80);/写保护开 stoptime=0;starttime=0;void starttimes() write_ds1302(0x80,0x00|(sec/10)*16+(sec%10);void savetime() /save time write_ds1302(0x82,0x80|(min/10)*16+(min%10); write_ds1302(0x84,0x80|(hour/10)*16+(hour%10);/*uchar keychuli() uchar k; k=P3; /P1口内容送K k=k; /取反 k=(k&0x3f); /屏蔽高3位,如果扫描8键,屏蔽该句
10、。 return(k); /返回键值 /* 函数原型:key();* 功 能:键盘扫描函数,函数返回值即键值。*/uchar key() uchar keyzhi,keyzhii; /电子钟键盘按键键值临时存放 keyzhi=keychuli(); /调P1口处理函数 if(keyzhi!=0) /有键动作延时去抖动,否则函数返回 send(); display(a0, a1, a2, a3, a4, a5, a6, a7); /再次调P1口处理函数=0) /真正有键按下,取键值并暂存 keyzhii=keyzhi; while(keyzhi!=0) /判按键是否释放,没有释放延时去抖动等待释
11、放 send(); keyzhi=keyzhii; /按键释放后恢复按键键值 return(keyzhi); /返回按键键值/*键值处理程序*void chuli() switch(key() case 0: break; case 1: / function+; switch(function) case 1:if(function_al=0)settime=1;stoptime=1;TR1=1;shan=1; if(function_al!=0)settime=0;stoptime=0;starttime=1;TR1=0;shan=0;next=0;function=0;function_
12、al=0;break; case 2:savetime();settime=0;break; / break; case 2: /+ if(function_al=0&function!=0) switch(next) case 1: sec+; if(sec=60) sec=0; case 2: min+; if(min=60) min=0; case 3: hour+; if(hour=24) hour=0; if(function_al! alfunction_al-1.s+;if(alfunction_al-1.s=60)alfunction_al-1.s=0; alfunction_
13、al-1.m+;if(alfunction_al-1.m=24)alfunction_al-1.m=0; alfunction_al-1.alon+;if(alfunction_al-1.alon=3)alfunction_al-1.alon=0; break; case 4: /- sec-; if(sec=255) sec=59; min-; if(min=255) min=59; hour-; if(hour=255) hour=23; alfunction_al-1.s-;if(alfunction_al-1.s=255)alfunction_al-1.s=59; alfunction
14、_al-1.m-;if(alfunction_al-1.m=255)alfunction_al-1.m=23; alfunction_al-1.alon-;if(alfunction_al-1.alon=255)alfunction_al-1.alon=2; case 8: /al function_al+; switch(function_al) case 1: readiic=1; TR1=1; /case 4: /case 5: /case 6: /case 7: /case 8: case 4: case 16: /next if(function|function_al!=0)nex
15、t+; switch(next) case 32: if(function=0&function_al=0&reset4)&0x07)*10;/秒 min=(read_ds1302(0x83)&0x0f)+(read_ds1302(0x83)/分 hour=(read_ds1302(0x85)&0x0f)+(read_ds1302(0x85)0x03)*10;/时sbit ACC0=ACC0;sbit ACC7=ACC7;sbit sclk=P36;sbit io=P34;sbit rst=P35;void delay1302(uint x) uint i,j; for(i=x;i0;i-)
16、for(j=114;jj-);void write_ds1302byte(uchar dat) /上升沿写1字节数据 ACC=dat; /数据放入累加器中/ rst=1;启动数据传送 for(i=8; io=ACC0; /累加器数据赋给io送出 sclk=0; sclk=1; /上升沿 ACC=ACC1;/累加器数据左移一位,先写最低位uchar read_ds1302byte()/下降沿读1字节数据/累加器数据左移一位,先读最低位 ACC7=io; /把io线上的数据赋给累加器 /下降沿 return ACC; /返回累加器数据void write_ds1302(uchar addr,uch
17、ar dat) /写地址,写数据 rst=0; sclk=0; delay1302(1); rst=1; write_ds1302byte(addr); /写地址 write_ds1302byte(dat); /写数据 sclk=1;/ delay1302(1);/ io=1;uchar read_ds1302(uchar addr) /写地址,读数据 uchar da; da=read_ds1302byte(); return da;void init_ds1302()/WP写保护关 write_ds1302(0x80,0x00);/写秒,十进制初值 write_ds1302(0x82,0x00); write_ds1302(0x84,0x00); write_ds1302(0x86,0x10);/day write_ds1302(0x88,0x03);/month write_ds1302(0x8a,0x6);/week write_ds1302(0x8c,0x12);/year /write_ds1302(0x90,0x00);/涡流 _ 是指充电的了/*
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1