Varför fungerar inte denna assablerkod????
Postat: 23 maj 2004, 23:39:11
Jag vill köra en stegmotor 100 steg framåt sen 150 steg bakåt i snabbare hastighet
När jag försöker assemblera får jag ett error som säger Symbol not previously defined (wait_2s) osv i samma feltyp
Här är koden:
#include "P16f877A.inc"
__CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF
LIST P=16A877A R=DEC
;*****************************VARIABELS***************************
Cblock 0x020
HIcnt
LOcnt
LOOPcnt
endc
;*************************Defines**********************************
#define STEP1 .5
#define STEP2 .9
#define STEP3 .10
#define STEP4 .6
#define POS1 .100
#define POS2 .150
;******************************************************************
pausems macro par1
local Loop1
local dechi
local Delay1ms
local Loop2
local End
movlw high par1 ;higher byte of parameter 1 goes to HIcnt
movwf HIcnt
movlw low par1 ;lower byte of parameter 1 goes to LOcnt
movwf LOcnt
Loop1
movf LOcnt, f ;Decrease HIcnt and Locnt necessary
btfsc STATUS, Z ;number of times and call subprogram Delay 1ms
goto dechi
call Delay1ms
decf LOcnt, f
goto Loop1
dechi
movf HIcnt, f
btfsc STATUS, Z
goto End
call Delay1ms
decf HIcnt, f
decf LOcnt, f
goto Loop1
Delay1ms: ;Delay1ms produce 1ms delay
movlw .100 ;100*10us=1ms
movwf LOOPcnt ;Loopcnt<-100
Loop2:
nop ;1
nop ;2
nop ;3
nop ;4
nop ;5
nop ;6
nop ;7
decfsz LOOPcnt, f
goto Loop2 ;Time period necessary to execute loop Loop2
return ;equals 10us
End
endm
;***************************PROGRAM START**************************
ORG 0
goto init
ORG 4
goto init
;**************************MAIN ROUTINE****************************
init
bcf STATUS,RP1
bsf STATUS,RP0 ;bank 1
movlw b'00000000' ;Set trisb to output
movwf TRISB
bcf STATUS, RP0 ;back to bank 0
goto Main
Main
call Plus
call wait_2s
call Minus
call wait_2s
goto Main ;do this loop forewer
Plus
movlw STEP1
movwf PORTB
call wait_50
movlw STEP2
movwf PORTB
call wait_50
movlw STEP3
movwf PORTB
call wait_50
movlw STEP4
movwf PORTB
call wait_50
decfsz POS1, f
goto Plus
return
Minus
movlw STEP4
movwf PORTB
call wait_10
movlw STEP3
movwf PORTB
call wait_10
movlw STEP2
movwf PORTB
call wait_10
movlw STEP1
movwf PORTB
call wait_10
decfsz POS2, f
goto Minus
return
wait_50
pausems .500 ;in macro
return
wait_10
pausems .100 ;in macro
return
wait_2s
pausems .2000 ;in macro
return
End
När jag försöker assemblera får jag ett error som säger Symbol not previously defined (wait_2s) osv i samma feltyp
Här är koden:
#include "P16f877A.inc"
__CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF
LIST P=16A877A R=DEC
;*****************************VARIABELS***************************
Cblock 0x020
HIcnt
LOcnt
LOOPcnt
endc
;*************************Defines**********************************
#define STEP1 .5
#define STEP2 .9
#define STEP3 .10
#define STEP4 .6
#define POS1 .100
#define POS2 .150
;******************************************************************
pausems macro par1
local Loop1
local dechi
local Delay1ms
local Loop2
local End
movlw high par1 ;higher byte of parameter 1 goes to HIcnt
movwf HIcnt
movlw low par1 ;lower byte of parameter 1 goes to LOcnt
movwf LOcnt
Loop1
movf LOcnt, f ;Decrease HIcnt and Locnt necessary
btfsc STATUS, Z ;number of times and call subprogram Delay 1ms
goto dechi
call Delay1ms
decf LOcnt, f
goto Loop1
dechi
movf HIcnt, f
btfsc STATUS, Z
goto End
call Delay1ms
decf HIcnt, f
decf LOcnt, f
goto Loop1
Delay1ms: ;Delay1ms produce 1ms delay
movlw .100 ;100*10us=1ms
movwf LOOPcnt ;Loopcnt<-100
Loop2:
nop ;1
nop ;2
nop ;3
nop ;4
nop ;5
nop ;6
nop ;7
decfsz LOOPcnt, f
goto Loop2 ;Time period necessary to execute loop Loop2
return ;equals 10us
End
endm
;***************************PROGRAM START**************************
ORG 0
goto init
ORG 4
goto init
;**************************MAIN ROUTINE****************************
init
bcf STATUS,RP1
bsf STATUS,RP0 ;bank 1
movlw b'00000000' ;Set trisb to output
movwf TRISB
bcf STATUS, RP0 ;back to bank 0
goto Main
Main
call Plus
call wait_2s
call Minus
call wait_2s
goto Main ;do this loop forewer
Plus
movlw STEP1
movwf PORTB
call wait_50
movlw STEP2
movwf PORTB
call wait_50
movlw STEP3
movwf PORTB
call wait_50
movlw STEP4
movwf PORTB
call wait_50
decfsz POS1, f
goto Plus
return
Minus
movlw STEP4
movwf PORTB
call wait_10
movlw STEP3
movwf PORTB
call wait_10
movlw STEP2
movwf PORTB
call wait_10
movlw STEP1
movwf PORTB
call wait_10
decfsz POS2, f
goto Minus
return
wait_50
pausems .500 ;in macro
return
wait_10
pausems .100 ;in macro
return
wait_2s
pausems .2000 ;in macro
return
End