單片機(jī)搶答器程序
#include at89x51.h>
#define uchar unsigned char
#define uint unsigned int
void delay(uint);
void sysini(void);
/************************************************************
*本程序版權(quán)所有
*http://www.51hei.com榮譽(yù)出品
*c語言編寫的單片機(jī)搶答器程序已經(jīng)測(cè)試成功,大家燒寫到芯片中就可以直接使用了
*************************************************************/
void main(void)
{sysini();
while(1)
{
P2=0x3f;
P2=0x3f;
if(P1!=0xff)
{P2=0x7c;
P3_1=0;
delay(65535);
P3_1=1;
continue;
}
while(P1==0xff); //循環(huán)判斷 等待按鍵,同時(shí)顯示0
//讀取數(shù)據(jù)
switch(P1)
{case 0xfe:P2=0x03;break; //1
case 0xfd:P2=0x6d;break; //2
case 0xfb:P2=0x67;break; //3
case 0xf7:P2=0x53;break; //4
case 0xef:P2=0x76;break; //5
case 0xdf:P2=0x7e;break; //6
case 0xbf:P2=0x23;break; //7
case 0x7f:P2=0x7f;break; //8
default: P2=0x7c;
}
P3_1=0;
delay(65535);
P3_1=1;
while(P3_2)
{if(!P3_2) break;
if(!P3_2) break;
if(!P3_2) break;
if(!P3_2) break;
}
}
}
void delay(uint a)
{uint i;
for(i=0;ia;i++)
;
}
void sysini(void)
{P2=0x00;delay(10000);
P2=0x01;delay(10000);
P2=0x02;delay(10000);
P2=0x04;delay(10000);
P2=0x08;delay(10000);
P2=0x10;delay(10000);
P2=0x20;delay(10000);
P2=0x00;delay(40000);
P2=0x38;delay(40000);
P2=0x00;delay(40000);
P2=0x7b;delay(40000);
P2=0x00;delay(40000);
P2=0x7b;delay(40000);
P2=0x00;delay(40000);
P2=0x01;delay(30000);
P2=0x03;delay(30000);
P2=0x07;delay(30000);
P2=0x0f;delay(30000);
P2=0x1f;delay(30000);
P2=0x3f;delay(30000);
}
---------下面還介紹一個(gè)匯編語言編程的單片機(jī)搶答器程序原理請(qǐng)讀者自行分析-------------------
C0002:
MOV P2,#0C0H
C0004:
MOV A,P1
CPL A
JZ C0004
C0005:
MOV R7,P1
MOV A,R7
ADD A,#081H
JZ C0014
ADD A,#0C0H
JZ C0013
ADD A,#0E0H
JZ C0012
ADD A,#0F0H
JZ C0011
ADD A,#0F8H
JZ C0010
ADD A,#0FCH
JZ C0009
ADD A,#0FEH
JZ C0008
DEC A
JNZ C0015
C0007:
MOV P2,#0FCH
SJMP C0016
C0008:
MOV P2,#092H
SJMP C0016
C0009:
MOV P2,#098H
SJMP C0016
C0010:
MOV P2,#0ACH
SJMP C0016
C0011:
MOV P2,#089H
SJMP C0016
C0012:
MOV P2,#081H
SJMP C0016
C0013:
MOV P2,#0DCH
SJMP C0016
C0014:
MOV P2,#080H
SJMP C0016
C0015:
MOV P2,#088H
C0016:
JNB P3_1,C0002
SJMP C0016m
評(píng)論