MPLAB XC who has tried it.

Status
Not open for further replies.
I just downloaded it and tried it this past weekend (version 1.51) and ran into a show stopping bug which made me go back to version 8.xx.

Trying to compile for a 16f720 and no matter what I put in the OSCCON.IRCF field, it will not change the frequency. Always stuck at the default. Same exact code works fine using MPLab 8.xx and Hi-Tech compiler.

Also, the IPE app is detecting the 16f720 as device ID 0x1c00 (which is correct) but claiming it should be 0x1c40.

Lost my faith.
 
//Following code for 12 led chaser with comet tail followed led fading effect.
//errors are:-
//1.Timer 1 & 2 settings
//2.internal oscillator
//3.analog inputs and comparators
//request correction pls.





#define _16F628A_SETTING

#include <xc.h>

// Define a rotate speed - set higher for slower rotate
#define ROTATE_SPEED 1023

#ifdef _16F628A_SETTING
#pragma config FOSC = INTOSCIO // or INTOSCCLK Internal RC Oscillator
#pragma config WDTE = OFF // Turn watchdog off
#pragma config BOREN = OFF
#endif

#ifdef _16F628A_SETTING
// Define which pin each LED is on
#define LED1 PORTAbits.RA0
#define LED2 PORTAbits.RA1
#define LED3 PORTAbits.RA2
#define LED4 PORTAbits.RA3
#define LED5 PORTBbits.RB0
#define LED6 PORTBbits.RB1
#define LED7 PORTBbits.RB2
#define LED8 PORTBbits.RB3
#define LED9 PORTBbits.RB4
#define LED10 PORTBbits.RB5
#define LED11 PORTBbits.RB6
#define LED12 PORTBbits.RB7

#endif

// Function definitions
void init(void);

// Global variables
unsigned int rot = 0;
unsigned char i = 0;
// Set on/off times for each LED in the "comet", for head to tail
unsigned char a = 0;
unsigned char b = 0;
unsigned char c = 0;
unsigned char d = 2;
unsigned char e = 5;
unsigned char f = 15;
unsigned char g = 25;
unsigned char h = 50;
unsigned char j = 100;
unsigned char k = 150;
unsigned char l = 175;
unsigned char m = 240;
unsigned char n = 0;


int main(int argc, char** argv) {

init();

while(1)
{

// Reset PWM variable
if(i == 255) i = 1;

// Rotate LEDs after desired period and reset rotate variable
if(rot > ROTATE_SPEED)
{
n = m;
m = l;
l = k;
k = j;
j = h;
h = g;
g = f;
f = e;
e = d;
d = c;
c = b;
b = a;
a = n;
rot=0;
}
}
}


// Interrupt Service Routine (keyword "interrupt" tells the compiler it's an ISR)
void interrupt int_routine(void)
{
// Check it's the timer that has interrupted
if (PIE1bits.TMR2IE && PIR1bits.TMR2IF)
{
PIR1bits.TMR2IF = 0; // Clear interrupt flag

// Toggle LEDs if their interval has elapsed
(i < a) ? LED1=1 : LED1=0;
(i < b) ? LED2=1 : LED2=0;
(i < c) ? LED3=1 : LED3=0;
(i < d) ? LED4=1 : LED4=0;
(i < e) ? LED5=1 : LED5=0;
(i < f) ? LED6=1 : LED6=0;
(i < g) ? LED7=1 : LED7=0;
(i < h) ? LED8=1 : LED8=0;
(i < j) ? LED9=1 : LED9=0;
(i < k) ? LED10=1 : LED10=0;
(i < l) ? LED11=1 : LED11=0;
(i < m) ? LED12=1 : LED12=0;

// Increment PWM and rotate variables
i++;
rot++;
}

// process other interrupt sources here, if required

}

// Set up various things - I/Os, interrupts, etc
void init(void)
{

#ifdef _16F628A_SETTING
// Set internal oscillator to 8MHz
PCON = 0x08;
// Turn analog inputs off
CMCON=0x07;
// Set all pins to outputs
TRISA = 0;
TRISB = 0;

#endif

// Use Timer 2 for PWM timing
T2CON = 0b00000000;
TMR2 = 0x00;
PR2 = 0x7F; // Timer 2 period register
T2CONbits.TMR2ON = 1;

// Setup interrupt for Timer 2
INTCONbits.GIE = 1; // Interrupts on
INTCONbits.PEIE = 1; // Peripheral interrupts on
PIE1bits.TMR2IE = 1; // Timer 2 interrupt enable
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…