|
小小的一个双面手工板实验,可以把这个手工板当作自己学习路上的第一块最小系统板,不仅促进手工及写代码能力,文件包含原理图和简单实现的C代码。
单片机源程序如下:
- #include <STC15F2K60S2.H>
- #include <LED595.h>//
- #include <Delay.h>
- #include <Digital595.h>
- #include <Timer0.h>
- #include <Key.h>
- #include <INTRINS.h>
- #include <Nixie.h>
- sbit sw1= P3^1;
- sbit sw0= P3^0;
- sbit sw2= P1^3;
- sbit LED= P1^2;
- sbit s0 = P3^7;
- sbit s1 = P1^4;
- sbit s2 = P1^1;
- sbit s3 = P1^0;
- unsigned char KeyNum,Time,sec1,sec2,min1,min2,i,LEDMode;
- unsigned char i=0,j=30000;
- void Delay1(unsigned int t)
- {
- while(t--);
- }
- void main()
- {
- unsigned char key1 = 0, key2 = 0, key4 = 0,key5 = 0;
-
- Timer0_Init();
- while(1)
- {
- key1 = Key();
- if(key1 == 3)
- {
- key2 = ~key2;
- }
- if(key1 == 2)
- {
- key4 = ~key4;
- }
- if(key1 == 1)
- {
- key5 = ~key5;
- }
- if(key4)
- {
-
- LED595(0X00);//I am so lazy to write circulation,so I prefer to chick someone.
- s0=0;s1=0;s2=0;
- DIG595(0x00);
- LED = 0;
- Delay(100);
- LED595(0XFF);
- s0=1;s1=1;s2=1;
- DIG595(0xFF);
- LED = 1;
- Delay(100);
- LED595(0X00);
- s0=0;s1=0;s2=0;
- DIG595(0x00);
- LED = 0;
- Delay(100);
- LED595(0XFF);
- s0=1;s1=1;s2=1;
- DIG595(0xFF);
- LED = 1;
- Delay(100);
- LED595(0X00);
- s0=0;s1=0;s2=0;
- DIG595(0x00);
- LED = 0;
- Delay(100);
- LED595(0XFF);
- s0=1;s1=1;s2=1;
- DIG595(0xFF);
- LED = 1;
- Delay(100);
- LED595(0X00);
- s0=0;s1=0;s2=0;
- DIG595(0x00);
- LED = 0;
- Delay(100);
- LED595(0XFF);
- s0=1;s1=1;s2=1;
- DIG595(0xFF);
- LED = 1;
- Delay(100);
- LED595(0X00);
- s0=0;s1=0;s2=0;
- DIG595(0x00);
- LED = 0;
- Delay(100);
- LED595(0XFF);
- s0=1;s1=1;s2=1;
- DIG595(0xFF);
- LED = 1;
- Delay(100);
- LED595(0X00);
- s0=0;s1=0;s2=0;
- DIG595(0x00);
- LED = 0;
- Delay(100);
- LED595(0XFF);
- s0=1;s1=1;s2=1;
- DIG595(0xFF);
- LED = 1;
- Delay(100);
- }
- if(key5)
- {LED=0;
- DIG595(0xb0);//running river lights,my _crol_ can not running.total 10 second.
- LED595(0x80);
- Delay(1000);
- LED595(0x40);
- Delay(1000);
- LED595(0x20);
- Delay(1000);
- LED595(0x10);
- Delay(1000);
- LED595(0x08);
- Delay(1000);
- LED595(0x04);
- Delay(1000);
- LED595(0x02);
- Delay(1000);
- LED595(0x01);
- Delay(1000);
- LED595(0x00);
- Delay(1000);
- LED595(0xff);
- Delay(1000);
- }
-
- else
- {
- s0=1;s1=1;s2=1;
- if(key2)
- {
- Nixie(1,sec1);//clock
- Nixie(2,sec2);
- Nixie(3,min1);
- Nixie(4,min2);
- LED595(0xaa);
- }
- else
- {
- sec1=0;//breath lights
- sec2=0;
- min1=0;
- min2=0;
- DIG595(0xf9);s3 = 0;
- for(Time=0;Time<100;Time++)
- {
- for(i=0;i<50;i++)
- {
- LED=0;LED595(0x00);
- Delay1(Time);
- LED=1;LED595(0xff);
- Delay1(100-Time);
- }
-
-
- }
-
- for(Time=100;Time>0;Time--)
- {
- for(i=0;i<50;i++)
- {
- LED=0;LED595(0x00);
- Delay1(Time);
- LED=1;LED595(0xff);
- Delay1(100-Time);
- }
-
-
- }
- }
- }
- }
-
-
- }
- void Timer0_Routine() interrupt 1
- {
- static unsigned int T0Count; //This routine from BV1Mb411e7re
- TH0=64535/256;//new words;
- TL0=64535%256;
- T0Count++;
- if(T0Count>=1000)
- {
- T0Count=0;
- sec1++;
- if(sec1>9)
- {
- sec1=0;
- sec2++;
- if(sec2>=6)
- {
- sec2=0;
- min1++;
- if(min1>9)
- {
- min1=0;
- min2++;
- if(min2>9)
- {
- min2=0;
- }
- }
- }
- }
- }
- }
复制代码
Keil代码下载:
手工板小实验.zip
(167.72 KB, 下载次数: 29)
|
评分
-
查看全部评分
|