微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机抢答器程序

单片机抢答器程序

时间:12-31 来源:互联网 点击:

#include at89x51.h>
#define uchar unsigned char
#define uint unsigned int

void delay(uint);
void sysini(void);

/************************************************************
*本程序版权所有
*http://www.51hei.com荣誉出品
*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); //循环判断 等待按键,同时显示0
//读取数据
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);
}



---------下面还介绍一个汇编语言编程的单片机抢答器程序原理请读者自行分析-------------------

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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top