所有资料都在文件里,有需要的下载就行了
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #include<string.h>
- #define uchar unsigned char
- #define uint unsigned int
- #include "LCD1602_drv.h"
- #include "stdio.h"
- uchar ocassioncount = 1; //场次
- uint16 score1=0;//甲队分数
- uint16 score2=0;//乙队分数
- uint16 deadline24=24;//24秒倒计时
- uint16 deadline12=720;//12分钟秒倒计时
- uchar scorestr[3]; //
- //uchar scorestr2[3]; //
- uchar dead24str[2]; //
- uchar dead12str[5]; //
- uchar ocassionstr[3]; //
- /*延时函数*/
- void delay(unsigned char x)
- {
- unsigned char i,j;
- for(i = x;i > 0;i--)
- for(j = 100;j > 0;j--);
- }
- //数字转化为字符串 三位整数
- void numtostr(uint16 num)
- {
- uchar i=0,numsize=0;
- scorestr[0]=num/100+0x30; //bai位
- scorestr[2]=num%10+0x30; //个位
- if(num>100)
- {
- scorestr[1]=(num/10)%10+0x30; //bai位
- }
- else
- {
- scorestr[1]=num/10+0x30; //bai位
-
- }
- }
- //数字转化为字符串 三位整数
- // void numtostr2(uint16 num)
- //{
- // uchar i=0,numsize=0;
- // scorestr2[0]=num/100+0x30; //bai位
- // scorestr2[2]=num%10+0x30; //个位
- // if(num>100)
- // {
- // scorestr2[1]=(num/10)%10+0x30; //bai位
- // }
- // else
- // {
- // scorestr2[1]=num/10+0x30; //bai位
- //
- // }
- // }
- //24s数字转为字符串
- void num24tostr(uint16 num)
- {
- dead24str[0]=num/10+0x30; //bai位
- dead24str[1]=num%10+0x30; //ge位
- }
-
- //12min数字转为字符串
- void num12tostr(uint16 num)
- {
- uint16 temp;
- temp= num;
- dead12str[0]=num/600+0x30; //bai位
- temp=num/60;
- dead12str[1]=temp%10+0x30; //ge位
- StringDisplay(11, 1, dead12str,2,1);
- StringDisplay(13, 1,":",1,1);
- dead12str[0]=(num%60)/10+0x30; //bai位
- dead12str[1]=(num%60)%10+0x30; //ge位
- StringDisplay(14, 1, dead12str,2,1);
-
- }
-
- //12min数字转为字符串
- void ocassionchange(uchar charch)
- {
- ocassionstr[0]=charch+0x30;
- switch(charch)
- {
- case 1:
- ocassionstr[1]='s';
- ocassionstr[2]='t';
- break;
- case 2:
- ocassionstr[1]='n';
- ocassionstr[2]='d';
- break;
- case 3:
- ocassionstr[1]='r';
- ocassionstr[2]='d';
- break;
- case 4:
- ocassionstr[1]='t';
- ocassionstr[2]='h';
- break;
-
- }
- }
-
- uchar P10last=0;
- uchar P11last=0;
- uchar P12last=0;
- uchar P13last=0;
- uchar P14last=0;
- uchar P15last=0;
- uchar P16last=0;
- uchar P17last=0;
- uchar P23last=0;
- uint16 bifenchange1=0;
- // uint16 bifenchange2=0;
- void keyslove1(void)
- {
- if(!P10)
- {
- P10last=1;}
- if(P10&P10last)
- { score1++;
- numtostr(score1);
- StringDisplay(0, 0, scorestr,3,1);
- P10last=0;
- }
- if(!P11)
- {
- P11last=1;}
- if(P11&P11last)
- { if(score1==0)
- {score1=0; }
- else
- {
- score1--;
-
- }
- numtostr(score1);
- StringDisplay(0, 0, scorestr,3,1);
- P11last=0;
- }
- if(!P12)
- {
- P12last=1;}
- if(P10&P12last)
- { TR0 = ~TR0 ; //启动定时器
-
- P12last=0;
- }
- if(!P13)
- {
- P13last=1;}
- if(P13&P13last)
- { score2++;
- numtostr(score2);
- StringDisplay(4, 0, scorestr,3,1);
- P13last=0;
- }
- if(!P14)
- {
- P14last=1;}
- if(P14&P14last)
- { if(score2==0)
- {score2=0; }
- else
- {
- score2--;
-
- }
- numtostr(score2);
- StringDisplay(4, 0, scorestr,3,1);
- P14last=0;
- }
- if(!P15)
- {
- P15last=1;}
- if(P15&P15last)
- {
- deadline24=24;
- num24tostr(deadline24);
- StringDisplay(14, 0, dead24str,3,10);
- P15last=0;
- }
- if(!P16)
- {
- P16last=1;}
- if(P16&P16last)
- {
- bifenchange1=score1;
- score1=score2;
- score2= bifenchange1;
- // numtostr(bifenchange1);
- // StringDisplay(0, 0, scorestr,3,1);
- //
- // numtostr2(bifenchange2);
- // StringDisplay(0, 4, scorestr2,3,1);
- //
- //
- // score1=bifenchange2;
- // score2= bifenchange1;
-
- P16last=0;
- }
- if(!P17)
- {
- P17last=1;}
- if(P17&P17last)
- { ocassioncount++;
- if(ocassioncount==5)
- {
- ocassioncount=1;
- }
-
- ocassionchange(ocassioncount);
- StringDisplay(0, 1, ocassionstr,3,1);
- P17last=0;
- }
- if(!P23)
- {
- P23last=1;}
- if(P23&P23last)
- {(*((void(code*)(void))0x0000))();
- P23last=0;
- }
-
- }
- uchar flagbuzz=0;
- void main(void)
- {
-
- P1=0xFF;
- P23=1;
- LCD1602Init();
- TMOD = 0x01; //初始化TMOD,定时器0,方式1
- TH0 = (65536 - 50000) / 256; //装填计数
- TL0 = (65536 - 50000) % 256;
- EA = 1; //开放所有中断
- ET0 = 1; //开放定时器0中断控制位
-
-
- numtostr(score1);
- StringDisplay(0, 0, scorestr,3,1);
- StringDisplay(3, 0,":",1,1);
- numtostr(score2);
- StringDisplay(4, 0, scorestr,3,1);
- num24tostr(deadline24);
- StringDisplay(14, 0, dead24str,3,10);
- ocassionchange(ocassioncount);
- StringDisplay(0, 1, ocassionstr,3,1);
- num12tostr(deadline12) ;
-
- while (1)
- {
- keyslove1();
- numtostr(score1);
- StringDisplay(0, 0, scorestr,3,1);
-
- StringDisplay(3, 0,":",1,1);
- // delay(50);
- numtostr(score2);
- StringDisplay(4, 0, scorestr,3,1);
- // delay(50);
- num24tostr(deadline24);
- StringDisplay(14, 0, dead24str,3,10);
-
- StringDisplay(0, 1, ocassionstr,3,1);
- num12tostr(deadline12) ;
- if(flagbuzz)
- {
- P37=~P37;
- delay(10);
- }
- }
- }
-
-
-
- uchar second1=0;
- int buzztime=0;
- void Interrupt() interrupt 1
- {
- TH0 = (65536 - 50000) / 256; //触发中断时重新装填计时
- TL0 = (65536 - 50000) % 256;
- second1++;
- if(second1==20)
- {
-
- second1=0;
- if(deadline24==0)
- { deadline24=0;
-
- }
- else{
- deadline24--;
- }
- if(deadline12==0)
- {
- deadline12=0;
- flagbuzz=1;
- }
- else{
- deadline12--;
- }
- if(flagbuzz)
- {
- if(buzztime==5)
- { flagbuzz=0;
- }
- else
- {buzztime++ ;
- }
-
- }
- }
-
-
- }
复制代码
所有资料51hei提供下载:
20190511篮球计分器.zip
(109.85 KB, 下载次数: 83)
|