制作出来的实物图如下:
用雕刻机雕出来的板子
单片机源程序如下:
- #include "stc15w408as.h"
- #include "delay.h"
- #include "74ls595.h"
- sbit key= P3^2; // 定义按键入口 时间的时选择位
- signed char key_mode = 0;
- unsigned char flag = 0; //定义一个按钮标志位1
- sbit key1= P3^3; // 定义按键入口 时间的分选择
- signed char key_mode1 = 0;
- unsigned char flag1 = 0; //定义一个按钮标志位2
- sbit LED=P1^1; //定义秒钟状态led
- unsigned char idata T1[3]={0x03,0x9F,0x25};//时十
- unsigned char idata T2[10]={0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09};//时个
- 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};//分个
- unsigned char hour1,hour2,hour3,hour4;
- unsigned long count,count1;
- unsigned char temp1=0,temp2=0;
- /* 定时器0的配置**************************************/
- void Timer0Init() //定时50ms出发一次中断
- {
- 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;} //分个位
- if(hour4>9){hour4=0;hour3=hour3+1;} //分十位
- if(hour3>5){hour3=0;hour2=hour2+1;} //时个位
-
- if(hour1<2)
- {
- if(hour2>9){hour2=0;hour1=hour1+1;}//时十位
- }
- 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入口,时调节
- {
-
-
- if(!key)
- {
- DelayMs(60); //延时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入口,分调节
- {
-
-
- if(!key1)
- {
- DelayMs(60); //延时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) //当时间的十分位为0不显示
- {
- WR_595(T4[hour4]);
- WR_595(T3[hour3]);
- WR_595(T2[hour2]);
- WR_595(0xff);
- OUT_595();
- }
- else //当时间的十分位位1显示
- {
- WR_595(T4[hour4]);
- WR_595(T3[hour3]);
- WR_595(T2[hour2]);
- WR_595(T1[hour1]);
- OUT_595();
-
-
- }
-
-
- }
-
-
- }
复制代码
所有资料51hei提供下载:
Sheet5.pdf
(52.44 KB, 下载次数: 15)
|