/***********************************
功能:定时器测试程序
MCU:dsPIC30F4011
TOOLS:MPLAB X IDE V3.15 + XC16 V1.25
震荡器:外部4M晶振
芯艺设计室 http://www.chipart.cn
2015-12-04
***********************************/
#include "xc.h"
#include <stdint.h>
#define XTFREQ 4000000 // xtal = 4Mhz;
#define PLLMODE 16 // PLLx16
#define FCY XTFREQ*PLLMODE/4 // Instruction Cycle Frequency
#define LED_PORT_INIT TRISBbits.TRISB6=0
#define LED_ON LATBbits.LATB6=1
#define LED_OFF LATBbits.LATB6=0
#define LED_FLASH LATBbits.LATB6^=1
_FOSC(CSW_FSCM_OFF & XT_PLL16);
_FWDT(WDT_OFF);
void __attribute__((__interrupt__,no_auto_psv))_T1Interrupt(void)
{
LED_FLASH;
IFS0bits.T1IF = 0;
}
void Timer1Init(void)
{
PR1=62500; //16000000/256
T1CONbits.TCKPS=3; //256
IEC0bits.T1IE=1;
T1CONbits.TON=1;
}
int main( void )
{
LED_PORT_INIT;
Timer1Init();
while(1)
{
}
return 0;
}
|
|