Menu

16F1829 - when compliled/program error!

Anobium
2013-02-09
2013-05-30
  • Anobium

    Anobium - 2013-02-09

    I am now building my robot and I have found an issue in the compiler.

    I am controlling a L293d but it was not working. Ports on the PortC device are staying HIGH.  I have simplied the code to reproduce the error.

    In the code below Portc.1 is turned on, and should not turn off but when programmed it does.  The ASM is below.

    #chip 16F1829, 4
    #config osc = xt, MCLRE_OFF
    dir PORTC.0 out
    dir PORTC.1 out
    dir PORTC.3 out
    Dir PORTC.4 out
        set PORTC.3 ON
      Set PORTC.4 ON
      wait 1 s
    do
        SET PORTC.4 OFF
      SET PORTC.3 ON
      SET PORTC.1 ON
    '  PORTC.0 = 0
      wait 1 s
        SET PORTC.4 ON
      SET PORTC.3 ON
        'PORTC.1 = 0
    '  PORTC.0 = 1
      Wait 1 s
    loop
    

    ASM

    ;Program compiled by Great Cow BASIC (0.9 5/11/2012)
    ;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=16F1829, r=DEC
    #include <P16F1829.inc>
     __CONFIG _CONFIG1, _MCLRE_OFF & _WDTE_OFF & _FOSC_XT
     __CONFIG _CONFIG2, _LVP_OFF & _PLLEN_OFF
    ;********************************************************************************
    ;Set aside memory locations for variables
    DELAYTEMP   EQU 112
    DELAYTEMP2  EQU 113
    SysWaitTempMS   EQU 114
    SysWaitTempMS_H EQU 115
    SysWaitTempS    EQU 116
    ;********************************************************************************
    ;Vectors
        ORG 0
        goto    BASPROGRAMSTART
        ORG 4
        retfie
    ;********************************************************************************
    ;Start of program memory page 0
        ORG 5
    BASPROGRAMSTART
    ;Call initialisation routines
        call    INITSYS
    ;Start of the main program
    ;dir PORTC.0 out
        banksel TRISC
        bcf TRISC,0
    ;dir PORTC.1 out
        bcf TRISC,1
    ;dir PORTC.3 out
        bcf TRISC,3
    ;Dir PORTC.4 out
        bcf TRISC,4
    ;set PORTC.3 ON
        banksel PORTC
        bsf PORTC,3
    ;Set PORTC.4 ON
        bsf PORTC,4
    ;wait 1a s
        movlw   1
        movwf   SysWaitTempS
        call    Delay_S
    ;do
    SysDoLoop_S1
    ;SET PORTC.4 OFF
        bcf PORTC,4
    ;SET PORTC.3 ON
        bsf PORTC,3
    ;SET PORTC.1 ON
        bsf PORTC,1
    ;PORTC.0 = 0
    ;wait 1 s
        movlw   1
        movwf   SysWaitTempS
        call    Delay_S
    ;SET PORTC.4 ON
        bsf PORTC,4
    ;SET PORTC.3 ON
        bsf PORTC,3
    ;PORTC.0 = 1
    ;Wait 1 s
        movlw   1
        movwf   SysWaitTempS
        call    Delay_S
    ;loop
        goto    SysDoLoop_S1
    SysDoLoop_E1
    BASPROGRAMEND
        sleep
        goto    BASPROGRAMEND
    ;********************************************************************************
    Delay_MS
        incf    SysWaitTempMS_H, F
    DMS_START
        movlw   142
        movwf   DELAYTEMP2
    DMS_OUTER
        movlw   1
        movwf   DELAYTEMP
    DMS_INNER
        decfsz  DELAYTEMP, F
        goto    DMS_INNER
        decfsz  DELAYTEMP2, F
        goto    DMS_OUTER
        decfsz  SysWaitTempMS, F
        goto    DMS_START
        decfsz  SysWaitTempMS_H, F
        goto    DMS_START
        return
    ;********************************************************************************
    Delay_S
    DS_START
        movlw   232
        movwf   SysWaitTempMS
        movlw   3
        movwf   SysWaitTempMS_H
        call    Delay_MS
        decfsz  SysWaitTempS, F
        goto    DS_START
        return
    ;********************************************************************************
    INITSYS
    ;OSCCON = OSCCON AND b'10000111'
        movlw   135
        banksel OSCCON
        andwf   OSCCON,F
    ;OSCCON = OSCCON OR b'01101000'
        movlw   104
        iorwf   OSCCON,F
    ;SET ADCON0.ADON OFF
        bcf ADCON0,ADON
    ;SET ADFM OFF
        bcf ADCON1,ADFM
    ;ANSELA = 0
        banksel ANSELA
        clrf    ANSELA
    ;ANSELB = 0
        clrf    ANSELB
    ;C2ON = 0
        banksel CM2CON0
        bcf CM2CON0,C2ON
    ;C1ON = 0
        bcf CM1CON0,C1ON
    ;PORTA = 0
        banksel PORTA
        clrf    PORTA
    ;PORTB = 0
        clrf    PORTB
    ;PORTC = 0
        clrf    PORTC
        return
    ;********************************************************************************
    ;Start of program memory page 1
        ORG 2048
    ;Start of program memory page 2
        ORG 4096
    ;Start of program memory page 3
        ORG 6144
     END
    
     
  • Chuck Hellebuyck

    You may be experiencing the Read Modify Write issue. Instead of writing to PORTC write to LATC.
    i.e.
    set LATC.3 ON

     
  • Anobium

    Anobium - 2013-02-12

    I will give this a try and test.

     

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.