dspic33f code review

Thread Starter


Joined Oct 12, 2016
I am trying to use the timer 1 module in the dsPIC33FJ12MC202 to toggle the status of a led connected to RB0.
IDE: Microchip MpLab.
Configuration: internal fast RC oscillator ; Watchdog timer off...
The code run just fine on proteus simulator, but it wont work when writing the code to the physical chip.
Note that the i successfully run another code on the dspic, but no timer module were involved.
I need you to check the code for me for any mistake.
This is my code:
// DSPIC33FJ12MC202 Configuration Bit Settings

// 'C' source line config statements

// FBS
#pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_FLASH // Boot Segment Program Flash Code Protection (No Boot program Flash segment)

// FGS
#pragma config GWRP = OFF // General Code Segment Write Protect (User program memory is not write-protected)
#pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected)

#pragma config FNOSC = FRC // Oscillator Mode (Internal Fast RC (FRC))
#pragma config IESO = OFF // Internal External Switch Over Mode (Start-up device with user-selected oscillator source)

#pragma config POSCMD = NONE // Primary Oscillator Source (Primary Oscillator Disabled)
#pragma config OSCIOFNC = OFF // OSC2 Pin Function (OSC2 pin has clock out function)
#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow Only One Re-configuration)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Both Clock Switching and Fail-Safe Clock Monitor are disabled)

#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config WDTPRE = PR128 // WDT Prescaler (1:128)
#pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog timer enabled/disabled by user software)

#pragma config FPWRT = PWR1 // POR Timer Value (Disabled)
#pragma config ALTI2C = OFF // Alternate I2C pins (I2C mapped to SDA1/SCL1 pins)
#pragma config LPOL = ON // Motor Control PWM Low Side Polarity bit (PWM module low side output pins have active-high output polarity)
#pragma config HPOL = ON // Motor Control PWM High Side Polarity bit (PWM module high side output pins have active-high output polarity)
#pragma config PWMPIN = ON // Motor Control PWM Module Pin Mode bit (PWM module pins controlled by PORT register at device Reset)

#pragma config ICS = PGD1 // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is Disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

unsigned char portValue=0;

void __attribute__((interrupt,no_auto_psv)) _T1Interrupt(void) {
LATBbits.LATB0 = ~LATBbits.LATB0;

int main(void) {

TRISBbits.TRISB0 = 0;
TRISBbits.TRISB12 = 0;
TRISBbits.TRISB13 = 0;

LATBbits.LATB12 = 1;
LATBbits.LATB13 = 1;

T1CONbits.TON = 0;
IEC0bits.T1IE = 1;
IPC0bits.T1IP = 1;
// SRbits.IPL = 7;
T1CONbits.TCS = 0;
T1CONbits.TCKPS = 2;


while (1){


return 0;