Hi I am have this code written for PIC32MX795F512L. It does not work. Any idea?
Config Bits
// PIC32MX795F512L Configuration Bit Settings
// 'C' source line config statements
// DEVCFG3
// USERID = No Setting
#pragma config FSRSSEL = PRIORITY_7 // SRS Select (SRS Priority 7)
#pragma config FMIIEN = ON // Ethernet RMII/MII Enable (MII Enabled)
#pragma config FETHIO = ON // Ethernet I/O Pin Select (Default Ethernet I/O)
#pragma config FCANIO = ON // CAN I/O Pin Select (Default CAN I/O)
#pragma config FUSBIDIO = ON // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = ON // USB VBUS ON Selection (Controlled by USB Module)
// DEVCFG2
#pragma config FPLLIDIV = DIV_12 // PLL Input Divider (12x Divider)
#pragma config FPLLMUL = MUL_24 // PLL Multiplier (24x Multiplier)
#pragma config UPLLIDIV = DIV_12 // USB PLL Input Divider (12x Divider)
#pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_256 // System PLL Output Clock Divider (PLL Divide by 256)
// DEVCFG1
#pragma config FNOSC = FRCDIV // Oscillator Selection Bits (Fast RC Osc w/Div-by-N (FRCDIV))
#pragma config FSOSCEN = ON // Secondary Oscillator Enable (Enabled)
#pragma config IESO = ON // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_8 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/8)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
// DEVCFG0
#pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2)
#pragma config PWP = OFF // Program Flash Write Protect (Disable)
#pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <p32xxxx.h> // Include PIC32 specifics header file
#include <xc.h> // Include the PIC32 Peripheral Library
#include <stdlib.h>
#include <sys/attribs.h>
//#include <int.h>
// Defines
#define SYSCLK 40000000L // System Clock Frequency
void __attribute__( (interrupt(ipl4srs),
vector(
)) Timer2Handler ( void );
void Timer2Handler(void)
{
LATBINV = 0X20;
IFS0CLR = 0x0200;
/* ISR code inserted here */
// clear Timer2 int flag, IFS0<9>
}
main (void){
asm("ei");
INTCONbits.MVEC=1;
AD1PCFG = 0XFFFF;
TRISBbits.TRISB5 = 0; // Set RB5 as digital output
LATB = 0x20;
T2CON = 0;
PR2 = 65535;
TMR2=0;
T2CON = 0X8070;
IEC0<9>=0; // disable Timer2 int, IEC0<9>
IFS0<9>=0; // clear Timer2 int flag, IFS0<9>
IPC2CLR = 0x001f; // clear Timer2 priority/subpriority fields IPC2<4:0>
//IPC2 = 0x0010; // set Timer2 int priority = 4, IPC2<4:2>
IPC2bits.T2IP=4; //Priority 2
//IEC0<9>=1; // enable Timer2 int, IEC0<9>
IEC0bits.T2IE=1; //Enable interrup
IFS0bits.T2IF=0; //Clear the flag
// Now we just wait in an infinite loop while interrupts do their thing!
__asm__ volatile ("ei");
while(1){
//LATAINV = 0X20;
__asm__ volatile ("nop");
}
}