下面c语言程序是关于单片机pwm调光的,请讲一下程序流程和具体功能,怎么实现调光的,越详细越好
voidInitial_timer(void){TMOD=0x01;TH0=(65536-10)/256;//periodTL0=(65536-10)%256;TR0=1...
void Initial_timer(void)
{
TMOD = 0x01;
TH0 = (65536-10) / 256; //period
TL0 = (65536-10) % 256;
TR0 = 1;
ET0 = 1;
EX0 = 1; EX1 = 1;
IT0 = 1; IT1 = 1;
EA = 1;
a = 0;
b=250;
}
void time0() interrupt 1
{
TL0 = (65536-10) % 256;
TH0 = (65536-10) / 256;
a++;
if(a == 85) a = 0;
if(a > b) P1 = 0xff;
else P1 = 0x00;
flag=0;
} 展开
{
TMOD = 0x01;
TH0 = (65536-10) / 256; //period
TL0 = (65536-10) % 256;
TR0 = 1;
ET0 = 1;
EX0 = 1; EX1 = 1;
IT0 = 1; IT1 = 1;
EA = 1;
a = 0;
b=250;
}
void time0() interrupt 1
{
TL0 = (65536-10) % 256;
TH0 = (65536-10) / 256;
a++;
if(a == 85) a = 0;
if(a > b) P1 = 0xff;
else P1 = 0x00;
flag=0;
} 展开
1个回答
推荐于2018-04-14
展开全部
看单片机的寄存器的说明
void Timer0Init(void) //100微秒@11.0592MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0xAE; //设置定时初值
TH0 = 0xFB; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
void Timer0Init(void) //100微秒@11.0592MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0xAE; //设置定时初值
TH0 = 0xFB; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询