如何用中断产生固定个数脉冲 ,请各位大神指点迷津 就用一个定时器。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar time;
uchar period=250;
uchar high=50;
sbit a=P1^3;
void init_timer0(void)
{
TMOD |=0x00;
TH0=0x00;
TL0=0x00;
EA=1;
ET0=1;
TR0=1;
}
void main()
{
init_timer0();
while(1);
}
void Timer0_isr(void) interrupt 1 using 1
{ int i;
for(i=0;i<30;i++)
{
TH0=0xff;
TL0=0xfe;
if(++time==high)
a=1;
else if(time==period)
{time=0;a=0;}
}
}
|