先声明本人小菜鸡一枚,然后上传的都是一些基础51课程实验,利用外部中断写的一个八路抢答器,该内容还有可能存在一些bug,故仅供参考

注意:仿真使用的是共阴数码管

#include<reg52.h>

#define uchar unsigned char
#define uint unsigned int
	
sbit LED_main = P3^6;
sbit Key = P3^0 ; 


uchar code tabie [] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

uchar main_go = 0;//主线


void Init_EX_0()//中断初始化函数
{
	EA = 1;
	EX0 = 1;
	IT0 = 1;
}

void Servoice_EX_0()  interrupt 0  //中断服务函数
{
	if(main_go == 1)
	{
		main_go = 0;//恢复主线,防止点亮多个LED灯
		P2 = 0xff;//读P2口的状态
		switch(P2)//判断是哪一个按键按下
		{
			case 0xfe : P1 = 0xfe; P0 = tabie [1] ; LED_main = 1; break;//第一个按键按下(下面递推)
			case 0xfd : P1 = 0xfd; P0 = tabie [2] ; LED_main = 1; break;
			case 0xfb : P1 = 0xfb; P0 = tabie [3] ; LED_main = 1; break;
			case 0xf7 : P1 = 0xf7; P0 = tabie [4] ; LED_main = 1; break;
			case 0xef : P1 = 0xef; P0 = tabie [5] ; LED_main = 1; break;
			case 0xdf : P1 = 0xdf; P0 = tabie [6] ; LED_main = 1; break;
			case 0xbf : P1 = 0xbf; P0 = tabie [7] ; LED_main = 1; break;
			case 0x7f : P1 = 0x7f; P0 = tabie [8] ; LED_main = 1; break;
		}
	}
}

void Scan_Key()//裁判按键扫描函数
{
	if(Key == 0)
	{
		main_go = 1;  //主线等于 1 时说明可进行抢答
		LED_main = 0 ;//同时点亮裁判灯
		P0 = 0x00;//关闭数码管
		P1 = 0xff;//关闭LED灯
	}
}

void main()
{
	Init_EX_0();//进行初始化操作
	while(1)
	{
		Scan_Key();//不断扫描裁判按键
	}
}

仿真图如下

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5qSw5ZWK5qSw5ZOm,size_20,color_FFFFFF,t_70,g_se,x_16