希望能帮到你,八路抢答器仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit m1=P3^1;
- sbit m2=P3^2;
- sbit k1=P1^0;
- sbit k2=P1^1;
- sbit k3=P1^2;
- sbit k4=P1^3;
- sbit k5=P1^4;
- sbit k6=P1^5;
- sbit k7=P1^6;
- sbit k8=P1^7;
- sbit k=P3^0;
- sbit beep=P3^7;
- uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77};
- uchar shiwei,gewei,xuanshou,count,i,second;
- uchar score1,score2,score3,score4,score5,score6,score7,score8;
- uint t,m,n,a,a1,a2,a3,a4,a5,a6,a7,a8;
- void Timer()
- {
- TMOD=0X01;
- TH0=0XD8;
- TL0=0Xf0;
- IE=0X82;
- TR0=1;
- }
- void tim(void) interrupt 1
- {TH0=0xd8;
- TL0=0xf0;
- count++;
- if(count==100)
- { count=0;
- second--;}
- }
- void delay(uint z)
- { uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--); }
- void display (uchar shiwei,gewei,xuanshou)
- { P2=0xfe;
- P0=shiwei;
- delay(5);
- P2=0xfd;
- P0=gewei;
- delay(5);
- P2=0xf7;
- P0=xuanshou;
- delay(5);
- }
- void dis(void)
- {shiwei=tab[second/10];
- gewei=tab[second%10];
- xuanshou=tab[i];
- display(shiwei,gewei,xuanshou);
- }
- void init()
- { P2=0x04;
- P0=0x3f;
- t=0;
- beep=0;
- i=0;
- second=29;
- score1=60;
- score2=60;
- score3=60;
- score4=60;
- score5=60;
- score6=60;
- score7=60;
- score8=60;
- a1=1;
- a2=1;
- a3=1;
- a4=1;
- a5=1;
- a6=1;
- a7=1;
- a8=1;
- }
- void main()
- { init();
- if(k==0)
- { Timer();
- delay(10);
- while(!k);
- while(1)
- { dis();
- m=0;
- n=0;}
- if(second==10){beep=1;delay(500);beep=0;}
- if(second==0){TR0=0;n=1;
- if(k==0)
- {beep=1;delay(500);beep=0;second=29;TR0=1;m=1;}
- } }
- if(n==0)
- { if(k1==0) {delay(5);if(k1==0);while(!k1);t=1;}
- else if(k2==0){delay(5);if(k2==0);while(!k2);t=2;}
- else if(k3==0){delay(5);if(k3==0);while(!k2);t=3;}
- else if(k4==0){delay(5);if(k4==0);while(!k2);t=4;}
- else if(k5==0){delay(5);if(k5==0);while(!k2);t=5;}
- else if(k6==0){delay(5);if(k6==0);while(!k2);t=6;}
- else if(k7==0){delay(5);if(k7==0);while(!k2);t=7;}
- else if(k8==0){delay(5);if(k8==0);while(!k2);t=8;}
- else if(k==0)
- {delay(5);if(k==0);while(!k);t=0;i=0;second=29;beep=1;delay(500);beep=0;TR0=1;}
- }
- while(t)
- { if(m==0)
- { switch(t)
- { case 1:
- { TR0=0;i=1;second=0;beep=1;delay(500);beep=0;
- a1=0;a2=1;a3=1;a4=1;a5=1;a6=1;a7=1;a8=1;m=1;break;
- }
- case 2:
- { TR0=0;i=2;second=0;beep=1;delay(500);beep=0;
- a2=0;a1=1;a3=1;a4=1;a5=1;a6=1;a7=1;a8=1;m=1;break;
- }
- case 3:
- { TR0=0;i=3;second=0;beep=1;delay(500);beep=0;
- a3=0;a1=1;a2=1;a4=1;a5=1;a6=1;a7=1;a8=1;m=1;break;
- }
- case 4:
-
- { TR0=0;i=4;second=0;beep=1;delay(500);beep=0;
- a4=0;a1=1;a2=1;a3=1;a5=1;a6=1;a7=1;a8=1;m=1;break;
- }
- case 5:
- { TR0=0;i=5;second=0;beep=1;delay(500);beep=0;
- a5=0;a1=1;a2=1;a3=1;a4=1;a6=1;a7=1;a8=1;m=1;break;
- }
- case 6:
- { TR0=0;i=6;second=0;beep=1;delay(500);beep=0;
- a6=0;a1=1;a2=1;a3=1;a4=1;a5=1;a7=1;a8=1;m=1;break;
- }
- case 7:
- { TR0=0;i=7;second=0;beep=1;delay(500);beep=0;
- a7=0;a1=1;a2=1;a3=1;a4=1;a5=1;a6=1;a8=1;m=1;break;
- }
- case 8:
- { TR0=0;i=8;second=0;beep=1;delay(500);beep=0;
- a8=0;a1=1;a2=1;a3=1;a4=1;a5=1;a6=1;a7=1;m=1;break;
- }
- }
- }
- if(a1==0)
- {second=score1;
- dis();
- if(m1==0)
- {delay(5);if(m1==0);while(!m1);beep=1;delay(100);beep=0;score1+=1;if(score1==99)score1=60;}
- else if(m2==0)
- {delay(5);if(m2==0);while(!m2);beep=1;delay(100);beep=0;score1-=1;if(score1==0)score1=60;
- }
- dis();
- }
- else if(a2==0)
- { second=score2;
- dis();
- if(m1==0)
- {delay(5);if(m1==0);while(!m1);beep=1;delay(100);beep=0;score2+=1;if(score2==99)score2=60;}
- else if(m2==0)
- {delay(5);if(m2==0);while(!m2);beep=1;delay(100);beep=0;score2-=1;if(score2==0)score2=60;}
- dis();
- }
- else if(a3==0)
- {second=score3;
- dis();
- if(m1==0)
- {delay(5);if(m1==0);while(!m1);beep=1;delay(100);beep=0;score3+=1;if(score3==99)score3=60;}
- else if(m2==0)
- {delay(5);if(m2==0);while(!m2);beep=1;delay(100);beep=0;score3-=1;if(score3==0)score3=60;}
- dis();
- }
- else if(a4==0)
- { second=score4;
- dis();
- if(m1==0)
- {delay(5);if(m1==0);while(!m1);beep=1;delay(100);beep=0;score4+=1;if(score4==99)score4=60;}
- else if(m2==0)
- {delay(5);if(m2==0);while(!m2);beep=1;delay(100);beep=0;score4-=1;if(score4==0)score4=60;}
- dis();
- }
- else if(a5==0)
- {second=score5;
- dis();
- if(m1==0)
- {delay(5);if(m1==0);while(!m1);beep=1;delay(100);beep=0;score5+=1;if(score5==99)score5=60;}
- else if(m2==0)
- {delay(5);if(m2==0);while(!m2);beep=1;delay(100);beep=0;score5-=1;if(score5==0)score5=60;}
- second=score5;
- dis();
- }
- else if(a6==0)
- {second=score6;
- dis();
- if(m1==0)
- {delay(5);if(m1==0);while(!m1);beep=1;delay(100);beep=0;score6+=1;if(score6==99)score6=60;}
- else if(m2==0)
- {delay(5);if(m2==0);while(!m2);beep=1;delay(100);beep=0;score5-=1;if(score5==0)score5=60;}
- second=score6;
- dis();
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
八路抢答器.rar
(28.83 KB, 下载次数: 22)
|