本帖最后由 jhcj2014 于 2020-7-2 22:45 编辑
因MCC生成的程序中的函数很多,不理解,有点乱,所以主程序还是调试不了用定时器1进行1S时间闪烁LED。所以用下面手输的程序进行调试。但程序下载后还是无法运行,LED灯是一直灭的。请教下大家,下面程序哪些地方是错误的。
#include <xc.h>
#define uint unsigned int
uint num;
void timer1_init();
void main(void)
{
timer1_init();
while(num==20)
{
num=0;
PORTEbits.RE0=0;
}
return;
}
void timer1_init()
{
num=0;
TRISE=0x00;
PORTE=0xFF;
//TMR1CLK = 0x01;
TMR1CLK=0x04;
OSCFRQ=0x05;
TMR1H =(65536-50000)/256;
TMR1L = (65536-50000)%256;
T1CON = 0x03;
//IPR4=0x04;
PIE4bits.TMR1IE = 1;
PIR4bits.TMR1IF = 0;
INTCON = 0xC0;
}
void __interrupt() _tmer1(void)
{
PIR4bits.TMR1IF = 0;
TMR1H =(65536-50000)/256;
TMR1L = (65536-50000)%256;
num++;
} |