It's my first post here and I'm just starting out with MCUs. I managed to get an LED to blink (yay!), however, at an uneven rate when it's programmed for an even one. I've tried everything that came to mind without success. It's a bit frustrating...
I'm running:
MPLAB X v1.51
XC 8 v 1.12 Compiler
PicKit 2 v2.61 IPE with support for:
PicCircuit ICP02v2 Programmer
PIC 16f1847
My code:
Code:
#include <pic16f1847.h>
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
//Internal clock setting (OSC of 32Mhz/4)
#define _XTAL_FREQ 800000
void main ()
{
TRISA = 0x00; //PORTA as an output
while (1) //infinite loop
{
PORTA = 0x0f; //PORTA high
__delay_ms(1000);
PORTA = 0x00; //PORTA low
__delay_ms(1000);
}
}
As I mentioned, this does work but poorly:
The LED seems to be on for 3/4 of the loop, off for 1/4 and I have no idea why when both delays are set for 1000ms.
Can anyone help me out?
Well done, its always great to see things start for the first time.
Cannot help with the C code detail, but most of the Ports default to Analogue Inputs at power on, suggest you turn then to Digital before making them Outputs using ANSEL
LATA = 0x00;
ANSELA = 0x00; //Turning analog ?input? function off; now digital I/O
TRISA = 0x00; //Setting PORTA as output
I don't really understand assembly very well but what I could tell from the that example and the datasheet, setting ANSELA low would set my port for digital input. The datasheet also says that ANSELA only affects inputs but can prevent abnormal behavior when setting pin states. Why would I worry about inputs? Thanks for your help.
I don't know if this is important. But the below link says to even include PORTA = 0x00; command. I have not programmed a PIC anytime, but you could try after adding that.
Success! It was the configuration that I was missing. By trial and error, disabling the watchdog timer fixed it (I'm not sure why). I had a config earlier but removing it made no difference so I left it out.
Thank you for your help everyone!