赞
踩
主函数
- #include <REGX52.H>
- #include "Delay.h"
- #include "Key.h"
- #include "Nixie.h"
- #include "Buzzer.h"
-
- sbit Buzzer=P2^5;
- unsigned char KeyNum;
- unsigned int i;
-
-
- void main()
- {
- Nixie(1,0);
- while(1)
- {
- KeyNum=Key();
-
- if(KeyNum)
- {
- Buzzer_Time(1000);
- Nixie(1,KeyNum);
- }
- }
- }
Buzzer
- #include <REGX52.H>
- #include <intrins.h>
- #include "delay.h"
-
- sbit Buzzer=P2^5;//蜂鸣器端口
-
-
- /**
- * @brief 蜂鸣器私有延时函数,延时500us
- * @param 无
- * @retval 无
- */
- void Buzzer_Delay500us() //@12.000MHz
- {
- unsigned char i;
-
- _nop_();
- i = 247;
- while (--i);
- }
- /**
- * @brief 蜂鸣器发声
- * @param ms 发声的时长
- * @retval 无
- */
- void Buzzer_Time(unsigned int ms)
- {
- unsigned int i;
- for(i=0;i<ms*2;i++)
- {
- Buzzer=!Buzzer;
- Buzzer_Delay500us();
- }
- }
Delay
- void Delay(unsigned int xms) //@12.000MHz
- {
- unsigned char i, j;
- while(xms--)
- {
- i = 2;
- j = 239;
- do
- {
- while (--j);
- } while (--i);
- }
- }
Key
- #include <REGX52.H>
- #include "Delay.h"
-
- /**
- * @brief 获取独立按键键码
- * @param 无
- * @retval 按下按键的键码,范围0——4 无按键按下,返回值为0
- */
-
- unsigned char Key()
- {
- unsigned char KeyNumber=0;
-
- if(P3_1==0){Delay(100);while(P3_1==0);Delay(100);KeyNumber=1;}
- if(P3_0==0){Delay(100);while(P3_0==0);Delay(100);KeyNumber=2;}
- if(P3_2==0){Delay(100);while(P3_2==0);Delay(100);KeyNumber=3;}
- if(P3_3==0){Delay(100);while(P3_3==0);Delay(100);KeyNumber=4;}
-
- return KeyNumber;
- }
MatrixLed
- #include <REGX52.H>
- #include "DELAY.h"
- sbit RCK=P3^5;//位申明,重新命名 RCLK
- sbit SCK=P3^6;//时钟 SRCLK
- sbit SER=P3^4;//SER
-
- #define MATRIX_LED_PORT P0
- /**
- * @brief 74HC595写入一个字节
- * @param 要写入的字节
- * @retval 无
- */
- void _74HC595_WriteByte(unsigned char Byte)//移位计时器
- {
- unsigned char i;
- for(i=0;i<8;i++)
- {
- SER=Byte&(0x80>>i);
- SCK=1;
- SCK=0;
- }
- RCK=1;
- RCK=0;
- }
- /**
- * @brief 点阵屏初始化
- * @param 无
- * @retval 无
- */
- void MatrixLED_Init()
- {
- SCK=0;
- RCK=0;
- }
-
- /**
- * @brief LED点阵屏显示一列数据
- * @param Column要选择的列,范围0—7,0在最左边
- Data要选择的显示的数据,高位在上,1为亮,0为灭
- * @retval 无
- */
- void MatrixLED_ShowColumn(unsigned char Column,Data)//点阵屏
- {
- _74HC595_WriteByte(Data);
- P0=~(0x80>>Column);//移位操作
- Delay(1);
- MATRIX_LED_PORT=0xFF;//位清零
- }
Nixie
- #include <REGX52.H>
- #include "Delay.h"
-
-
- unsigned char NixieTable[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7f,0x6F};
-
- void Nixie(unsigned char Location,Number)
- {
- switch(Location)
- {
- case 1: P2_4=1;P2_3=1;P2_2=1;break; //??????
- case 2: P2_4=1;P2_3=1;P2_2=0;break;
- case 3: P2_4=1;P2_3=0;P2_2=1;break;
- case 4: P2_4=1;P2_3=0;P2_2=0;break;
- case 5: P2_4=0;P2_3=1;P2_2=1;break;
- case 6: P2_4=0;P2_3=1;P2_2=0;break;
- case 7: P2_4=0;P2_3=0;P2_2=1;break;
- case 8: P2_4=0;P2_3=0;P2_2=0;break;
- }
- P0=NixieTable[Number];
- //Delay(1);
- //P0=0x00;
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。