Menu

array problem

Help
2013-09-07
2015-06-26
  • Bob Knipper

    Bob Knipper - 2013-09-07

    I used variables instead of the array 'time' at first and compiled OK. When I changed to the array the compiler doesn't error but no code is created. Any ideas why?

    ;Chip Settings

    chip 16F628A,4

    config BOREN=OFF, CP=OFF, PWRTE=ON, WDT=OFF, LVP=OFF, MCLRE=OFF, OSC=INTOSC_OSC_NOCLKOUT

    ;Variables
    Dim dsu As byte
    Dim dst As byte
    Dim dmu As byte
    Dim dmt As byte
    Dim dhu As byte
    Dim dht As byte
    Dim t1low As byte
    Dim t1hi As byte
    Dim hsec As byte
    Dim offset As byte
    Dim time(6)
    Dim timebu(6)

    ;Interrupt Handlers
    On Interrupt Timer1Overflow Call TickIrq

    EPRead 0, offset
    t1con = b'110000'
    t1hi = 11
    t1low = 221 + offset
    tmr1h = t1hi
    tmr1l = t1low
    tmr1on = 1
    tmr1ie = 1
    loop:
    display:

    'Display
    dsu = time(1) # b'00101111'
    dst = time(2) # b'00010111'
    dmu = time(3) # b'00011111'
    dmt = time(4) # b'00001111'
    dhu = time(5) # b'00011111'
    dht = time(6) # b'00000111'
    Goto loop

    Sub TickIrq
    tmr1on = 0
    tmr1h = t1hi
    tmr1l = t1low
    tmr1on = 1
    hsec = hsec + 1
    If hsec Xor b'0000001' = 0 Then
    Goto exitsub
    End If
    sutick:
    If portb.0 = 0 Then
    time(1) = 0
    time(2) = 0
    Goto hutick
    End If
    If portb.2 = 0 Then
    time(1) = 0
    Goto mutick
    End If
    If time(1) < 9 Then
    time(1) = time(1) + 1
    Goto exitsub
    End If
    time(1) = 0
    sttick:
    If time(2) < 5 Then
    time(2) = time(2 )+ 1
    Goto exitsub
    End If
    time(2) = 0
    mutick:
    If time(3) < 17 Then
    If time(3) = 7 Then
    time(3) = time(3) + 9
    Else
    time(3) = time(3) + 1
    End If
    Goto exitsub
    End If
    time(3) = 0
    mttick:
    If time(4) < 9 Then
    If time(4) = 3 Then
    time(4) = time(4) + 5
    Else
    time(4) = time(4)t + 1
    End If
    Goto exitsub
    End If
    time(4) = 0
    hutick:
    If time(5) < 17 Then
    If time(5) # b'11111110' = 1 Then
    time(5) = time(5) + 3
    Else
    time(5) = time(5) + 1
    End If
    Goto exitsub
    End If
    time(5) = 0
    httick:
    If time (6) < 4 Then
    time(6) = time(6) + 2
    Goto exitsub
    End If
    time(6) = 0
    exitsub:
    Exit Sub
    End Sub

    Sub delay
    Wait 10 ms
    Exit Sub
    End Sub

     
  • kent_twt4

    kent_twt4 - 2013-09-07

    Could be GCBasic syntax for comments? GCBasic uses ' and ; not #

    EDIT: Or just explain what you are trying to do with the array variable? define as constant and pass on to dxx?

     

    Last edit: kent_twt4 2013-09-07
  • Bob Knipper

    Bob Knipper - 2013-09-07

    This is the code that works, variables su,st,mu,mt,hu,ht are time , su= seconds units, st= seconds tens, etc. Work in progress for a binary clock. Wanted to use array so I could use a for/next to store time data in timebu array while I use disply routine to display other data. dsu, etc. are just for debugging the code and won't be in final code. # is same as xor. Hope this makes it more clear what I am trying to do..Bob

    ;Chip Settings

    chip 16F628A,4

    config BOREN=OFF, CP=OFF, PWRTE=ON, WDT=OFF, LVP=OFF, MCLRE=OFF, OSC=INTOSC_OSC_NOCLKOUT

    ;Variables
    Dim su As byte
    Dim st As byte
    Dim mu As byte
    Dim mt As byte
    Dim hu As byte
    Dim ht As byte
    Dim dsu As byte
    Dim dst As byte
    Dim dmu As byte
    Dim dmt As byte
    Dim dhu As byte
    Dim dht As byte
    Dim t1low As byte
    Dim t1hi As byte
    Dim hsec As byte
    Dim offset As byte

    ;Interrupt Handlers
    On Interrupt Timer1Overflow Call TickIrq

    EPRead 0, offset
    t1con = b'110000'
    t1hi = 11
    t1low = 226 + offset
    tmr1h = t1hi
    tmr1l = t1low
    tmr1on = 1
    tmr1ie = 1
    loop:
    display:

    'Display
    dsu = su # b'00101111'
    dst = st # b'00010111'
    dmu = mu # b'00011111'
    dmt = mt # b'00001111'
    dhu = hu # b'00011111'
    dht = ht # b'00000111'
    Goto loop

    Sub TickIrq
    tmr1on = 0
    tmr1h = t1hi
    tmr1l = t1low
    tmr1on = 1
    hsec = hsec + 1
    If hsec # b'0000001' = 0 Then
    Goto exitsub
    End If
    sutick:
    If portb.0 = 0 Then
    su = 0
    st = 0
    Goto hutick
    End If
    If portb.2 = 0 Then
    su = 0
    Goto mutick
    End If
    If su < 9 Then
    su = su + 1
    Goto exitsub
    End If
    su = 0
    sttick:
    If st < 5 Then
    st = st + 1
    Goto exitsub
    End If
    st = 0
    mutick:
    If mu < 17 Then
    If mu = 7 Then
    mu = mu + 9
    Else
    mu = mu + 1
    End If
    Goto exitsub
    End If
    mu = 0
    mttick:
    If mt < 9 Then
    If mt = 3 Then
    mt = mt + 5
    Else
    mt = mt + 1
    End If
    Goto exitsub
    End If
    mt = 0
    hutick:
    If hu < 17 Then
    If hu # b'11111110' = 1 Then
    hu = hu + 3
    Else
    hu = hu + 1
    End If
    Goto exitsub
    End If
    hu = 0
    httick:
    If ht < 4 Then
    ht = ht + 2
    Goto exitsub
    End If
    ht = 0
    exitsub:
    Exit Sub
    End Sub

    Sub delay
    Wait 10 ms
    Exit Sub
    End Sub

    Assembler code generated::::

    ;Program compiled by Great Cow BASIC (0.9 21/4/2013)
    ;Need help? See the GCBASIC forums at http://sourceforge.net/projects/gcbasic/forums,
    ;check the documentation or email w_cholmondeley at users dot sourceforge dot net.

    ;**************

    ;Set up the assembler options (Chip type, clock source, other bits and pieces)
    LIST p=16F628A, r=DEC

    include <P16F628A.inc>

    __CONFIG _INTOSC_OSC_NOCLKOUT & _MCLRE_OFF & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _CP_OFF & _BODEN_OFF

    ;**************

    ;Set aside memory locations for variables
    SysSTATUS EQU 127
    SysW EQU 126
    DHT EQU 32
    DHU EQU 33
    DMT EQU 34
    DMU EQU 35
    DST EQU 36
    DSU EQU 37
    HSEC EQU 38
    HT EQU 39
    HU EQU 40
    MT EQU 41
    MU EQU 42
    OFFSET EQU 43
    ST EQU 44
    SU EQU 45
    SavePCLATH EQU 46
    SaveSysTemp1 EQU 47
    SysIntOffCount EQU 48
    SysTemp1 EQU 49
    T1HI EQU 50
    T1LOW EQU 51

    ;**************

    ;Alias variables
    EEADDRESS EQU EEADR
    EEDATAVALUE EQU EEDATA

    ;**************

    ;Vectors
    ORG 0
    goto BASPROGRAMSTART
    ORG 4
    Interrupt

    ;**************

    ;Save Context
    movwf SysW
    swapf STATUS,W
    movwf SysSTATUS
    incf SysIntOffCount,F
    banksel STATUS
    ;Store system variables
    movf SysTemp1,W
    movwf SaveSysTemp1
    movf PCLATH,W
    movwf SavePCLATH
    clrf PCLATH
    ;On Interrupt handlers
    banksel PIE1
    btfss PIE1,TMR1IE
    goto NotTMR1IF
    banksel PIR1
    btfss PIR1,TMR1IF
    goto NotTMR1IF
    call TICKIRQ
    bcf PIR1,TMR1IF
    goto INTERRUPTDONE
    NotTMR1IF
    ;User Interrupt routine
    INTERRUPTDONE
    ;Restore Context
    ;Restore system variables
    banksel SAVESYSTEMP1
    movf SaveSysTemp1,W
    movwf SysTemp1
    movf SavePCLATH,W
    movwf PCLATH
    clrf SysIntOffCount
    swapf SysSTATUS,W
    movwf STATUS
    swapf SysW,F
    swapf SysW,W
    retfie

    ;**************

    ;Start of program memory page 0
    ORG 39
    BASPROGRAMSTART
    ;Call initialisation routines
    call INITSYS
    ;Enable interrupts
    bsf INTCON,GIE
    bsf INTCON,PEIE
    clrf SysIntOffCount
    ;Automatic pin direction setting
    banksel TRISB
    bsf TRISB,2
    bsf TRISB,0

    ;Start of the main program
    bsf PIE1,TMR1IE
    clrf EEADDRESS
    banksel STATUS
    call SYSEPREAD
    banksel EEDATAVALUE
    movf EEDATAVALUE,W
    banksel OFFSET
    movwf OFFSET
    movlw 48
    movwf T1CON
    movlw 11
    movwf T1HI
    movlw 226
    addwf OFFSET,W
    movwf T1LOW
    movf T1HI,W
    movwf TMR1H
    movf T1LOW,W
    movwf TMR1L
    bsf T1CON,TMR1ON
    banksel PIE1
    bsf PIE1,TMR1IE
    LOOP
    DISPLAY
    movlw 47
    banksel SU
    xorwf SU,W
    movwf DSU
    movlw 23
    xorwf ST,W
    movwf DST
    movlw 31
    xorwf MU,W
    movwf DMU
    movlw 15
    xorwf MT,W
    movwf DMT
    movlw 31
    xorwf HU,W
    movwf DHU
    movlw 7
    xorwf HT,W
    movwf DHT
    goto LOOP
    BASPROGRAMEND
    sleep
    goto BASPROGRAMEND

    ;**************

    INITSYS
    movlw 7
    movwf CMCON
    clrf PORTA
    clrf PORTB
    return

    ;**************

    SYSEPREAD
    bcf INTCON,GIE
    incf SysIntOffCount,F
    banksel EECON1
    bsf EECON1,RD
    banksel SYSINTOFFCOUNT
    movf SysIntOffCount,F
    btfss STATUS,Z
    decf SysIntOffCount,F
    btfsc STATUS,Z
    bsf INTCON,GIE
    return

    ;**************

    TICKIRQ
    bcf T1CON,TMR1ON
    movf T1HI,W
    movwf TMR1H
    movf T1LOW,W
    movwf TMR1L
    bsf T1CON,TMR1ON
    incf HSEC,F
    movf HSEC,W
    movwf SysTemp1
    btfsc SysTemp1,0
    goto EXITSUB
    SUTICK
    btfsc PORTB,0
    goto ENDIF2
    clrf SU
    clrf ST
    goto HUTICK
    ENDIF2
    btfsc PORTB,2
    goto ENDIF3
    clrf SU
    goto MUTICK
    ENDIF3
    movlw 9
    subwf SU,W
    btfsc STATUS, C
    goto ENDIF4
    incf SU,F
    goto EXITSUB
    ENDIF4
    clrf SU
    STTICK
    movlw 5
    subwf ST,W
    btfsc STATUS, C
    goto ENDIF5
    incf ST,F
    goto EXITSUB
    ENDIF5
    clrf ST
    MUTICK
    movlw 17
    subwf MU,W
    btfsc STATUS, C
    goto ENDIF6
    movlw 7
    subwf MU,W
    btfss STATUS, Z
    goto ELSE10_1
    movlw 9
    addwf MU,F
    goto ENDIF10
    ELSE10_1
    incf MU,F
    ENDIF10
    goto EXITSUB
    ENDIF6
    clrf MU
    MTTICK
    movlw 9
    subwf MT,W
    btfsc STATUS, C
    goto ENDIF7
    movlw 3
    subwf MT,W
    btfss STATUS, Z
    goto ELSE11_1
    movlw 5
    addwf MT,F
    goto ENDIF11
    ELSE11_1
    incf MT,F
    ENDIF11
    goto EXITSUB
    ENDIF7
    clrf MT
    HUTICK
    movlw 17
    subwf HU,W
    btfsc STATUS, C
    goto ENDIF8
    movf HU,W
    movwf SysTemp1
    btfss SysTemp1,0
    goto ELSE12_1
    movlw 3
    addwf HU,F
    goto ENDIF12
    ELSE12_1
    incf HU,F
    ENDIF12
    goto EXITSUB
    ENDIF8
    clrf HU
    HTTICK
    movlw 4
    subwf HT,W
    btfsc STATUS, C
    goto ENDIF9
    movlw 2
    addwf HT,F
    goto EXITSUB
    ENDIF9
    clrf HT
    EXITSUB
    return
    return

    ;**************

    END

     
  • kent_twt4

    kent_twt4 - 2013-09-07

    Here is the offending line in the array code, looks like a typo, it compiles when corrected.

    #time(4) = time(4)t + 1
    
     
  • Bob Knipper

    Bob Knipper - 2013-09-07

    Your right , typo. I should have caught it! Thanks. Threw me because it didn't cause a error. Just learning the ins and outs of GCB but I love it. Thanks again.>>>Bob

     
  • kent_twt4

    kent_twt4 - 2013-09-07

    I use Crimson editor, and an error definitely showed up in the output window as an out of bounds error of some sort, referring to a line number of the variables .h and/or a GCB init file. In any case, you are on your (GCBasic) way now :).

     
  • Bob Knipper

    Bob Knipper - 2013-09-10

    Probably didn't show because I have been using GCGB. Need to learn GCB syntax so I downloaded GCB and Crimson editor and will start using them. Thanks again for the help.

     
  • Bob Knipper

    Bob Knipper - 2015-06-26

    Finally finished my binary clock, in my projects page.
    Nothing like I first envisioned it.

     

Log in to post a comment.