12f508 asm help

Discussion in 'Programmer's Corner' started by cristian, Oct 16, 2005.

  1. cristian

    Thread Starter New Member

    Oct 9, 2005
    1
    0
    Could you help me get this fixed?

    It is a slight modified (different outputs<HLH> instead of three LOW outputs, see the OutputOn and OutputOff) of a Microchip's AppNote.
    The MPASMWIN returns a lot of errors.

    ;****************************************************************************
    ;* Project: Smart Wiper Switch *
    ;****************************************************************************
    processor 12f508
    radix dec
    errorlevel 0,-305
    include "p12f508.inc"
    #define __12F508
    __config _WDT_OFF & _IntRC_OSC & _MCLRE_OFF & _CP_ON
    #define zero STATUS, 2
    #define carry STATUS, 0
    #define TRUE 0
    #define FALSE -1
    CBLOCK 0x07 ; start of RAM
    ENDC
    MOVWF OSCCAL
    GOTO Main
    ;
    TMR0overrun EQU .16384 ; timer0 overrun every 16.4ms
    ; remember to change the option value
    #define ms 1000/TMR0overrun ; in the main program when changing
    #define secs 1000000/TMR0overrun ; this
    ;* Hardware *****************************************************************
    #define Switch GPIO, 3
    #define LED GPIO, 5
    #define Buzzer GPIO, 4
    #define LedOn BCF LED ; LED output is activ low
    #define LedOff BSF LED
    BuzzerOn MACRO
    BCF Buzzer ; Buzzer is open drain in order
    MOVLW b'001000' ; to share it with other units
    TRIS GPIO
    ENDM
    BuzzerOff MACRO
    MOVLW b'011000'
    TRIS GPIO
    ENDM
    OutputOn MACRO
    MOVLW b'000101' ;
    ANDWF GPIO
    ENDM
    OutputOff MACRO
    MOVLW b'111010'
    IORWF GPIO
    ENDM
    ;
    WiperThreshold EQU 500*ms
    MinimumInterval EQU 1*secs
    DefaultInterval EQU 2*secs
    BeepLength EQU 200*ms
    DenoiseTime EQU 50*ms
    DebounceTime EQU 50*ms
    DisableAfter EQU 20*secs
    ;* Macros *******************************************************************
    TWSTrue MACRO ; (T)est (W) and (S)kip if (True)
    IORLW 0
    BTFSS zero
    ENDM
    TWSFalse MACRO
    IORLW 0
    BTFSC zero
    ENDM
    #define SkipIfZero BTFSS zero
    #define DoIfZero BTFSC zero
    #define RET RETLW 0
    ;* Switch ********************************************************************
    CBLOCK
    Denoise
    Debounce
    Flags
    ENDC
    #define SwitchClosed Flags, 0
    ;
    HandleSwitch MACRO
    BTFSS Switch
    GOTO HS.closed
    HS.opened MOVLW DebounceTime; switch open now, so
    MOVWF Debounce ; reset timer for 'switch closed'
    BTFSS SwitchClosed
    GOTO HS.done ; switch is already denoised
    DECFSZ Denoise ; otherwise, wait till switch
    GOTO HS.done ; is stable a certain time
    BCF SwitchClosed
    GOTO HS.done
    HS.closed MOVLW DenoiseTime; as above
    MOVWF Denoise
    BTFSC SwitchClosed
    GOTO HS.done
    DECFSZ Debounce
    GOTO HS.done
    BSF SwitchClosed
    HS.done
    ENDM
    ;* Timer *********************************************************************
    CBLOCK
    Timer0L
    Timer0H
    Timer1L
    Timer1H
    OldTMR0
    ENDC
    IncreaseTimer1 MACRO
    INCFSZ Timer1L
    GOTO Timer1.done
    INCF Timer1H
    Timer1.done
    ENDM
    Interrupt MOVF OldTMR0, W ; increase Timer on TMR0-overflow
    SUBWF TMR0, W ; overflow, if OldTMR0 > TMR0
    BTFSC carry
    GOTO Interrupt.done
    ADDWF OldTMR0
    ; program enters here every 16.4ms
    HandleSwitch
    IncreaseTimer1
    INCFSZ Timer0L
    RETLW FALSE
    INCFSZ Timer0H
    RETLW FALSE
    RETLW TRUE ; return TRUE upon hitting zero
    ; in timer0 !
    Interrupt.done ADDWF OldTMR0
    RETLW FALSE
    ;
    LoadTimer0 MACRO Value
    MOVLW low(-Value)
    MOVWF Timer0L
    MOVLW high(-Value)
    MOVWF Timer0H
    ENDM
    ;* Subroutines **************************************************************
    Beep LoadTimer0 BeepLength
    Beep.loop BTFSC TMR0, 2 ; this will generate about 2 kHz
    BuzzerOn
    BTFSS TMR0, 2
    BuzzerOff
    CALL Interrupt
    TWSTrue
    GOTO Beep.loop
    BuzzerOff
    RET
    ;
    Delay MACRO Value
    LOCAL Loop
    LoadTimer0 Value
    Loop CALL Interrupt
    TWSTrue
    GOTO Loop
    ENDM
    ;****************************************************************************
    CBLOCK
    IntervalL
    IntervalH
    ENDC
    Main MOVLW b'10010101'; pullups on
    OPTION ; -> TMR0overrun every 16.384us
    BuzzerOff ; this will also set TRIS correctly
    OutputOff
    MOVLW DebounceTime
    MOVWF Debounce
    BCF SwitchClosed
    ;
    Main.loop LedOff
    CALL Interrupt
    BTFSS SwitchClosed
    GOTO Main.loop
    MOVLW low(DefaultInterval); Interval:= DefaultInterval
    MOVWF IntervalL ;
    MOVLW high(DefaultInterval);
    MOVWF IntervalH ;
    LedOn
    CheckInterval MOVLW high(MinimumInterval); if Interval<MinimumInterval
    SUBWF IntervalH, W ; then GOTO Wipe.continuous
    BTFSS carry ;
    GOTO Wipe.continuous;
    BTFSS zero ;
    GOTO Wipe.interval ;
    MOVLW low(MinimumInterval);
    SUBWF IntervalL, W ;
    BTFSS carry ;
    GOTO Wipe.continuous;
    ;-------------------------------;
    Wipe.interval OutputOn ; initiate single wipe
    CLRF Timer1L ; always clear timer1 upon
    CLRF Timer1H ; wiping
    Delay WiperThreshold;
    OutputOff ;
    Wipe.int.loop CALL Interrupt
    BTFSS SwitchClosed
    GOTO Off?
    MOVF IntervalH, W ; if timer1<Interval
    SUBWF Timer1H, W ; then GOTO Wipe.int.loop
    BTFSS carry ; else GOTO Wipe.interval
    GOTO Wipe.int.loop ;
    BTFSS zero ;
    GOTO Wipe.interval ;
    MOVF IntervalL, W ;
    SUBWF Timer1L, W ;
    BTFSS carry ;
    GOTO Wipe.int.loop ;
    GOTO Wipe.interval ;
    ;-------------------------------;
    Wipe.continuous OutputOn
    CLRF Timer1L ; always clear timer1 upon
    CLRF Timer1H ; wiping
    CALL Interrupt
    BTFSC SwitchClosed
    GOTO Wipe.continuous
    OutputOff
    ;-------------------------------;
    Off? LoadTimer0 DisableAfter
    Off?.loop BTFSC SwitchClosed
    GOTO NewIntervalSet
    CALL Interrupt
    TWSTrue
    GOTO Off?.loop
    GOTO Main.loop ; 30 seconds expired
    ;-------------------------------;
    NewIntervalSet MOVF Timer1L, W
    MOVWF IntervalL
    MOVF Timer1H, W
    MOVWF IntervalH
    CALL Beep
    GOTO CheckInterval
    ;****************************************************************************
    END
     
Loading...