Hey there,
I have a question about PIC programming in Microchip C18:
Why is it that this block of code does nothing:
While this block of code makes the output pulse on and off:
I have set up the PIC to run at 8 MHz CPU Frequency (8 MHz clock / 4 with 4x PLL), with all PORTC pins as outputs. Watchdog timer is off.
As far as I can see, both these loops are equivalent, as the first one will toggle on between 0 and 1, causing the output to flash, and the second one hard-codes the flashing.
If I simulate in MPLAB X, both code samples seem to work! The PIC is a PIC18F14K22, programmer is USBPICProg, which is able to write the program to the PIC and read it back to me correctly. I have a 0.1uF cap between Vdd and Vss, and I have MCLR set at 3.3V (despite me using it as a standard input pin).
Any ideas? :S
I have a question about PIC programming in Microchip C18:
Why is it that this block of code does nothing:
Code:
#pragma config FOSC = IRC
#pragma config PLLEN = ON
#pragma config WDTEN = OFF
#pragma config MCLRE = OFF
void main(void)
{
char on = 0;
OSCTUNE = 0b11000000;
OSCCON = 0b01100000;
TRISA = 0b00001010;
TRISB = 0;
TRISC = 0;
while(1)
{
LATCbits.LATC0 = on;
on = ( on == 1 ? 0 : 1 );
Delay10KTCYx(100);
}
return;
}
While this block of code makes the output pulse on and off:
Code:
#pragma config FOSC = IRC
#pragma config PLLEN = ON
#pragma config WDTEN = OFF
#pragma config MCLRE = OFF
void main(void)
{
OSCTUNE = 0b11000000;
OSCCON = 0b01100000;
TRISA = 0b00001010;
TRISB = 0;
TRISC = 0;
while(1)
{
LATCbits.LATC0 = 0x00;
Delay10KTCYx(100);
LATCbits.LATC0 = 0x01;
Delay10KTCYx(100);
}
return;
}
I have set up the PIC to run at 8 MHz CPU Frequency (8 MHz clock / 4 with 4x PLL), with all PORTC pins as outputs. Watchdog timer is off.
As far as I can see, both these loops are equivalent, as the first one will toggle on between 0 and 1, causing the output to flash, and the second one hard-codes the flashing.
If I simulate in MPLAB X, both code samples seem to work! The PIC is a PIC18F14K22, programmer is USBPICProg, which is able to write the program to the PIC and read it back to me correctly. I have a 0.1uF cap between Vdd and Vss, and I have MCLR set at 3.3V (despite me using it as a standard input pin).
Any ideas? :S