本帖最后由 小S咯 于 2017-7-13 10:58 编辑
// 1/16M * 1000 = 62.5
#define TH0_INIT (65536-1000)/256
#define TL0_INIT (65536-1000)%256
u8 dat1=0;
void Timer0_Init(void)
{
TIMER0_MODE1_ENABLE; //Timer0 mode1 configuration
set_T0M;
TH0 = TH0_INIT;
TL0 = TL0_INIT;
set_ET0; //enable Timer0 interrupt
set_EA; //enable interrupts
set_TR0; //Timer0 run
}
void Timer0_ISR (void) interrupt 1 //interrupt address is 0x000B
{
static u8 Count=0;
clr_TR0; //
TH0 = TH0_INIT;
TL0 = TL0_INIT;
set_TR0;
if(++Count>=120)
Count=0;
if(dat1>Count)
P05=0;
else
P05=1;
}
void main()
{
int i=1;
while(1)
{ dat1=dat1+i;
if(dat1>=120)
i=-1;
if(dat1<=0)
i=1;
}
}
问题:
1.中断里Count加到120,是不是说明PWM斜率为1/120?
2.dat1加到120是什么意思,改变会不会有什么影响
3.PWM频率?
|