|
制作出來的實(shí)物圖如下:
用雕刻機(jī)雕出來的板子
單片機(jī)源程序如下:
- #include "stc15w408as.h"
- #include "delay.h"
- #include "74ls595.h"
- sbit key= P3^2; // 定義按鍵入口 時(shí)間的時(shí)選擇位
- signed char key_mode = 0;
- unsigned char flag = 0; //定義一個(gè)按鈕標(biāo)志位1
- sbit key1= P3^3; // 定義按鍵入口 時(shí)間的分選擇
- signed char key_mode1 = 0;
- unsigned char flag1 = 0; //定義一個(gè)按鈕標(biāo)志位2
- sbit LED=P1^1; //定義秒鐘狀態(tài)led
- unsigned char idata T1[3]={0x03,0x9F,0x25};//時(shí)十
- unsigned char idata T2[10]={0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09};//時(shí)個(gè)
- unsigned char idata T3[6]={0x03,0x9F,0x25,0x0D,0x99,0x49};//分十
- unsigned char idata T4[10]={0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09};//分個(gè)
- unsigned char hour1,hour2,hour3,hour4;
- unsigned long count,count1;
- unsigned char temp1=0,temp2=0;
- /* 定時(shí)器0的配置**************************************/
- void Timer0Init() //定時(shí)50ms出發(fā)一次中斷
- {
- AUXR &= 0x7F;
- TMOD &= 0xF0;
- TL0 = 0x00;
- TH0 = 0x4C;
- //TF0 = 0;
- TR0 = 1;
- ET0=1;
- EA=1;
- }
- void TIMER0() interrupt 1
- {
- if(temp1==0&&temp2==0)
- {
- count1++;
- if(count1==20){count1=0;count=count+1;LED=~LED;}
- if(count==60){count=0;hour4=hour4+1;} //分個(gè)位
- if(hour4>9){hour4=0;hour3=hour3+1;} //分十位
- if(hour3>5){hour3=0;hour2=hour2+1;} //時(shí)個(gè)位
-
- if(hour1<2)
- {
- if(hour2>9){hour2=0;hour1=hour1+1;}//時(shí)十位
- }
- if(hour1==2)
- {
- if((hour2>3)){hour1=0;hour2=0;hour3=0;hour4=0;}
- }
- }
- else
- {
- if(temp1==1){hour2=hour2+1;temp1=0;}
- if(temp2==1){hour4=hour4+1;temp2=0;}
- }
- }
- void KeyInit0() interrupt 0 //外部中斷0入口,時(shí)調(diào)節(jié)
- {
-
-
- if(!key)
- {
- DelayMs(60); //延時(shí)20ms
- if(key==0&&flag==0)
- {
- DelayMs(10);
- flag=1;
- }
- while(!key);
- }
- if(key==1&&flag==1)
- {
- DelayMs(60);
- flag=0;
- temp1=temp1+1;
- }
-
-
-
- }
- void KeyInit1() interrupt 2 //外部中斷2入口,分調(diào)節(jié)
- {
-
-
- if(!key1)
- {
- DelayMs(60); //延時(shí)20ms
- if(key1==0&&flag1==0)
- {
- DelayMs(10);
- flag1=1;
- }
- while(!key1);
- }
- if(key1==1&&flag1==1)
- {
- DelayMs(60);
- flag1=0;
- temp2=temp2+1;
- }
-
-
-
- }
-
- void main()
- {
- Timer0Init() ;
-
- LED=1;
-
-
- //配置外部中斷1和0
-
- IT0=1;
- EX0=1;
- IT1=1;
- EX1=1;
- EA = 1;
-
- while(1)
- {
-
-
-
- if(hour1==0) //當(dāng)時(shí)間的十分位為0不顯示
- {
- WR_595(T4[hour4]);
- WR_595(T3[hour3]);
- WR_595(T2[hour2]);
- WR_595(0xff);
- OUT_595();
- }
- else //當(dāng)時(shí)間的十分位位1顯示
- {
- WR_595(T4[hour4]);
- WR_595(T3[hour3]);
- WR_595(T2[hour2]);
- WR_595(T1[hour1]);
- OUT_595();
-
-
- }
-
-
- }
-
-
- }
復(fù)制代碼
所有資料51hei提供下載:
Sheet5.pdf
(52.44 KB, 下載次數(shù): 15)
2019-3-20 20:42 上傳
點(diǎn)擊文件名下載附件
layout
時(shí)鐘器.rar
(642.99 KB, 下載次數(shù): 8)
2019-3-20 20:40 上傳
點(diǎn)擊文件名下載附件
雕刻機(jī)雕出來的板子
時(shí)鐘.rar
(701.55 KB, 下載次數(shù): 7)
2019-3-20 20:47 上傳
點(diǎn)擊文件名下載附件
程序
|
評(píng)分
-
查看全部評(píng)分
|