以下時部分程序,謝謝。
制作出來的實物圖如下:
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機源程序如下:
- #include "reg52.h" //單片機頭文件
- #define uchar unsigned char //定義uchar 代替 unsigned char
- #define uint unsigned int
- sbit shi=P0;
- sbit fen=P2; //位定義
- sbit fenn=P1;
- sbit k1=P3^4;
- sbit k2=P3^5;
- sbit k3=P3^6;
- sbit k4=P3^7;
- void display(uchar a0,uchar a1,uchar a2,uchar a3,uchar a4,uchar a5); //函數聲明
- //void delay(uchar mss);
- //修改了數組的值
- uchar code tab1[]={0x20,0x30,0x38,0x3c,0x3e,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
- uchar code tab2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f};
- //uchar code tab3[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
- //uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f};
- uchar code tab3[]={0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00};//數組顯示
- uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20};
- //uchar code tab1[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
- //uchar code tab2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f};
- //uchar code tab3[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f}; 去除的
- //uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f}; 去除的
- //uchar code tab3[]={0x01,0x02,0x04,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00};//數組顯示
- //uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01};
- uchar ms=0,mg=0,fs=0,fg=0,ss=0,sg=0,m=0,f=0,s=0,ff=0,hf=0,fff=0;//定義變量
- char led[4]={0}; //顯示數組,修改
- void delay(int i) //延時函數
- {
- while(i--);
- }
- void led4(void) //顯示函數
- {
- char i;
- for(i=0;i<4;i++) //4位
- {
- P0=~led[i]; //送段碼 P2,P0對換了
- P2=~(0x01<<i); //送位碼
- delay(100); //延時
- P0=0xff; //關閉顯示
- P2=0xff; //關閉顯示
- }
- }
- char k,kk; //循環次數
- long n; //移位
- int h; //另外一個定時變量
- main()
- {
- TMOD=0x01;
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- EA=1;
- ET0=1;
- TR0=1;
- while(1)
- {
- led4(); //調用顯示函數
- if(k1==0) //按鍵k1為低電頻
- {
- delay(40); //延時去抖
- if(k1==0) //判斷k1是否按下
- {
- while(k1!=1); //等待按鍵釋放
- ff++; //ff,5分鐘自加
- fff++; //fff也自加 //秒置0
- if(ff==12) //ff夠12,自動置0,小時自加1
- {
- ff=0;
- m=0;
- h++;
- hf++;
- if(h==11)
- {h=0;}
- }
- }
- }
- if(k2==0) //按鍵k2控制加1小時
- {
- delay(40);
- if(k2==0)
- {
- while(k2!=1);
- h++;
- hf++;
- m=0;
- if(h==11)
- {
- h=0;
- }
- }
- }
- if(fff==1) //把fff清0返回5分鐘后的效果
- {
- fff=0;
- led[0]=tab1[k];
- led[3]=tab2[k];
- k++;
- if(k>11) k=0;
- }
復制代碼
/////////////////////////////
全部資料51hei下載地址:
5分鐘時鐘項目.rar
(58.44 KB, 下載次數: 9)
2020-7-12 10:55 上傳
點擊文件名下載附件
|