回复
今天又遇到问题了,就是按照while(1)改变位置后,由于在while(1)中有中断产生,使得有时定时器1的重新装载执行了,而定时器0的重新装载没执行,输出的波形总是在变化,我把程序改成定时器1定时总周期,但是输出总是高电平,不知为什么,有什么解决办法?
#include <reg51.h>
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
sbit P2_6=P2^6;
sbit P2_7=P2^7;
unsigned int t=30;
void timer0(void) interrupt 1 using 1 //定时器0中断服务程序
{
TR0=0;
P2_7=0;
}
void timer1(void) interrupt 3 using 2 //定时器1中断服务程序
{
P2_7=1;
TR0=1;
}
void service_int1(void) interrupt 0 using 3 //外部中断服务程序
{
EA=1;
t=0;
if(P2_6) t=64;
if(P1_5) t=t+32;
if(P1_4) t=t+16;
if(P1_3) t=t+8;
if(P1_2) t=t+4;
if(P1_1) t=t+2;
if(P1_0) t=t+1;
t=t/2;
}
void main(void)
{
while(1)
{
IP=0x0a;
IT0=1;
TMOD=0x22;
TH1=256-41;
TL1=TH1;
TH0=256-t;
TL0=TH0;
IE=0x8b;
TR0=1;
TR1=1;
}
}
发表时间:2006年8月8日9:22:28