缘由51单片机怎么实现通过外部中断出发定时器-编程语言-CSDN问答

cpp
#include"reg52.h"
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
unsigned char Js=0,c=0;
unsigned char code led_mod[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x79};//共阴极数码管0-9
void EX_Init()
{
TH1+=(65536-9216)/256;/*定时器赋初值,定时10ms触发中断,自动补偿方式*/
TL1+=(65536-9216)%256;
TMOD=0X10;//16位定时器/计数器
ET1=EA=EX1=IT1=1; //启动定时器T0开启定时器。
TR1=0;
}
void main()
{
unsigned char xd=0;
EX_Init();P2=0;
while(1)
{
P0 = ~led_mod[c?c:10];
if(TR1&&c)
{
if(Js==100)
{Js=0;if(--c==0)TR1=0;}
if(!s1&&++xd==0)
{TR1=0;while(!s1)P1 = ~led_mod[1];P2=15;}
if(!s2&&++xd==0)
{TR1=0;while(!s2)P1 = ~led_mod[2];P2=15;}
if(!s3&&++xd==0)
{TR1=0;while(!s3)P1 = ~led_mod[3];P2=15;}
}
}
}
void EX0_ISP()interrupt 2
{
c=5;TR1=1;P2=12;Js=0;
}
void ZhongDuan() interrupt 3
{
++Js;
TH1+=(65536-9216)/256;
TL1+=(65536-9216)%256;
}
