0.png (58.4 KB, 下載次數: 64)
下載附件
2017-11-19 06:22 上傳
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
0.png (47.04 KB, 下載次數: 60)
下載附件
2017-11-19 06:23 上傳
0.png (15.49 KB, 下載次數: 75)
下載附件
2017-11-19 06:23 上傳
單片機源程序如下:
- #include <REGX51.H>
- #define Keytimer_1 10
- sbit K0=P3^0;
- 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 A575=P2^0; sbit B575=P2^1; sbit C575=P2^2;
- sbit BZ=P2^3;
- unsigned int Keytimer=0,t=0,sec=60,OK=0,hh=0,sec1=0;
- unsigned char DM[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; //8個數碼管段碼表
- unsigned char WE[4]={0x01,0x02,0x04,0x08}; //8個數碼管段碼表
- void flang();
- /*------------------------------------------------
- 公用延遲函數
- ------------------------------------------------*/
- void delayus(unsigned int y)
- {
- while(y--);
- }
- //*****************定時器初始化**************************
- void initialize(void)
- {
- TMOD =0x01;
- TH0 = 0x3C;
- TL0 = 0xB0; //50ms
- ET0 = 1;
- EA = 1;
- TR0 = 1;
- }
- /*------------------------------------------------
- 8位數碼管 指針 顯示函數
- ------------------------------------------------*/
- void shumaxianshi()
- {
- unsigned char i,ii=2,tempP[4];
- if(OK==2)
- {ii=4;flang();
- tempP[0] = sec1/10%10;
- tempP[1]=sec1%10;
- }
- else
- {tempP[0] = sec/10%10;
- tempP[1]=sec%10;}
- tempP[2]=hh/10%10;
- tempP[3] = hh %10;
- for(i=0;i<ii;i++)
- {
- P0=DM[tempP[i]]; //指針賦值
- A575=1;A575=0;
- delayus(4);
- P0=~WE[i];
- B575=1;B575=0;
- delayus(4); //最低限制
- P0=0xff;
- B575=1;B575=0;
- }
- }
- unsigned char KES()
- {
- if(K1==1&&K2==1&&K3==1&&K4==1&&K5==1&&K6==1&&K7==1&&K8==1&&K0==1) //沒有按的時候 返回 加快 51 跑的速度
- return 0;
- if(K0==0 && !Keytimer)
- {
- Keytimer=Keytimer_1;
- return 9;
- }
- if(K1==0 && !Keytimer)
- {
- Keytimer=Keytimer_1;
- return 1;
- }
- if(K2==0 && !Keytimer)
- {
- Keytimer=Keytimer_1;
- return 2;
- }
- if(K3==0 && !Keytimer)
- {
- Keytimer=Keytimer_1;
- return 3;
- }
- if(K4==0 && !Keytimer)
- {
- Keytimer=Keytimer_1;
- return 4;
- }
- if(K5==0 && !Keytimer)
- {
- Keytimer=Keytimer_1;
- return 5;
- }
- if(K6==0 && !Keytimer)
- {
- Keytimer=Keytimer_1;
- return 6;
- }
- if(K7==0 && !Keytimer)
- {
- Keytimer=Keytimer_1;
- return 7;
- }
- if(K8==0 && !Keytimer)
- {
- Keytimer=Keytimer_1;
- return 8;
- }
- return 0;
- }
- void main()
- {
- unsigned char yh;
- BZ=1;
- A575=B575=C575=0;
- P0=0x00;
- C575=1;C575=0;
- initialize();
- while(1)
- {
- yh=KES();
- if(yh==9)
- {
- OK++;
- if(OK==3){OK=0;sec=60,sec1=t=0;P0=0x00;
- C575=1;C575=0;BZ=1;
- }
- }
- else if(OK==1 && yh>=1)
- {
- OK=2;
- hh=yh;
- if(yh==1)
- {
- P0=0x01;
- C575=1;C575=0;
- }
- else if(yh==2)
- {
- P0=0x02;
- C575=1;C575=0;
- }
- else if(yh==3)
- {
- P0=0x04;
- C575=1;C575=0;
- }
- else if(yh==4)
- {
- P0=0x08;
- C575=1;C575=0;
- }
- else if(yh==5)
- {
- P0=0x10;
- C575=1;C575=0;
- }
- else if(yh==6)
- {
- P0=0x20;
- C575=1;C575=0;
- }
- else if(yh==7)
- {
- P0=0x40;
- C575=1;C575=0;
- }
- else if(yh==8)
- {
- P0=0x80;
- C575=1;C575=0;
- }
- }
- shumaxianshi();
- }
- }
- void Timer0(void) interrupt 1
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
八路搶答器.rar
(165.37 KB, 下載次數: 80)
2017-11-18 19:28 上傳
點擊文件名下載附件
51單片機八路搶答器 下載積分: 黑幣 -5
|