用外部中断1做一计数器的c语言程序怎么写

2025-02-25 05:36:01
推荐回答(2个)
回答1:

#include "reg52.h"
sbit key=P3^2;
void main()
{
IT0=1; //外部中断0连沿触发方式
EX0=1; //使能外部中断0
EA=1; //开部中断

while(1) ;
}
void int0() interrupt 0
{

int tab[]={0xff,0x7f,0xbf,0x3f,0xdf,0x5f,0x9f,0x1f,0xef,0x6f,0xaf,0x2f,0xcf,0x4f,0x8f,0x0f} ;

int count=15;
long int i;

while(1)
{
if(key==0)
for(i=0;i<10000;i++);
if(key==0)
{ count--;

if(count==0)
count=15;
P3= tab[count] ;
while(key==0);
}
}

}

回答2:

循环语句就行了,加个计数器i