主要问题:想使用定时器0中断,并且配置LED2一秒钟变化一次,时钟想配置内部16M,现在的问题是LED2用示波器观测时1.12秒变化一次,目前还没找到问题,求助各位,已经三天了!
/********************部分配置字
#pragma config RETEN = ON
#pragma config INTOSCSEL = HIGH
#pragma config SOSCSEL = DIG
#pragma config XINST = OFF
// CONFIG1H
#pragma config FOSC = INTIO2
#pragma config PLLCFG = OFF
#pragma config FCMEN = OFF
#pragma config IESO = OFF
// CONFIG2L
#pragma config PWRTEN = OFF
#pragma config BOREN = SBORDIS
#pragma config BORV = 3 // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)
// CONFIG2H
#pragma config WDTEN = OFF // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 16 // Watchdog Postscaler (1:1048576)
// CONFIG3L
#pragma config RTCOSC = INTOSCREF // RTCC Clock Select (RTCC uses INTOSCREF)
// CONFIG3H
#pragma config CCP2MX = PORTC // CCP2 Mux (RC1)
#pragma config MSSPMSK = MSK7 // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON // Master Clear Enable (MCLR Enabled, RG5 Disabled)
// CONFIG4L
#pragma config STVREN = ON // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K // Boot Block Size (2K word Boot Block size)
********************/
/************************时钟配置部分
IRCF2 = 1;
IRCF1 = 1;
IRCF0 = 1; //内部16M时钟
SCS1 = 1;
PLLEN = 0; //不4倍频
SOSCRUN = 0;
MFIOSEL = 0;
//OSCTUNE = 0X80;
while(!HFIOFS);
************************/
/***********************定时器配置部分
void Time0InitConfig()
{
T08BIT = 0; //16位定时器
T0CS = 0; //内部1/4FOSC时钟
T0PS2 = 0;
T0PS1 = 0;
T0PS0 = 1; //预分频器1/4分频
PSA = 0; //设置使用预分频器的频率
TMR0L = 0x9c;
TMR0H = 0xff;
//TMR0 = 156; //定时100us
TMR0IE = 1; //启动中断
TMR0ON = 1; //开启定时器中断
TMR0IF = 0;
}
***********************/
/************定时器中断
void Tmr0Interrupt_ISR()
{
static uint x;
if(TMR0IF == 1)
{
TMR0IF = 0;
TMR0L = 0x9c;
TMR0H = 0xff;
BeepWork();
x++;
if(x <= 10000)
LED2 = 0;
else if(x <= 20000)
LED2 = 1;
else
x = 0;
}
}
/************
|