硬件是LB1012触控板 MCU:SC92F8462B ,用引出脚P25(板上丝印P03)来指示中断频率.Fsys=Fosc/2
我想要的是100Hz的中断,实际上测量引出P25脚波形是396Hz,也就是中断是800Hz,问题在哪里,望网友赐教.
程序如下:
#include "SC92F846XB_C.h"
volatile uint8_t timer0_counter = 0 ;
//=======定时器0程序区============
void timer0_init(void)
{
TMCON = (TMCON&0xfe)|(0<<0); //bit0: 0为Fsys/12,1为Fsys
TMOD = TMOD&0xfe; //设置定时0,工作方式1
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TF0 = 0; //清中断标志
TR0=0; //关定时器0
ET0=1; //使能定时器0中断
TR0=1;
IPT0 = 1; //优先级高
EA =1;
}
#define LED1 P25 //悬空,拉高
//========定时器0中断服务程序区===========
void timer0()interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
if( timer0_counter == 0)
{
LED1 = 0;
timer0_counter = 1;
}
else
{
LED1 = 1;
timer0_counter = 0;
}
}
main()
{
P0CON|=0xC0,P1CON|=0xC0,P2CON|=0x0C,P5CON|=0x03; //SC92F8462B的未引出来的IO口配置
P0CON = 0xFF;
P0PH = 0xFF;
P2CON = 0xFF;
P2PH = 0xFF;
timer0_init();
while(1);
}
|