(分享设计)这是一个简单的51单片机的篮球比分牌,两位数计时,附件里面含有源代码和仿真原理图。
本人是新手,做得比较简单。
计时是24秒的倒计时,加分是+1分的设置。
篮球比分牌仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
程序代码:
单片机源程序如下:
- #include <reg51.h>
- #include<intrins.h>
- sbit led=P1^7;
- sbit sy=P1^6;
- bit second=0,trun=1;
- unsigned char key,t1,t2=24;
- unsigned char SMG_CA[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
- unsigned char score[8]={0,0,0,0,0,0,0,0};
- void delayms(unsigned int x)
- {
- unsigned char t;
- while(x--)
- for (t=0;t<120;t++);
- }
- void service_int0 (void) interrupt 0
- {
- key=P1& 0x0f;
- }
- void timer0(void) interrupt 1
- {
- t1++;
- if (t1==20)
- {
- t1=0; second=1;
- }
- TH0=0X3C;TL0=0Xb0;
- }
- void Alarm(unsigned char m)
- {
- unsigned char n,k;
- for(n=0;n<200;n++)
- {
- sy=~sy;
- for(k=0;k<m;k++); //由参数t行成不同的频率
- }
- }
- main ()
- {
- unsigned char i,wei=0x80,a=0,a1=0,a2=0,a3=0,b=0,b1=0,b2=0,b3=0;
- TMOD=0X01;
- TH0=0X3C;
- TL0=0Xb0;
- TR0=1;
- ET0=1;
- IT0=1;
- EX0=1;
- EA=1;
- sy=0;
- while(1)
- {
- if(key==0x0e)
- {
- a=a+1;
- a3=a/100;
- a2=(a-a3*100)/10;
- a1=a-a3*100-a2*10;
- score[0]=a3;score[1]=a2;score[2]=a1;
- }
- if(key==0x0d)
- {
- b=b+1;
- b3=b/100;
- b2=(b-b3*100)/10;
- b1=b-b3*100-b2*10;
- score[5]=b3;score[6]=b2;score[7]=b1;
- }
- score[3]=t2/10;
- score[4]=t2%10;
- if (key==0x0c)
- {
- trun=~trun;
- if (trun==0) {TR0=0;led=0;}
- else {TR0=1;led=1;}
- }
- if(key==0x0b) {t2=24;}
- key=0;
- if(second==1)
- {
- second=0;
- t2--;
- if(t2<=0||t2>24)
- {
- t2=0;
- Alarm(90);
- }
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
篮球比分牌.zip
(74.35 KB, 下载次数: 109)
|