Charlieplexing asm code

Discussion in 'Embedded Systems and Microcontrollers' started by pontoma, Apr 26, 2013.

  1. pontoma

    Thread Starter New Member

    Apr 23, 2013
    2
    0
    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?
     
  2. TheComet

    Member

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

    Code ( (Unknown Language)):
    1. goto led2
    2.  
    3. ; -- SNIP --
    4.  
    5. led2: <-- Note the colon
    Same goes with subroutines:

    Code ( (Unknown Language)):
    1. call delay
    2.  
    3. ; -- SNIP --
    4.  
    5. delay: <-- Note the colon
    6.  
    7. ret
    TheComet
     
  3. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    764
    Colon

    I have never used a colon for labels.

    Rarely I find colons in other people's code.
     
  4. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    764
    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: Apr 26, 2013
  5. TheComet

    Member

    Mar 11, 2013
    88
    12
    That's strange, I could have sworn that was the problem.
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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:
    Code ( (Unknown Language)):
    1. main: incf foo, f
    2.       goto main
     
    atferrari likes this.
Loading...