Charlieplexing asm code

Thread Starter

pontoma

Joined Apr 23, 2013
2
Hi I am trying to charlieplex 8 LEDS using the PIC12F609. I am using them to create something like a stop light sort of example.
In my program I have written a function that will turn on each LED. I have never used .asm before and have run into a lot of problems. I am having the biggest problem getting the program to go to the next LED and so on.
Here is my code:

; PIC12F609 Project
list p=12F609
#include <p12F609.inc>
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTOSCIO & _IOSCFS_4MHZ
UDATA
dc1 RES 1
dc2 RES 1
dc3 RES 1
RESET CODE 0x000
led1
banksel GPIO;
movlw b'000001'
movwf GPIO;
banksel TRISIO;
movlw b'000100';
movwf TRISIO;
call delay
goto led2

led2
banksel GPIO;
movlw b'000010'
movwf GPIO;
banksel TRISIO;
movlw b'000100';
movwf TRISIO;
call delay
call delay
goto (next led and so on)

led3
banksel GPIO;
movlw b'000001'
movwf GPIO;
banksel TRISIO;
movlw b'000010';
movwf TRISIO;

led4
banksel GPIO;
movlw b'000010'
movwf GPIO;
banksel TRISIO;
movlw b'000001';
movwf TRISIO;

led5
banksel GPIO;
movlw b'000100'
movwf GPIO;
banksel TRISIO;
movlw b'000001';
movwf TRISIO;

led6
banksel GPIO;
movlw b'000100'
movwf GPIO;
banksel TRISIO;
movlw b'000010';
movwf TRISIO;

led7
banksel GPIO;
movlw b'010000'
movwf GPIO;
banksel TRISIO;
movlw b'000010';
movwf TRISIO;

led8
banksel GPIO;
movlw b'100000'
movwf GPIO;
banksel TRISIO;
movlw b'000010';
movwf TRISIO;

delay
movlw .50
movwf dc1
outerloop
movlw .100
movwf dc2
middleloop
movlw .250
movwf dc3
innerloop
nop
decfsz dc3,f
goto innerloop
decfsz dc2,f
goto middleloop
decfsz dc1,f
goto outerloop
return;
END

Does goto not work as simple as I thought it would?
 

TheComet

Joined Mar 11, 2013
88
Labels in asm generally have a colon after it.

Rich (BB code):
goto led2

; -- SNIP --

led2: <-- Note the colon
Same goes with subroutines:

Rich (BB code):
call delay

; -- SNIP --

delay: <-- Note the colon

ret
TheComet
 

atferrari

Joined Jan 6, 2004
4,764
Labels in asm generally have a colon after it.

Rich (BB code):
goto led2

; -- SNIP --

led2: <-- Note the colon
Same goes with subroutines:

Rich (BB code):
call delay

; -- SNIP --

delay: <-- Note the colon

ret
TheComet
Colon

I have never used a colon for labels.

Rarely I find colons in other people's code.
 

atferrari

Joined Jan 6, 2004
4,764
Hi I am trying to charlieplex 8 LEDS using the PIC12F609. I am using them to create something like a stop light sort of example.
In my program I have written a function that will turn on each LED.

Does goto not work as simple as I thought it would?
Could you add comments to code? Even better, a brief explanation (preceding it) with what you expect the code to do?

If you learn how to use the simulator, the time you spend there would help in debugging.

Divide and conquer; test small pieces, as small as necessary and add later.
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
There's no need for a colon, but some people like to put a label and then an instruction on the same line which is the main purpose of the colon in assembler, eg:
Rich (BB code):
main: incf foo, f
      goto main
 
Top