Altium Designer画的模拟冰球原理图和PCB图如下:(51hei附件中可下载工程文件)
DIY模拟冰球,压缩包里有全套原理图,PCB,源代码,烧录文件
单片机程序源码如下:
// C语言程序如下
/**************************************************************
* 文件 : -----.C
* 功能 : 对键盘进行读出,控制内部数值的加减,在数码管显示0到10
***************************************************************/
#include <reg51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit KK1 = P3^1;//按键输入;
sbit KK2 = P3^3;//按键输入;
sbit KK3 = P3^4; //接近开关输入;
uchar code table[11] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0xff};
/**************************************************************
* 名称 : Delay_1ms()
* 功能 : 延时子程序,延时时间为 1ms * x
* 输入 : x (延时一毫秒的个数)
* 输出 : 无
***************************************************************/
void Delay_1ms(uint x)
{
uchar i, j;
for(i = 0; i < x; i++) for(j = 0; j <= 148; j++);
}
/**************************************************************
* 名称 : Display(uchar k)
* 功能 : 将参数分成十位、个位分别显示
* 输入 : k
* 输出 : 无
***************************************************************/
void Display(uchar k)
{
P2 = 0; //先消隐
if (k / 10 == 0) P0 = table[10]; //显示空白
else P0 = table[k / 10]; //显示十位
P2 = 0x02; Delay_1ms(5); //显示5ms
P2 = 0;
P0 = table[k % 10]; //显示个位
P2 = 0x01; Delay_1ms(5);
}
/**************************************************************
* 名称 : Main()
* 功能 : 主函数
***************************************************************/
void Main(void)
{
uchar Value = 0; //数值
while(1) {
//sbit KK1 = P3^2; //按键输入;
//sbit KK2 = P3^3; //按键输入;
//sbit KK3 = P3^4; //接近开关输入;
P3 = 0xff;
if(!KK1) {//KK1按下
Display(Value);//延时消抖
// Delay_1ms(20);
if(!KK1) {//KK1依然按下
while(!KK1);//等KK1释放
Value++;
if (Value > 10) Value = 10;//显示最大值0-10
}
}
if(!KK2) { //KK2按下
Display(Value); //延时消抖
// Delay_1ms(20);
if(!KK2) { //KK2依然按下
while(!KK2); //等KK2释放
if (Value == 0) Value = 1;
Value--;
}
}
全部资料51hei下载地址:
BQ.rar
(325.06 KB, 下载次数: 14)
|