利用外部中断实现8路智力抢答器

本文介绍了一个基于51单片机的简单程序,该程序利用定时器进行计数并显示在LED上。同时,通过外部中断实现计数的重置,并详细展示了如何配置定时器中断和服务函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<stdio.h>
#include<reg51.h>

 

sbit P20=P2^0;
sbit P21=P2^1;
sbit P32=P3^2;
sbit P00=P0^0;
sbit P01=P0^1;
sbit P02=P0^2;
sbit P03=P0^3;
sbit P04=P0^4;
sbit P05=P0^5;
sbit P06=P0^6;
sbit P07=P0^7;
sbit P17=P1^7;

unsigned int xx=9;
unsigned int yy=0;
unsigned char tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80};
void main()
{
#ifndef MONIOTR51
TMOD=0x01;
TH0=0x3C;
TL0=0xB0;
EA=1;
ET0=1;
EX0=1;
TR0=1;
#endif

while(xx)
{
P1=tab[yy];
}
TR0=0;
yy=0;

P20=1;
while(1)
 {
 P1=tab[yy];
 P20=(P00&P01&P02&P03&P04&P05&P06&P07);
 }
}

void timer0() interrupt 1
{
static unsigned int count=0;
TH0=0x3C;
TL0=0xB0;
count++;
if(count==10)  {xx--;count=0;yy++;}
}

void int0() interrupt 0
{
int k;
if(!P00) yy=1;
if(!P01) yy=2;
if(!P02) yy=3;
if(!P03) yy=4;
if(!P04) yy=5;
if(!P05) yy=6;
if(!P06) yy=7;
if(!P07) yy=8;
P21=0;
for(k=0;k<1000;k++) ;
P21=1; 
 while(P17) {P1=tab[yy];}
 yy=0;
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值