单位淘汰下的双色LED单元板,大部分都能正常使用,拿来研究了一下,结合网上的一些程序,制作了一个电子钟,初次发贴,见笑。。。
成品图

亚克力板
 
粘合
 
打孔,安装
合体
  
几点说明:
1、单片机必须用STC12C5A60S2,不能用89C51,要用推挽输出才能正常显示。
2、温度没用18B20,用的是10K感温头。
3、单元板比较费电,5W左右,单独供电,所以用了两5V电源(用一个电源时DS1302不能正常工作)。
单片机源程序如下:
- #include"STC12C5A60S2.h" /*头文件的包含*/
- #include"zimo.h"
- #include <intrins.h>
- #include <ADC.H>
- #include"led_595.h"
- #include"DS1302.h"
- sbit K1=P3^0;
- sbit K2=P3^1;
- sbit K3=P3^2;
- sbit K4=P3^3;
- unsigned char SetState,SetPlace=0;
- void Int0Configuration();
- unsigned char code temp_table[]={67, 70, 72, 74, 76, 78, 81, 83, 85, 87,
- 89, 90, 91, 93, 95, 97, 100,103,106,110,
- 113,116,119,122,125,128,131,133,136,139,
- 141,143,146,148,150,152,154,157,159,161,
- 163,165,167,169,171,173,175,176,178,180,
- 182,184,186,187,189,191,193,194,196,198,
- 199,200,201,202};
- unsigned int temp_change(unsigned char temp1)
- {
- unsigned int i;
- for(i=0;i<=63;i++)
- {
- if(temp_table[i]>temp1) break;
- }
- if(temp_table[i]==0) return 0;
- else if(temp_table[i]==63) return 640;
- else
- {
- return (unsigned int)((temp1-temp_table[i-1])*10/(temp_table[i]-temp_table[i-1])+(i-1)*10+5);
- }
- }
- void SendTime(void)
- {
- unsigned int TempData;
- GetTime();
- TempData=GetADCResult(2);
- TempData=temp_change(TempData);
- line1_num[2]=TableDs1302[6]/10;
- line1_num[3]=TableDs1302[6]%10;
- line1_num[5]=TempData/100;
- line1_num[6]=TempData%100/10;
- line2_num[0]=TableDs1302[4]/10;
- line2_num[1]=TableDs1302[4]%10;
- line2_num[3]=TableDs1302[3]/10;
- line2_num[4]=TableDs1302[3]%10;
- line2_num[7]=TableDs1302[5]+10;
- line3_num[0]=TableDs1302[2]/10;
- line3_num[1]=TableDs1302[2]%10;
- line3_num[3]=TableDs1302[1]/10;
- line3_num[4]=TableDs1302[1]%10;
- line3_num[6]=TableDs1302[0]/10;
- line3_num[7]=TableDs1302[0]%10;
- }
- void main()
- {
- unsigned int i;
- LED_Init();
- DelayMS(100);
- InitADC();
- DelayMS(1000);
- Int0Configuration();
- if(K2==0)
- {
- DelayMS(1000);
- InitDS1302();
-
-
-
- }
- while(1)
- {
- if(SetState==0)
- {
- SendTime();
- for(i=0;i<10;i++) LED_Display();
- }
- else
- {
- SendTime();
- for(i=0;i<20;i++) LED_Display();
- for(i=0;i<2;i++)
- {
- if(SetPlace==0) {line3_num[6]=11;line3_num[7]=11;}
- if(SetPlace==1) {line3_num[3]=11;line3_num[4]=11;}
- if(SetPlace==2) {line3_num[0]=11;line3_num[1]=11;}
- if(SetPlace==3) {line2_num[3]=10;line2_num[4]=10;}
- if(SetPlace==4) {line2_num[0]=10;line2_num[1]=10;}
- if(SetPlace==5) {line2_num[7]=10;}
- if(SetPlace==6) {line1_num[2]=10;line1_num[3]=10;}
- LED_Display();
- }
-
- if(K1==0) //检测按键K1是否按下
- {
- LED_Display(); //消除抖动
- if(K1==0)
- {
- SetPlace++;
- if(SetPlace>=7)
- SetPlace=0;
- }
- while((i<50)&&(K1==0)) //检测按键是否松开
- {
- LED_Display();
- i++;
- }
- i=0;
- }
- if(K2==0) //检测按键K2是否按下
- {
- LED_Display(); //消除抖动
- if(K2==0)
- {
- TableDs1302[SetPlace]++;
- if((TableDs1302[SetPlace]>=60)&&(SetPlace<2)) //分秒只能到59
- {
- TableDs1302[SetPlace]=0;
- }
- if((TableDs1302[SetPlace]>=24)&&(SetPlace==2)) //小时只能到23
- {
- TableDs1302[SetPlace]=0;
- }
- if((TableDs1302[SetPlace]>=32)&&(SetPlace==3)) //日只能到31
- {
- TableDs1302[SetPlace]=1;
- }
- if((TableDs1302[SetPlace]>=13)&&(SetPlace==4)) //月只能到12
- {
- TableDs1302[SetPlace]=1;
- }
- if((TableDs1302[SetPlace]>=8)&&(SetPlace==5)) //周只能到7
- {
- TableDs1302[SetPlace]=1;
- }
- if((TableDs1302[SetPlace]>=31)&&(SetPlace==6)) //年暂时到2030
- {
- TableDs1302[SetPlace]=0;
- }
- InitDS1302();
- }
-
- while((i<50)&&(K2==0)) //检测按键是否松开
- {
- LED_Display();
- i++;
- }
- i=0;
-
- }
- }
- }
- }
- void Int0Configuration()
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
LED_595_1302.rar
(43.65 KB, 下载次数: 101)
|