1、#include sbit DS1302_CLK=P30;sbit DS1302_IO=P31;sbit DS1302_RST=P32; unsigned char fy=0;unsigned char tj=0;sbit tjxz = P35;sbit fanyel=P34;sbit fanyer=P33;sbit ACC0=ACC0;sbit ACC7=ACC7;sbit qian=P24; sbit bai=P25; sbit shi=P26; sbit ge=P27; bit flag; sfr smdis = 0x80; sfr p2m1 = 0x95; sfr p2m0 = 0x9
2、6; sfr p1m1 = 0x91; sfr p1m0 = 0x92;code unsigned charseg1=0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef;/?code unsigned char seg=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f; /?unsigned char clk_time8=0x59,0x58,0x8,0x9,0x12,0x03,0x09,0x20; /?,?,?,?,?,?,?/*DS1302:?(?)*/ /*void DS1302InputBy
3、te(unsigned char da) unsigned char i; ACC=da; for(i=8;i0;i-) DS1302_IO=ACC0; DS1302_CLK=0; DS1302_CLK=1; ACC=ACC1; /*DS1302:?(?)*/*unsigned char DS1302OutputByte(void) unsigned char i; for(i=0;i1; DS1302_CLK = 1; DS1302_CLK = 0; ACC7 = DS1302_IO; return(ACC);*/void DS1302InputByte(unsigned char d) /
4、?(?) unsigned char i,j; EA=0; for(i=8; i0; i-) DS1302_CLK = 0; for(j=2;j0;j-); if(d&0x01) DS1302_IO = 1; else DS1302_IO = 0; for(j=2;j0;j-); DS1302_CLK = 1; d=d1; EA=1;unsigned char DS1302OutputByte(void) /?(?) unsigned char i,j,d=0; EA=0; for(i=0; i0;j-); DS1302_CLK = 0; if( DS1302_IO) d=d|(0x010;i
5、-) for(j=0;j500;j+); void delay(unsigned int a )/? unsigned char i; while(a- !=0) for(i=0;i125;i+); void led_disp1(unsigned char *poi)/?,?-?1 ge=0; P0=seg*poi % 16; delay(2); ge=1; shi=0; P0=seg*poi /16; delay(2); shi=1; poi+; bai=0; P0=0x0; delay(2); bai=1; qian=0; P0=0x0; delay(2); qian=1;void led
6、_disp2(unsigned char *poi)/?,?-?2 ge=0; P0=seg*poi % 16; delay(2); ge=1; shi=0; P0=seg*poi /16; delay(2); shi=1; poi+; bai=0; P0=seg1*poi % 16; delay(2); bai=1; qian=0; P0=seg*poi / 16; delay(2); qian=1;void led_disp3(unsigned char *poi)/?,?-?2 ge=0; P0=seg*poi % 16; delay(2); ge=1; shi=0; P0=seg*po
7、i /16; delay(2); shi=1; poi+; bai=0; P0=seg*poi % 16; delay(2); bai=1; qian=0; P0=seg*poi / 16; delay(2); qian=1;void shixianfy()/?switch(fy) case 4 : led_disp1(&clk_time0);break;case 3 : led_disp2(&clk_time1);break;case 2 : led_disp2(&clk_time3);break ;case 1 : led_disp1(&clk_time5);break; case 0 :
8、 led_disp3(&clk_time6);break;void kongzhify()/?if(fanyel=0)delay(0);if(fanyel=0)fy+;if(fy=5)fy=0;else if(fanyer=0)delay(10);if(fanyer=0) fy-;if(fy=-1)fy=4; void main(void) unsigned char temp=0x80; unsigned char i; /Write1302(0x80,0x80);Write1302(0x80,0x00); /WP=0 ? for(i=0;i7;i+) Write1302(temp,clk_timei); temp+=2; /WP=1 ? while(1) while(fanyer=0 ); kongzhify(); while(fanyel=0 ); kongzhify(); temp=0x81; for(i=0;i7;i+) /clk_timei=0x0; clk_timei=Read1302(temp); temp+=2;shixianfy();