Altium Designer畫的模擬冰球原理圖和PCB圖如下:(51hei附件中可下載工程文件)
51hei.png (40.21 KB, 下載次數: 56)
下載附件
2020-10-28 15:46 上傳
51hei.png (26.49 KB, 下載次數: 64)
下載附件
2020-10-28 15:46 上傳
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.png (9.97 KB, 下載次數: 49)
下載附件
2020-10-28 15:49 上傳
全部資料51hei下載地址:
BQ.rar
(325.06 KB, 下載次數: 14)
2020-10-28 10:41 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|