The PICKit arrived and I started experimenting with a few PIC16F72 on a breadboard, starting with a LED blinker.
Here is the code:
config.h
#ifndef CONFIG_H
#define CONFIG_H
#define _XTAL_FREQ 16000000 // 16MHz crystal oscillator used
#include <pic.h>
#include <xc.h>
#ifdef MAIN_FILE
// Configuration bits
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config CP = OFF // FLASH Program Memory Code Protection bit (Code protection off)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#endif
#endif /* CONFIG_H */
main.c
#define MAIN_FILE
#include "config.h"
void main(void)
{
// Make the LED light up.
TRISA &= ~0x1;
while (1)
{
PORTA |= 0x1;
__delay_ms(500);
PORTA &= ~0x1;
__delay_ms(500);
}
}
I have a 16MHz crystal across pins 9 and 10, power at appropriate pins with a 220nF bypass, and a LED with MOSFET low side switch at pin 2.
The blinking is erratic and I am confused at what is going on. 16F72 does not support debugging with PICKit (D'oh!) so pointers please?
EDIT: Solved. Two culprits: the pin I used was an analog pin which have to be configured into a digital output first, and I left the RESET pin flapping in the wind.