I am trying to get my LED to blink. I have been learning to use the pic microcontrollers. I am trying to use c language. I am using the xc8 compiler. The program builds successfully, I select the programmer (Pic2 Kit), program the chip, and release it.
The LED stays unlit for 10 seconds and then turns on. It is suppose to blink! can anyone see any errors or improper setup, coding, etc? Please help.
Code:
#include <xc.h>
__CONFIG(MCLRE_OFF & CP_OFF & WDTE_OFF & OSC_IntRC);
//Master clear off, code protection off, watch dog timer off
#define _XTAL_FREQ 4000000 // 4 Mhz
//To reference speed with __delay_ms() or __delay_us()
void main(){
TRIS = 0b111101; //set GP1 as an OUTPUT
for(;;){ //loop forever
GPIO = 0b000010; // GP1 HIGH
__delay_ms(500); // 1/2 s delay
GPIO = 0b000000; // GP1 LOW
__delay_ms(500); // 1/2 s delay
}
}
__CONFIG(MCLRE_OFF & CP_OFF & WDTE_OFF & OSC_IntRC);
//Master clear off, code protection off, watch dog timer off
#define _XTAL_FREQ 4000000 // 4 Mhz
//To reference speed with __delay_ms() or __delay_us()
void main(){ // you have to specify which port to be out put eg: port A: TRISA = 0b11110111;
TRIS = 0b11110111; //set GP1 as an OUTPUT
for(;{ //loop forever // and here PORTA = 0b00001000; and 0b00001000 is for 8 bit processors
PORTA = 0b000010; // GP1 HIGH
__delay_ms(500); // 1/2 s delay
PORTA = 0b000000; // GP1 LOW
__delay_ms(500); // 1/2 s delay
}
}
magvi is absolutely correct--you need to specify which tris you're setting, whether it be TRISA, TRISB, TRISC, etc. You can't just say "TRIS=xxxxxxxx". The processor won't know which tris to set.
Try this:
Code:
//Master clear off, code protection off, watch dog timer off
#define _XTAL_FREQ 4000000 // 4 Mhz
//To reference speed with __delay_ms() or __delay_us()
void main(){
TRISA = 0b00000000; //set PORTA as an OUTPUT
for(;;){ //loop forever
PORTA = 0b00000010; // PORTA HIGH
__delay_ms(500); // 1/2 s delay
PORTA = 0b00000000; // PORTA LOW
__delay_ms(500); // 1/2 s delay
}
}
P.S. I noticed you're only mentioning 6 bits (i.e. 0b000010). Each port has 8 bits, not 6.
DerStrom8 and magvi. Neither suggestion has worked. I am using a Pic12F508 which from what I have read so far has only one TRIS and is accessed just like this. Do higher processors have more TRIS registers? The pic12F508 has 6 bits to work with.
I think that's only for assembly lang. the prgram finally works now. i'm had to switch from the xc.h compiler to the hi-tec compiler. can't believe it was the compiler the whole time. was up till 4 am last night pulling my hair out.
I think that's only for assembly lang. the prgram finally works now. i'm had to switch from the xc.h compiler to the hi-tec compiler. can't believe it was the compiler the whole time. was up till 4 am last night pulling my hair out.