Menu

Errant code (again)

Help
2009-12-02
2013-05-30
  • Alistair George

    Alistair George - 2009-12-02

    Hello. 3 ports on a PIC10F drive a led matrix, allowing up to six LED off the 3 ports. Unfortunately, its not playing ball. For example, when the code calls LED0, GP1 & GP2 should both go high - they dont, and similar for the other ports, but some go high, and others dont.
    GCBasic version 0.9
    <pre><code>
    'This program flashes an LED matrix on GPIO.0/1/2 using GCBasic function PulseOut
    #chip 10f200,1
    #config _WDT_OFF & _CP_OFF & _MCLRE_OFF
    #define led0 GPIO=b'0110'
    #define led1 GPIO=b'0001'
    #define led2 GPIO=b'0100'
    #define led3 GPIO=b'0010'
    #define ledclr GPIO=b'0000'
    movlw   b'00001000'
    movwf   GPIO       
    movlw   b'00001000'
    TRIS GPIO
    asm MOVLW b'11001111' '
    asm option
    start:
    PulseOut led0, 1000 ms 'Turn LED on for 1 sec
    Wait 1000 ms 'Wait 1 sec with LED off
    PulseOut led1, 1000 ms 'Turn LED on for 1 sec
    wait 1000 ms
    PulseOut led2, 1000 ms 'Turn LED on for 1 sec
    wait 1000 ms
    PulseOut led3, 1000 ms 'Turn LED on for 1 sec
    wait 1000 ms
    goto start
    </code></pre>

     
  • Alistair George

    Alistair George - 2009-12-02

    <pre><code>
    sorry about the markup - its not playing ball either!
    </code></pre>

     
  • Alistair George

    Alistair George - 2009-12-02

    Everywhere there is a # it alters markup! eg #define comes out as large text 'define'

     
  • Frank

    Frank - 2009-12-02

    Hi alygeorge,

    PulseOut only works on a single pin. GCBasic is trying to interpret you're LED defines as a pin definition such as GPIO.0 or GPIO.1 and ends up using the B'00000110' parts as a bit number which is why you are seeing odd results on the leds.

    The code below might do what you want - the assembly looks ok to me but I haven't simulated it or tried it out on hardware. PulseOut is replaced with a macro that outputs you're bit patterns and then waits for a number of milliseconds before clearing the LEDs. You could make MatrixOut into a sub but it ends up being longer in assembly than using the macro or inline coding the whole loop.

        'This program flashes an LED matrix on GPIO.0/1/2 using macro MatrixOut
       
        #chip 10f200,1
        #config WDT=OFF, CP=OFF, MCLRE=OFF
       
       
        #define led0 b'0110'
        #define led1 b'0001'
        #define led2 b'0100'
        #define led3 b'0010'
        #define ledclr b'0000'
       
        GPIO=b'00001000'
       
        movlw b'00001000'
        TRIS GPIO
        'asm MOVLW b'11001111'
        'asm option ' Done by GCBasic in INITSYS
       
        start:
        MatrixOut led0, 1000 'Turn LED on for 1 sec
        Wait 1000 ms 'Wait 1 sec with LED off
        MatrixOut led1, 1000 'Turn LED on for 1 sec
        wait 1000 ms
        MatrixOut led2, 1000 'Turn LED on for 1 sec
        wait 1000 ms
        MatrixOut led3, 1000 'Turn LED on for 1 sec
        wait 1000 ms
        goto start
       
        macro MatrixOut(MatrixPattern,MatrixDelay)
        GPIO = MatrixPattern
        wait MatrixDelay ms
        GPIO = ledclr
        end macro

    I compiled this using the latest GCBasic update from 29/11/09 so if you are really using 0.9 it may not work.

    Frank

     
  • Alistair George

    Alistair George - 2009-12-02

    Thank you kindly Frank. BTW where can I get the later version of GCB as the latest on sourceforge is my current unstable 0.9 date 15/11

     
  • Hugh Considine

    Hugh Considine - 2009-12-02

    Latest version is always linked to from .

      : http://gcbasic.sourceforge.net/update.html

     
  • Alistair George

    Alistair George - 2009-12-02

    Thanks so much works perfectly Id made a error on led3 which should be #define led3 b'0011'
    Best wishes,
    Alistair.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.