Hi all,
I am very new to microcontrollers but am very excited to learn the fundamentals of them. I have purchased a PICkit1 for just this reason.
I have tried to create a simple blinking LED using a PIC16F684 and PICkit 1 development board from Microchip. However, all I am getting is constant LED luminance and it does not seem to be pulsing at all.
I have created it in c using the HI-TECH C Compilier.
Does anyone see any problems in my few lines of code here? Basically have a 2ms delay nested inside a for-loop for 128 repetitions. This should give me approximately 4Hz on the output.
#include <htc.h>
#define _XTAL_FREQ 4000000 // define oscillator freq = 4Mz
void main(void){
int x;
TRISC2 = 0; //set RC2 as output
PORTC = 0; // initialize PORTC low
while(1){
if (PORTC==0){
PORTC = 4; //set RC2 high
}
else{
PORTC = 0; //set RC2 low
}
for(x = 0; x<=127; x++){
__delay_ms(2); //delay 2ms
CLRWDT();
}
}
}
All help and suggestions is appreciated.
Thanks.
I am very new to microcontrollers but am very excited to learn the fundamentals of them. I have purchased a PICkit1 for just this reason.
I have tried to create a simple blinking LED using a PIC16F684 and PICkit 1 development board from Microchip. However, all I am getting is constant LED luminance and it does not seem to be pulsing at all.
I have created it in c using the HI-TECH C Compilier.
Does anyone see any problems in my few lines of code here? Basically have a 2ms delay nested inside a for-loop for 128 repetitions. This should give me approximately 4Hz on the output.
#include <htc.h>
#define _XTAL_FREQ 4000000 // define oscillator freq = 4Mz
void main(void){
int x;
TRISC2 = 0; //set RC2 as output
PORTC = 0; // initialize PORTC low
while(1){
if (PORTC==0){
PORTC = 4; //set RC2 high
}
else{
PORTC = 0; //set RC2 low
}
for(x = 0; x<=127; x++){
__delay_ms(2); //delay 2ms
CLRWDT();
}
}
}
All help and suggestions is appreciated.
Thanks.