;*************************************************************************
;***************** CONTROL DE UN MOTOR PASO A PASO UNIPOLAR *****************
;**************************************************************************
list p=16f84 ;microcontrolador que vamos a usar
status equ 03h ;declaracion de los registros especificos
trisa equ 05h
porta equ 05h
trisb equ 06h
portb equ 06h
cblock 0ch ;declaracion de los registros de porposito general
r0, r1, r2, r3, r4, r5, PDel0, PDel1
endc
f equ 1
w equ 0
#define banco0 bcf status,5
#define banco1 bsf status,5
org 00h
banco1 ;ingresa al banco1 para configurar pin I/O
bsf trisa,0 ;configuro porta,0 como entrada
bsf trisa,1 ;configuro porta,1 como entrada
bsf trisa,2 ;configuro porta,2 como entrada
bsf trisa,3 ;configuro porta,3 como entrada
bsf trisa,4 ;configuro porta,4 como entrada
bcf trisb,0 ;configuro portb,0 como salida
bcf trisb,1 ;configuro portb,1 como salida
bcf trisb,2 ;configuro portb,2 como salida
bcf trisb,3 ;configuro portb,3 como salida
bcf trisb,4 ;configuro portb,4 como salida
bcf trisb,5 ;configuro portb,5 como salida
bcf trisb,6 ;configuro portb,6 como salida
bcf trisb,7 ;configuro portb,7 como salida
banco0 ;regreso al banco0
inicio movlw .255
movwf portb
loop0 btfsc porta,0
goto loop1
call girar1
loop1 btfsc porta,1
goto loop0
call girar2
goto loop0
girar1 movlw b'00000011' ;W = 00000011
movwf portb ;portb = W
call retardo ;rutina de retardo
movlw b'00000110'
movwf portb
call retardo
movlw b'00001100'
movwf portb
call retardo
movlw b'00001001'
movwf portb
call retardo
return
girar2 movlw b'00001100' ;W = 00001100
movwf portb ;portb = W
call retardo ;rutina de retardo
movlw b'00000110'
movwf portb
call retardo
movlw b'00000011'
movwf portb
call retardo
movlw b'00001001'
movwf portb
call retardo
return
;-------------------- 200ms ---------------------------------
retardo movlw .156 ; 1 set number of repetitions (B)
movwf PDel0 ; 1 |
PLoop1 movlw .213 ; 1 set number of repetitions (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 cycles delay
PDelL2
decfsz PDel1,1 ; 1 + (1) is the time over? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0,1 ; 1 + (1) is the time over? (B)
goto PLoop1 ; 2 no, loop
PDelL3 goto PDelL4 ; 2 cycles delay
PDelL4 clrwdt ; 1 cycle delay
return ; 2+2 Done
;-------------------------------------------------------------
end