|
基于單片機(jī)的三路搶答器的設(shè)計
設(shè)計內(nèi)容:
1.具有3路搶答輸入(由獨立按鍵實現(xiàn) )
2.顯示搶答剩余時間,初始為10秒,最小量化單位為1秒;
3.搶答結(jié)束后,成功的那一路,并顯示搶答成功的號碼;失敗的其他路,并顯示F;
4.如果沒有人搶答,報警,并重新進(jìn)入開始搶答狀態(tài)。
我不知道如何該在外部中斷執(zhí)行第三條要求
#include<reg51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={0xc0,0x90,0x80,0xF8,0x82,0x92,0x99,0xb0,0xa4,0xf9};
uchar code table1[]={0x71,0x06,0x00,0x71};//一搶
uchar code table2[]={0x06,0x71,0x00,0x71}; // 二搶
uchar code table3[]={0x71,0x71,0x00,0x06}; // 三搶
uchar code address[]={0x08,0x04,0x02,0x01};
void delayms(uint);
sbit w=P3^6;
sbit p=P3^0;
sbit a=P3^2;
int n;
uint m;
void delay(uint z) //延時子程序
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delayms(uint m)
{
while(m--);
}
void main()
{
EA=1;
EX0=1;
IP=0X04;
IT0=1;
EX1=1;
IT1=1;
while(1);
}
void INT_0() interrupt 0
{
if(p==0) //中斷0,按下p3.2開始,d9亮并開始倒計時
w=0;
EX0=0;
delay(20);
EX0=1;
while(1)
{
if(m==10)
{
P0=0x89;
a=0;
delayms(20);
}
else
{P0=table[m];
delay(1000);
m++;}
}
}
void INT_1() interrupt 2
{
EX1=0;
delay(20);
EX1=1;
while(1)
if(w==0)
{if(P2=0xfe)
while(1)
{
if(m==4)m=0;
P1=address[m];
P0=table1[m++];delayms(500);
}
else if(P2=0xfd)
{
if(m==4)m=0;
P1=address[m];
P0=table2[m++];delayms(500);
}
else
{
if(m==4)m=0;
P1=address[m];
P0=table3[m++];delayms(500);
}
}
}
|
-
255.PNG
(50.27 KB, 下載次數(shù): 20)
下載附件
2018-12-21 22:58 上傳
|