|
这是自己在学单片机的时候 写的一个篮球计分器程序 包括protues仿真图,带节次设置键 复位按钮等
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg52.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar secs = 0;
- uchar minutes = 1;
- uchar LED,num1,num2,num = 4;
- uchar flag1 = 1,flag2 = 0;
- uchar m_secs = 24;
- uchar key_value = 0;
- uchar table[13] = {1,2,3,4,5,6,7,8,9,0,1,2,3};
- uchar code LedNum[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar scan_kay(void);
- void delay(uchar z);
- void INT0_Initial(void)
- {
- EX0 = 1;
- IT0 = 1;
- EA = 1;
- P1 = 0xF0;
- }
- void INT0_Interrupt(void) interrupt 0
- {
- uchar temp;
- temp = scan_kay();
- if(temp!=0x7f)
- {
- key_value = temp;
- }
- P1 = 0xF0;
- }
- void Time0_Initial(void)
- {
- TMOD = 0x01;
- TH0 = (65536-50000)/256;
- TL0 = (65536-50000)%256;
- ET0 = 1;
- TR0 = 1;
- EA = 1;
- PT0 = 1;
- PX0 = 0;
- }
- volatile uchar cnt = 0;
- void Time0_Interrupt(void) interrupt 1
- {
- TH0 = (65536-50000)/256;
- TL0 = (65536-50000)%256;
- cnt ++;
- minutes=11;
- if(cnt==15)
- {
- cnt = 0;
- secs --;
- m_secs --;
- if(flag2==1)
- {
- LED = !LED;
- }
- if(flag2==0)
- {
- LED = 0;
- }
- }
- if(secs>60)
- {
- secs = 59;
- minutes --;
- }
- if(m_secs>24)
- {
- m_secs = 23;
- if(flag1==1)
- {
- flag2 = 1;
- }
- if(flag1==0)
- {
- flag2 = 0;
- }
- }
- if(minutes>60)
- {
- minutes = 11;
- m_secs = 24;
- num ++;
- }
- if(num==4)
- {
- num = 1;
- }
- }
- void HEXTOBCD(void)
- {
- table[0] = LedNum[num];
- table[1] = LedNum[m_secs/10];
- table[2] = LedNum[m_secs%10];
- table[3] = LedNum[minutes/10];
- table[4] = LedNum[minutes%10];
- table[5] = LedNum[secs/10];
- table[6] = LedNum[secs%10];
- table[7] = LedNum[num1/100];
- table[8] = LedNum[num1%100/10];
- table[9] = LedNum[num1%10];
- table[10] = LedNum[num2/100];
- table[11] = LedNum[num2%100/10];
- table[12] = LedNum[num2%10];
- }
- void Display(uchar *str)
- {
- uchar i,temp = 0;
- for(i=0;i<13;i++)
- {
- P0 = 0x00;
- _nop_();
- P2 = temp+i;
- P0 = str[i];
- delay(2);
- }
- }
- uchar i,j;
- void delay(uchar z)
- {
- for(i=1;i<z;i++)
- for(j=1;j<110;j++);
- }
- void main()
- {
- INT0_Initial();
- Time0_Initial();
- delay(10);
- LED = 0;
- while(1)
- {
- switch(key_value)
- {
- case 12:
- {
- num1 ++;key_value = 0;
- flag1 = 0;
- if(num1>255)
- {
- num1 = 0;
- }
- break;
- }
- case 13:
- {
- num1 --;key_value = 0;
- flag1 = 0;
- if(num1>255)
- {
- num1 = 255;
- }
- break;
- }
- case 14:
- {
- num2 ++;key_value = 0;
- flag1 = 0;
- if(num2>255)
- {
- num2 = 0;
- }
- break;
- }
- case 15:
- {
- num2 --;key_value = 0;
- flag1 = 0;
- if(num2>255)
- {
- num2 = 255;
- }
- break;
- }
- case 1:
- {
- TR0 = 1;
- key_value = 0;
- break;
- }
- case 2:
- {
- num1 = 0;num2 = 0;
- num = 4;
- secs = 0;minutes = 12;
- m_secs = 24;
- key_value = 0;
- TR0 = 1;
- break;
- }
- case 3:
- {
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
篮球计分器.zip
(19.98 KB, 下载次数: 70)
|
|