纯干货,持续更新
单片机源程序如下:
- #include <STC15F2K60S2.H>
- #include "ds18b20.h"
- #include "ds1302.h"
- #define uchar unsigned char
- #define uint unsigned int
-
- uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff,0xc6};
- uchar yi,er,san,si,wu,liu,qi,ba;
- extern uchar shijian[];
- uchar wendu;
- uchar change;
- char jia1=0,jia2=0,jia3=0;
- uchar mode;
- void allinit(void);
- void keyscan(void);
- void delay(uint tt);
- void display1(uchar yi,uchar er);
- void display2(uchar san,uchar si);
- void display3(uchar wu,uchar liu);
- void display4(uchar qi,uchar ba);
- void main()
- {
- allinit();
- DS_init();
- while(1)
- {
- if(change==0)
- {
- DS_get();
- yi=shijian[2]/10;er=shijian[2]%10;san=10;
- si=shijian[1]/10;wu=shijian[1]%10;liu=10;
- qi=shijian[0]/10;ba=shijian[0]%10;
- }
- else if(change==1)
- {
- DS_get();
- yi=shijian[2]/10;er=shijian[2]%10;san=10;
- si=shijian[1]/10;wu=shijian[1]%10;liu=10;
- qi=shijian[0]/10;ba=shijian[0]%10;
- if(shijian[0]%10%2==0)yi=11,er=11;
- else if(shijian[0]%2%10!=0)yi=shijian[2]/10,er=shijian[2]%10;
- }
- else if(change==2)
- {
- DS_get();
- yi=shijian[2]/10;er=shijian[2]%10;san=10;
- si=shijian[1]/10;wu=shijian[1]%10;liu=10;
- qi=shijian[0]/10;ba=shijian[0]%10;
- if(shijian[0]%10%2==0)si=11,wu=11;
- else if(shijian[0]%2%10!=0)si=shijian[1]/10,wu=shijian[1]%10;
- }
- else if(change==3)
- {
- DS_get();
- yi=shijian[2]/10;er=shijian[2]%10;san=10;
- si=shijian[1]/10;wu=shijian[1]%10;liu=10;
- qi=shijian[0]/10;ba=shijian[0]%10;
- if(shijian[0]%10%2==0)qi=11,ba=11;
- else if(shijian[0]%2%10!=0)qi=shijian[0]/10,ba=shijian[0]%10;
- }
- if(change==4)
- {
- wendu=Tempget();
- yi=11,er=11,san=11,si=11,wu=11;
- liu=wendu/10;qi=wendu%10;ba=12;
- if(P33==1)change=0;
- }
- keyscan();
- display1(yi,er);
- display2(san,si);
- display3(wu,liu);
- display4(qi,ba);
- }
- }
- void allinit(void)
- {
- P2=0xa0;P0=0x00;
-
- P2=0x80;P0=0xff;
-
- P2=0xc0;P0=0xff;
- P2=0xff;P0=0xff;
- }
- void delay(uint tt)
- {
- while(tt--);
- }
- void display1(uchar yi,uchar er)
- {
- P2=0xc0;P0=0x01;P2=0xff;P0=tab[yi];delay(1000);
-
- P2=0xc0;P0=0x02;P2=0xff;P0=tab[er];delay(1000);
- }
- void display2(uchar san,uchar si)
- {
- P2=0xc0;P0=0x04;P2=0xff;P0=tab[san];delay(1000);
-
- P2=0xc0;P0=0x08;P2=0xff;P0=tab[si];delay(1000);
- }
- void display3(uchar wu,uchar liu)
- {
- P2=0xc0;P0=0x10;P2=0xff;P0=tab[wu];delay(1000);
-
- P2=0xc0;P0=0x20;P2=0xff;P0=tab[liu];delay(1000);
- }
- void display4(uchar qi,uchar ba)
- {
- P2=0xc0;P0=0x40;P2=0xff;P0=tab[qi];delay(1000);
-
- P2=0xc0;P0=0x80;P2=0xff;P0=tab[ba];delay(1000);
-
- P2=0xc0;P0=0xff;P2=0xff;P0=0xff;
- }
- void keyscan(void)
- {
- if(P30==0)
- {
- delay(10);
- if(P30==0)
- {
- mode++;
- change++;
- if(change==4)change=0;
- if(change==0)mode=0;
- }
- while(!P30);
- }
- else if(P31==0)
- {
- delay(10);
- if(P31==0)
- {
-
- }
- while(!P31);
- }
- else if(P32==0)
- {
- delay(10);
- if(P32==0)
- {
- if(change==1)
- {
- shijian[2]++;DS_init();
- }
- else if(change==2)
- {
- shijian[1]++;DS_init();
- }
- else if(change==3)
- {
- shijian[0]++;DS_init();
- }
- }
- while(!P32);
- }
- else if(P33==0)
- {
- delay(10);
- if(P33==0)
- {
- if(mode==0)change=4;
- if(mode!=0)
- {
- if(change==1)shijian[2]--,DS_init();
- else if(change==2)shijian[2]--,DS_init();
- else if(change==3)shijian[2]--,DS_init();
- }
-
- }
- if((change==1)||(change==2)||(change==3))while(!P33);
-
- }
- }
复制代码
所有资料51hei提供下载,本人初学,如有错误,请大家多多指教:
第八届初赛_电子钟.zip
(49.84 KB, 下载次数: 50)
|