HOWTO Get a PIC10F206 Alive
When you want to dive in and start bit twiddling on a microcontroller, you need to know what infrastructure code has to exist before you implement your idea. If you haven't written for the device before, it's off to Google you go to hopefully find someone example code you can strip down to the bare essentials. Maybe I'm the guy that Google found. Hope this helps.
Here's the code I used just to show that the PIC10F206 I'd soldered wasn't bricked. I connected an LED to GP2 and simply wanted it to light up, as a kind of "Hello World!". The resistor is 330R.
The picture shows the breadboard, using a clone PICKit 2 to provide power and programming via ICSP. Pin 1 is on the right of the header at the top.
Here's the code. The Microchip Datasheet and programming guides are pretty essential reads. Make sure you don't do a full erase or you'll lose the oscillator calibration at 0x1FF.
#include <P10F206.INC>
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
; The reset vector is 0x1ff which is preprogrammed
; to load W with the value to calibrate the oscillator.
; First job is to move this value into OSCCAL
CODE 0x00
MOVWF OSCCAL ; Put val into OSCCAL
BCF OSCCAL,FOSC4 ; Turn osc output off on GP2
; 7:Wake up off
; 6:Pull ups off
; 5:Timer0 on clock
; 4:Timer0 L2H
; 3;Prescale Timer0
; 210:Prescale by 256
MOVLW B'11000111'
OPTION
MOVLW B'00000001' ; Comparator off
MOVWF CMCON0
CLRF GPIO ; Clear IO latches
MOVLW B'00001011' ; GP2 only is OUTPUT
TRIS GPIO
BSF GPIO,GP2 ; Set GP2 to 1
END ; Hello world?
- Login to post comments
