Unable to Program the simplest function on PIC12f509

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Posts: 8
Joined: Fri Jul 15, 2016 1:21 am

Re: Unable to Program the simplest function on PIC12f509

Post by c_mario » Sat Jul 23, 2016 12:04 am

Ok, now I got it to work. There were several reasons for this.
1. I have not touched assembly for probably 30 years.
2. I have never used MPLAB
3. I did not realise that the assembler expected code to be organised in columns.
4. The configuration bits don't seem to go to programmer correctly and are reversed, i.e. tick mark sets the bit low not high in the programmer.
5. My initial question was about C code so had to start again.
Perhaps a "tiny" difficult to the experienced, but extremely frustrating.
and Sybase is owned by Oracle

The code below blinks the led on GP2 and sets GP0 high when GP3 is set high.
#include <p12f509.inc>
__config _MCLRE_OFF & _WDT_OFF & _CP_OFF & _IntRC_OSC
GPIO equ 6
d1 equ 0x7
d2 equ 0x8
d3 equ 0x9

; Starting Point
org 0 ;set program origin
movwf OSCCAL
movlw b'001000'
tris GPIO ;all GP pins escept GP3 set to output
movlw b'00000111' ;sets up TMR0 to count
option ;internally prescaled by 256
movlw b'0'
movfw GPIO ; clear all GPIO pins
Goto main
; Delay timing
movlw d'1' ; sets up marker
movwf d1 ;

movlw d'1' ; sets up first postscaler
movwf d2 ;

movlw d'4' ; sets up five second counter
movwf d3 ;

decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto delay_0
goto $+1
retlw 0

btfsc GPIO,3
bsf GPIO,0
btfss GPIO,3
bcf GPIO,0
movlw b'0000100' ;toggle GP1
xorwf GPIO
call delay
goto main

Perhaps now I can get on with my real project.
Thanks for your input.

User avatar
Support Volunteer
Posts: 5734
Joined: Sun May 01, 2005 11:20 am
Location: St. Leonards-on-Sea, E. Sussex, UK.

Re: Unable to Program the simplest function on PIC12f509

Post by leon_heller » Sat Jul 23, 2016 8:04 am

Use the Code button to preserve the code formatting.
Leon Heller

Post Reply