请教各位高人,为什么我在t0的中断里设置的判断中断计数的led状态没有改变呢 按照我的设想,在中断不同的次数里,led会输出不同的状态 不知问题在哪里 请各位指点一二
// 18.432MHz
#include "reg52.h"
#define PWM8BIT 485
#define HIGHDUTY 80
#define LOWDUTY (PWM8BIT-HIGHDUTY)
sfr AUXR = 0x8e;
sfr INT_CLKO = 0x8f;
sbit T0CLKO = P1^0;
sbit led = P1^1;
bit flag;
unsigned int cout;
void tm0() interrupt 1
{
T0CLKO = !T0CLKO;
flag = !flag;
if (flag)
{
TL0 = (65536-HIGHDUTY);
TH0 = (65536-HIGHDUTY) >> 8;
}
else
{
TL0 = (65536-LOWDUTY);
TH0 = (65536-LOWDUTY) >> 8;
}
cout=+1;
switch(cout)
{
case 20:
led=0;
break;
case 40:
led=1;
break;
case 60:
led=0;
break;
case 80:
led=1;
break;
case 100:
led=0;
break;
case 120:
led=1;
break;
case 140:
led=0;
break;
case 160:
led=1;
break;
case 180:
led=0;
break;
case 200:
led=1;
break;
}
if (cout==200)
{
cout=1;
}
}
void main()
{
AUXR = 0x80;
INT_CLKO = 0x01;
TMOD &= 0xf0;
TL0 = (65536-LOWDUTY);
TH0 = (65536-LOWDUTY) >> 8;
T0CLKO = 1;
flag = 0;
TR0 = 1;
ET0 = 1;
EA = 1;
cout=1;
led=0;
while (1);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>