asm code problems

Discussion in 'Programmer's Corner' started by markosillypig, Apr 1, 2009.

  1. markosillypig

    Thread Starter Active Member

    Jul 21, 2008
    184
    0
    hi all i have a problem i have a asm code and would like it into a hex file the problem is the program i use tells me there are errors and will not make a hex file can anyone help it is for the 12f629 chip
    here is the asn code

    ;*****************************************************************************
    ; Navlights.asm LED Lighting System
    ;*****************************************************************************
    ; Bruce Abbott bhabbott@paradise.net.nz
    ;
    ; for Microchip PIC 12C508, 12C509, 12F629 or 12F675.
    ;
    ;=============================================================================
    ; Summary of Changes
    ;
    ; 2005/03/15 V0.0 - Created from RXDecode.asm
    ; 2005/08/06 V0.1 - Two strobe lights, asyncronous flash sequence.
    ; 2005/12/17 V0.2 - Servo input selects Landing, Lights On, or Lights Off.
    ; -----------------------------------------------------------------------------
    #DEFINE TIME 4 ; number of servo pulses per strobe state
    #DEFINE version "0.2"
    ;#DEFINE __12C508 ; enable if processor not specified elsewhere
    ;#DEFINE __12F675 ; MPLAB users should use menu <Configure/Select Device>
    ;#DEFINE NO_OSCCAL ; enable if OSCCAL value was erased!

    ifdef __12C508
    PROCESSOR PIC12C508
    INCLUDE <P12C508.inc>
    __CONFIG _MCLRE_OFF&_CP_OFF&_WDT_ON&_IntRC_OSC
    else
    PROCESSOR PIC12F675
    INCLUDE <P12F675.inc>
    __CONFIG _MCLRE_OFF&_CP_OFF&_WDT_ON&_BODEN_ON&_INTRC_OSC_NOCLKOUT
    endif
    radix dec
    errorlevel 0,-305,-302

    ; Bit definitions for the GPIO register and the TRIS register
    ; NOTE: LED is turned on when its GPIO ouput is LOW.
    ;
    #DEFINE STRB1 5 ; pin 2 Strobe Light #1
    #DEFINE STRB2 4 ; pin 3 Strobe Light #2
    #DEFINE SERVO 3 ; pin 4 servo pulse input
    #DEFINE LAND 2 ; pin 5 Landing Lights
    #DEFINE LED1 1 ; pin 6 Fixed lighting (eg. Navigation Lights)
    #DEFINE LED2 0 ; pin 7 More Fixed Lighting (eg. Cabin Lights)
    ;
    #DEFINE TrisBits (1<<SERVO) ; servo pulse is an input
    ; -------------------- OPTIONS ------------------------
    ; no wakeup (12C508)
    ; weak pullups enabled
    ; Timer 0 source internal
    ; Prescaler to Timer 0, divide by 256.
    ;
    ifdef __12C508
    #DEFINE OptionBits B'10000111'
    else
    #DEFINE OptionBits B'00000111'
    endif

    ;=========================================================================
    ; Macro for generating short time delays
    ;
    NO_OP MACRO count
    NO_OP_COUNT SET count
    WHILE NO_OP_COUNT>1
    goto $+1 ; 2 clocks
    NO_OP_COUNT SET NO_OP_COUNT-2
    ENDW
    IF NO_OP_COUNT
    nop ; 1 clock
    ENDIF
    ENDM
    ;===========================================================================
    ; Macro to create offsets for variables in RAM
    ;
    ifdef __12C508
    ByteAddr SET 7
    else
    ByteAddr SET 32 ; user RAM starts here
    endif
    BYTE MACRO ByteName
    ByteName EQU ByteAddr
    ByteAddr SET ByteAddr+1
    ENDM
    ; ==========================================================================
    ; RAM Variable Definitions
    ;
    BYTE Flags ; various boolean flags
    BYTE ServoCount ; servo pulse length. 1~255 = 0.01~2.55mS
    BYTE Timer ; delay timer for strobes
    BYTE Strobe1 ; strobe 1 sequencer
    BYTE Strobe2 ; strobe 2 sequencer
    BYTE Glitches ; number of consecutive bad servo pulses
    BYTE Temp1
    BYTE Temp2

    ; flag values
    ;
    #DEFINE WATCH 0 ; Watchdog timed out
    #DEFINE STROBE1 1 ; strobe 1 on
    #DEFINE STROBE2 2 ; strobe 2 on
    #DEFINE LANDING 3 ; Landing lights on

    ;****************************************************************************
    ; Code
    ;
    ORG 0
    goto ColdStart
    ;-------------------------- version string ----------------------------------
    org 8
    ifdef __12C508
    dt "LIGHT508"
    endif
    ifdef __12F629
    dt "LIGHT629"
    endif
    ifdef __12F675
    dt "LIGHT675"
    endif
    dt "--V"
    dt version
    dt "--"
    ;============================================================================
    ColdStart:
    bcf Flags,WATCH
    btfss STATUS,NOT_TO ; copy Watchdog timeout flag
    bsf Flags,WATCH
    ; get oscillator calibration value and use it to fine-tune clock frequency.
    ; 12C508/9 has value in W at startup, 12F629/75 gets it from RETLW at 0x3ff.
    ifdef __12C508
    ifdef NO_OSCCAL
    movlw 0x90 ; replace with value for your PIC!
    endif
    movwf OSCCAL ; set oscillator calibration
    else
    bsf STATUS,RP0 ; register bank 1 (12F629/75)
    call 0x3ff ; get OSCCAL value
    movwf OSCCAL ; set oscillator calibration
    bcf STATUS, RP0 ; register bank 0
    endif
    ; set options
    ifdef __12C508
    movlw OptionBits
    option
    else
    bsf STATUS,RP0 ; register bank 1 (12F629/75)
    movlw OptionBits
    movwf OPTION_REG
    bcf STATUS,RP0 ; register bank 0
    endif
    ;========================================================================
    ; initialise I/O registers
    ifdef __12C508
    movlw 0
    movwf GPIO ; all outputs on
    movlw TrisBits
    TRIS GPIO ; set I/O pin directions
    else
    clrf GPIO ; all outputs low
    bsf STATUS,RP0 ; register bank 1 (12F629/75)
    movlw TrisBits
    movwf TRISIO ; set I/O pin directions
    ifdef ANSEL
    clrf ANSEL ; disable analog inputs (12F675)
    endif
    bcf STATUS,RP0 ; register bank 0
    ifdef CMCON
    movlw b'00000111'
    movwf CMCON ; Comparator off
    endif
    endif
    ; CPU specific stuff done, now we can start the main program!
    goto Main
    SeqStrobe1:
    ifdef PCLATH
    clrf PCLATH
    endif
    movf Strobe1,w
    addwf PCL
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'10000000'
    SeqStrobe2:
    ifdef PCLATH
    clrf PCLATH
    endif
    movf Strobe2,w
    addwf PCL
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'10000000'
    ;-------------------------------------------------------------------------------
    ; Millisecond Delay Timer
    ;-------------------------------------------------------------------------------
    ; Input: W = number of milliseconds to wait (max 256mS)
    ;
    dx1k: movwf Temp1
    _dx1k1: movlw (1000-5)/5
    movwf Temp2
    _dx1k2: clrwdt ; avoid watchdog timeout
    nop
    decfsz Temp2 ; wait 1mS
    goto _dx1k2
    decfsz Temp1
    goto _dx1k1
    retlw 0

    ;*******************************************************************************
    ; Main
    ;*******************************************************************************

    Main: btfsc Flags,WATCH ; did the watchdog timeout ?
    goto MainLoop ; oops! try to keep going ...
    clrf Flags ; clear all flags
    movlw 250 ; wait 500mS for power to stabilise
    call dx1k
    movlw 250
    call dx1k
    movlw TIME
    movwf Timer
    clrf Strobe1
    clrf Strobe2
    clrf Glitches
    MainLoop: clrf TMR0 ; start timer
    WaitLow: clrwdt ; avoid watchdog timeout
    btfsc TMR0,7 ; timer reached 33mS ?
    goto NoSignal
    btfsc GPIO,SERVO ; wait for no servo pulse
    goto WaitLow
    clrf TMR0 ; start timer
    waitpulse: clrwdt ; avoid watchdog timeout
    btfsc TMR0,7 ; timer reached 33mS ?
    goto NoSignal
    btfss GPIO,SERVO ; wait for start of servo pulse
    goto waitpulse
    clrf ServoCount
    measure: clrwdt ;1
    incf ServoCount ;2 count = pulse width (* 10uS)
    skpnz ;3 > 2.55mS ?
    goto BadPulse ;4 Yes, error
    NO_OP 3 ;5~7
    btfsc GPIO,SERVO ;8 servo pulse finished ?
    goto measure ;9,10 no, continue measuring
    movlw 70
    subwf ServoCount,w ; less than 0.7mS ?
    skpc
    goto BadPulse ; yes, bad pulse
    bcf Flags,LANDING ; assume landing lights are off
    movlw 130
    subwf ServoCount,w ; less than 1.3mS ?
    skpc
    bsf Flags,LANDING ; yes, landing lights on
    movlw 170
    subwf ServoCount,w ; less than 1.7mS ?
    skpc
    goto power_on ; yes, power on
    power_off movlw 1<<STRB1|1<<STRB2|1<<LAND|1<<LED1|1<<LED2
    movwf GPIO ; All lights OFF
    goto GoodPulse
    power_on: bcf GPIO,LED1 ; fixed lights ON
    bcf GPIO,LED2
    landing_lights: btfss Flags,LANDING
    bsf GPIO,LAND ; Landing lights OFF
    btfsc Flags,LANDING
    bcf GPIO,LAND ; Landing lights ON
    strobes: decfsz Timer ; time for next strobe change?
    goto GoodPulse ; no, done
    movlw TIME
    movwf Timer ; restart timer
    call SeqStrobe1 ; get Strobe 1 state
    movwf Temp1
    incf Strobe1 ; next state
    btfsc Temp1,7 ; end of sequence ?
    clrf Strobe1 ; restart sequence
    bcf Flags,STROBE1
    btfsc Temp1,0 ; strobe 1 to be on ?
    bsf Flags,STROBE1
    call SeqStrobe2 ; get Strobe2 state
    movwf Temp1
    incf Strobe2 ; next state
    btfsc Temp1,7 ; end of sequence ?
    clrf Strobe2 ; restart sequence
    bcf Flags,STROBE2
    btfsc Temp1,0 ; strobe 2 to be on ?
    bsf Flags,STROBE2
    btfss Flags,STROBE1
    bsf GPIO,STRB1 ; flash strobe 1
    btfsc Flags,STROBE1
    bcf GPIO,STRB1
    btfss Flags,STROBE2
    bsf GPIO,STRB2 ; flash strobe 2
    btfsc Flags,STROBE2
    bcf GPIO,STRB2
    GoodPulse: tstf Glitches
    skpnz
    goto done
    decf Glitches ; another good pulse received
    goto done
    BadPulse: incf Glitches ; another bad pulse!
    movlw 10
    subwf Glitches,w
    skpc ; too many bad pulses?
    goto done
    decf Glitches
    NoSignal: movlw 1<<STRB1|1<<STRB2|1<<LAND|1<<LED1|1<<LED2
    movwf GPIO ; turn off all outputs
    done: goto MainLoop



    ;---------- Oscillator Calibration Subroutine (12F629/75 only) --------------
    ifdef __12F675
    org 0x3ff
    retlw 0x90 ; replace with oscal value for your PIC!
    endif
    END
     
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    And where's the error listing? I guess you are using MPLAB, correct?
     
  3. markosillypig

    Thread Starter Active Member

    Jul 21, 2008
    184
    0
    yes i am i have been trying to find a program that makes an easy job of it have you any suggestions or can someone just send me the asm file back as a hex file
    thanks all
     
  4. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Assembly is picky about spaces.

    Directives and labels need to be in column 1, everything else needs to be past column 2.

    Other than that, no clue why it didn't work for you. MPLAB v8.20

    Ran perfectly after I ran it through assembly formatting script.

    attached.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Got a schematic to go with it? I have a couple 675s layin here with nothin to do, lemme know if it is interesting and what connects to what.

    Might as well make the thread complete. :)
     
  6. markosillypig

    Thread Starter Active Member

    Jul 21, 2008
    184
    0
    here is the scamatic of the circuit
    the circuit is to control 8 led lights via your remote control handset to opporate the landing light
    cabin lights and the navigation lights
    like the real thing
    i had a few problems with this asm same kind of thing but just for hellicopters
    could you have a look at the code for me and if evrything is ok send it back to me as a hex
    your help is much appreciated
     
    Last edited: Apr 2, 2009
  7. markosillypig

    Thread Starter Active Member

    Jul 21, 2008
    184
    0
    i had a few problems with this asm same kind of thing but just for hellicopters
    could you have a look at the code for me and if evrything is ok send it back to me as a hex
    your help is much appreciated


    ;***************************************************************************
    ; lights.asm Scale LED Lighting System
    ;***************************************************************************
    ; Bruce Abbott bhabbott@paradise.net.nz
    ;
    ; for Microchip PIC 12C508, 12C509, 12F629 or 12F675.
    ;
    ;============================= Description =================================
    ;
    ; =============================================================================
    ; Summary of Changes
    ;
    ; 2005/03/15 V0.0 - Created from RXDecode.asm
    ; 2005/03/19 V0.1 - Reduced strobe flash time
    ; 2005/05/20 V0.2 - Changed strobe flash sequence again!
    ;
    ; -----------------------------------------------------------------------------
    #DEFINE TIME 4 ; number of servo pulses per strobe state
    #DEFINE version "0.2"
    ;#DEFINE __12C508 ; enable if processor not specified elsewhere
    ;#DEFINE __12F675 ; MPLAB users should use menu <Configure/Select Device>
    ;#DEFINE NO_OSCCAL ; enable if OSCCAL value was erased!

    ifdef __12C508
    PROCESSOR PIC12C508
    INCLUDE <P12C508.inc>
    __CONFIG _MCLRE_OFF&_CP_OFF&_WDT_ON&_IntRC_OSC
    else
    PROCESSOR PIC12F675
    INCLUDE <P12F675.inc>
    __CONFIG _MCLRE_OFF&_CP_OFF&_WDT_ON&_BODEN_ON&_INTRC_OSC_NOCLKOUT
    endif
    radix dec
    errorlevel 0,-305,-302

    ; Bit definitions for the GPIO register and the TRIS register
    #DEFINE STRB1 0 ; pin 7 strobe light #1 (switched) WHITE
    #DEFINE STRB2 1 ; pin 6 strobe light #2 (not switched) RED
    #DEFINE NAV 2 ; pin 5 navigation lights (switched) RED/GREEN
    #DEFINE SERVO 3 ; pin 4 servo pulse input
    #DEFINE AUX1 4 ; pin 3 auxilary output 1
    #DEFINE AUX2 5 ; pin 2 auxilary output 2
    #DEFINE TrisBits (1<<SERVO)

    ; Bits to be set with the OPTION instruction
    ; No wake up
    ; No weak pullups
    ; Timer 0 source internal
    ; Prescaler to Watchdog, divide by 16 (~270mS).
    ;
    #DEFINE OptionBits B'11011100'

    ;=========================================================================
    ; Macro for generating short time delays
    ;
    NO_OP MACRO count
    NO_OP_COUNT SET count
    WHILE NO_OP_COUNT>1
    goto $+1 ; 2 clocks
    NO_OP_COUNT SET NO_OP_COUNT-2
    ENDW
    IF NO_OP_COUNT
    nop ; 1 clock
    ENDIF
    ENDM
    ;===========================================================================
    ; Macro to create offsets for variables in RAM
    ;
    ifdef __12C508
    ByteAddr SET 7
    else
    ByteAddr SET 32 ; user RAM starts here
    endif
    BYTE MACRO ByteName
    ByteName EQU ByteAddr
    ByteAddr SET ByteAddr+1
    ENDM
    ; ==========================================================================
    ; RAM Variable Definitions
    ;
    BYTE Flags ; various boolean flags
    BYTE ServoCount ; servo pulse length. 1~255 = 0.01~2.55mS
    BYTE Timer ; delay timer for strobes
    BYTE Strobe1 ; strobe 1 sequencer
    BYTE Strobe2 ; strobe 2 sequencer

    BYTE Temp1
    BYTE Temp2

    ; flag values
    ;
    #DEFINE WATCH 0 ; Watchdog timeout
    #DEFINE STROBE1 1 ; strobe 1 is on
    #DEFINE STROBE2 2 ; strobe 2 is on
    #DEFINE SWITCH 4 ; switch is on (controlled by servo input)

    ;****************************************************************************
    ; Code
    ;
    ORG 0
    goto ColdStart
    ;-------------------------- version string ----------------------------------
    org 8
    ifdef __12C508
    dt "RYANL508"
    endif
    ifdef __12F629
    dt "RYANL629"
    endif
    ifdef __12F675
    dt "RYANL675"
    endif
    dt "--V"
    dt version
    dt "--"
    ;============================================================================
    ColdStart:
    bcf Flags,WATCH
    btfss STATUS,NOT_TO ; copy Watchdog timeout flag
    bsf Flags,WATCH
    ; get oscillator calibration value and use it to fine-tune clock frequency.
    ; 12C508/9 has value in W at startup, 12F629/75 gets it from RETLW at 0x3ff.
    ifdef __12C508
    ifdef NO_OSCCAL
    movlw 0x90 ; replace with value for your PIC!
    endif
    movwf OSCCAL ; set oscillator calibration
    else
    bsf STATUS,RP0 ; register bank 1 (12F629/75)
    call 0x3ff ; get OSCCAL value
    movwf OSCCAL ; set oscillator calibration
    bcf STATUS, RP0 ; register bank 0
    endif
    ; ==========================================================================
    ; Moves the prescaler from tmr0 to the watchdog without accidental resets.
    ;
    clrwdt
    clrf TMR0
    movlw OptionBits | 7
    option
    clrwdt
    movlw OptionBits
    option
    clrwdt

    ifdef __12C508
    clrwdt
    clrf TMR0
    movlw OptionBits | 7
    option
    clrwdt
    movlw OptionBits
    option
    clrwdt
    else
    clrwdt
    clrf TMR0
    bsf STATUS,RP0 ; register bank 1 (12F629/75)
    movlw OptionBits | 7
    movwf OPTION_REG
    clrwdt
    movlw OptionBits
    movwf OPTION_REG
    bcf STATUS,RP0 ; register bank 0
    clrwdt
    endif
    ;========================================================================
    ; initialise I/O registers
    ifdef __12C508
    clrf GPIO ; all outputs low
    movlw TrisBits
    TRIS GPIO ; set I/O pin directions
    else
    clrf GPIO ; all outputs low
    bsf STATUS,RP0 ; register bank 1 (12F629/75)
    movlw TrisBits
    movwf TRISIO ; set I/O pin directions
    ifdef ANSEL
    clrf ANSEL ; disable analog inputs (12F675)
    endif
    bcf STATUS,RP0 ; register bank 0
    ifdef CMCON
    movlw b'00000111'
    movwf CMCON ; Comparator off
    endif
    endif
    ; CPU specific stuff done, now we can start the main program!
    goto Main

    SeqStrobe1:
    ifdef PCLATH
    clrf PCLATH
    endif
    movf Strobe1,w
    addwf PCL
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'10000000'
    SeqStrobe2:
    ifdef PCLATH
    clrf PCLATH
    endif
    movf Strobe2,w
    addwf PCL
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'10000000'
    ;-------------------------------------------------------------------------------
    ; Millisecond Delay Timer
    ;-------------------------------------------------------------------------------
    ; Input: W = number of milliseconds to wait (max 256mS)
    ;
    dx1k: movwf Temp1
    _dx1k1: movlw (1000-5)/5
    movwf Temp2
    _dx1k2: clrwdt ; avoid watchdog timeout
    nop
    decfsz Temp2 ; wait 1mS
    goto _dx1k2
    decfsz Temp1
    goto _dx1k1
    retlw 0

    ;*******************************************************************************
    ; Main
    ;*******************************************************************************

    Main: btfsc Flags,WATCH ; did the watchdog timeout ?
    goto MainLoop ; oops! try to keep going ...
    clrf Flags ; clear all flags
    movlw 250 ; wait 500mS for power to stabilise
    call dx1k
    movlw 250
    call dx1k
    movlw TIME
    movwf Timer
    clrf Strobe1
    clrf Strobe2
    MainLoop: clrwdt ; avoid watchdog timeout
    btfsc GPIO,SERVO ; wait for no servo pulse
    goto MainLoop
    waitpulse: clrwdt ; avoid watchdog timeout
    btfss GPIO,SERVO ; wait for start of servo pulse
    goto waitpulse
    clrf ServoCount
    measure: incf ServoCount ;1 count * 10uS
    skpnz ;2
    goto ServoError ;3 >2.55mS ?
    clrwdt ; 4 avoid watchdog timeout
    NO_OP 3 ;5~7
    btfsc GPIO,SERVO ;8 servo pulse finished ?
    goto measure ;9,10 no, continue measuring
    movlw 150
    subwf ServoCount,w ; less than 1.5mS ?
    bcf Flags,SWITCH ; assume no
    skpc
    bsf Flags,SWITCH ; yes
    decfsz Timer
    goto MainLoop ; time for next change?
    movlw TIME
    movwf Timer
    call SeqStrobe1 ; get Strobe 1 state
    movwf Temp1
    incf Strobe1 ; next state
    btfsc Temp1,7 ; end of sequence ?
    clrf Strobe1 ; restart sequence
    bcf Flags,STROBE1
    btfsc Temp1,0 ; strobe 1 to be on ?
    bsf Flags,STROBE1
    call SeqStrobe2 ; get Strobe2 state
    movwf Temp1
    incf Strobe2 ; next state
    btfsc Temp1,7 ; end of sequence ?
    clrf Strobe2 ; restart sequence
    bcf Flags,STROBE2
    btfsc Temp1,0 ; strobe 2 to be on ?
    bsf Flags,STROBE2
    btfsc Flags,SWITCH ; switch on ?
    goto switch_on
    switch_off: bcf GPIO,NAV ; no, turn off NAV lights
    bcf GPIO,STRB1 ; turn of strobe 1
    goto switch_done
    switch_on: bsf GPIO,NAV ; yes, turn on NAV lights
    btfss Flags,STROBE1 ; flash strobe 1
    bcf GPIO,STRB1
    btfsc Flags,STROBE1
    bsf GPIO,STRB1
    switch_done: btfss Flags,STROBE2 ; flash strobe 2
    bcf GPIO,STRB2
    btfsc Flags,STROBE2
    bsf GPIO,STRB2
    ServoError:
    done: goto MainLoop



    ;---------- Oscillator Calibration Subroutine (12F629/75 only) --------------
    ifdef __12F675
    org 0x3ff
    retlw 0x90 ; replace with oscal value for your PIC!
    endif
    END
     
Loading...