#include <xc.h>
#include <stdio.h>
#include <stdint.h>
#include <proc/p32mx170f256b.h>
#include <sys/attribs.h>
//Configuration bits
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider (2x Divider)
#pragma config FPLLMUL = MUL_20 // PLL Multiplier (20x Multiplier)
#pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (PLL Divide by 2)
// DEVCFG1
#pragma config FNOSC = PRIPLL // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disabled)
#pragma config IESO = ON // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = HS // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
// DEVCFG0
#pragma config JTAGEN = OFF // JTAG Enable (JTAG Disabled)
//Definición de ISR
void __attribute__( (interrupt(ipl2),
vector(_TIMER_1_VECTOR))) Timer1Handler ( void );
int main() {
INTCONbits.MVEC = 1; //Interrupt controller configured for Multi-vectored mode
IPC1 = 0;
IPC1bits.T1IP = 2; //Priority
//TIMER1 CONFIG
T1CONbits.ON = 1; //Timer1 ON
T1CONbits.TCKPS0 = 0; //00 = 1:1 prescale value
T1CONbits.TCKPS1 = 0;
T1CONbits.TCS = 0; //Timer Clock Source Select bit, 0 = Internal peripheral clock
TMR1 = 0;
IFS0bits.T1IF = 0; //Clear flags interrupt
IEC0bits.T1IE = 1; //Enable interrupt timer1
ANSELA = 0;
ANSELB = 0;
TRISBbits.TRISB7 = 0; //Output
LATBbits.LATB7 = 0;
while (1) {
asm("nop");
}
return 0;
}
void __ISR(_TIMER_1_VECTOR, IPL2SOFT) Timer1Handler(void){
IFS0bits.T1IF = 0; //Clear flag
LATBbits.LATB7 = LATBbits.LATB7 ^ 1; //Toogle output
}