// PIC18F24Q10 Configuration Bit Settings
#include <xc.h>
#pragma config RSTOSC = HFINTOSC_64MHZ // Power-up default value for COSC bits (HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1)
#pragma config MCLRE = INTMCLR // Master Clear Enable bit (If LVP = 0, MCLR pin (RE3) is an input; If LVP =1, MCLR pin (RE3) is MCLR)
#pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit (PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle)
#pragma config WDTE = OFF // WDT operating mode (WDT Disabled)
void __interrupt() isr(void)
{
TMR0IF=0; //清零中断位
LATC1=~LATC1; //驱动LED,每秒闪烁一次,正常
}
void main(void)
{
TRISC1=0; //输出驱动LED,测试T0计数溢出中断
TRISC2=0; //输出驱动LED,测试T0输出,LED不会闪烁,不正常
ANSELC2=0;
//PPSLOCK=0;
RC2PPS=0x13; //端口定义为由计数器TMR0计数溢出输出
//PPSLOCK=1;
GIEH=1; //全局中断允许位
GIEL=1; //外设中断允许位
IPEN=0; //禁止中断优先级
T0CON0|=0x80; //TMR0 使能位
T0CON0+=8; //0->15 = 1-16分频(后分频),值是8就是9分频
T0CON1=64+12; //时钟源=Fosc/4,4096预分频
TMR0H=217; //8位计时的周期值
TMR0IE=1; //中断使能,速度=16M/(9*4096*217)=2次/秒
while(1);
}
|
网上找个现成的程序对照一下!