You are on page 1of 12

El circuito

La fuente de alimentacin

Circuito de control

El cdigo

PROCESSOR 16F84
LIST R=DEC
INCLUDE "P16F84.INC"
#DEFINE DEMORA 4
tiempo equ 12
__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON
org 0
bsf STATUS,RP0
movlw B'00000011'
movwf TRISA
bcf STATUS,RP0
clrf PORTB
bsf STATUS,RP0
clrf TRISB
bcf STATUS,RP0
verificarPulsadores
btfsc PORTA,0
goto sentidoNormal
btfsc PORTA,1
goto sentidoInverso
movlw 0
call salida
goto verificarPulsadores
sentidoNormal
movlw B'00000001'
call salida
movlw B'00000101'
call salida
movlw B'00000100'
call salida
movlw B'00000110'
call salida
movlw B'00000010'
call salida
movlw B'00001010'
call salida
movlw B'00001000'
call salida
movlw B'00001001'
call salida
goto verificarPulsadores
sentidoInverso
movlw B'00000001'
call salida
movlw B'00001001'
call salida
movlw B'00001000'
call salida
movlw B'00001010'
call salida
movlw B'00000010'
call salida
movlw B'00000110'
call salida
movlw B'00000100'
call salida
movlw B'00000101'
call salida
goto verificarPulsadores
salida
movwf PORTB
demora
decfsz tiempo
goto demora
decfsz tiempo+1
goto demora
movlw DEMORA
movwf tiempo+1
return
end



Ahora en el archivo Retardo.inc escribiremos el siguiente cdigo:
1
2
3
4
5
6
7
#define Conta
cblock
Conta1
Conta2
Conta3
endc

8
9
10
11
12
13
14
15
16
17
18
Retardo200ms
clrf Conta1
clrf Conta2
Repeat
decfsz Conta1, F ;Salta cuando Conta1 llega a 0
bra Repeat ;Salta a Repeat para Decrementar
Conta1

decfsz Conta2, F ;Salta cuando Conta2 llega a 0
bra Repeat ;Salta a Repeat

Return
Se guardan los cambios y se continua editando el archivo fuente
como sigue:
1
2
; ********************************************************
; Desarrollo de Microcontroladores y DSPS
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
; Control de un Motor a pasos Bipolar
; Prctica 3
;
; Fecha: 15/06/2012
; Notas: Control de un motor a pasos bipolar mediante
; dos botones que controlan su direccin
;
; Autor: ek
;
**********************************************************
**
LIST P = 18F4550
INCLUDE <P18F4550.INC>
;*********************************************************
***
CONFIG FOSC = HS ;INTOSC_XT no disponible para simulacin,
usar HS
CONFIG PWRT = ON
19
2
0
21
22
23
24
25
26
27
28
29
3
0
31
32
33
CONFIG BOR = OFF
CONFIG WDT = OFF
CONFIG MCLRE = ON
CONFIG PBADEN = OFF
CONFIG LVP = OFF
CONFIG DEBUG = OFF
CONFIG XINST = OFF
; CODE
******************************************************
cblock
SecuenC ;Indice de la Secuencia
endc

ORG 0x00 ;Iniciar el programa en el registro 0x00

movlw 0x62 ;Palabra de congiguracin del OSC Interno
34
35
36
37
38
39
4
0
41
42
43
44
45
46
47
4
8
movwf OSCCON ;Configurar OSCC2ON <- W

clrf PORTD ;Borra posibles valores en PORTD
clrf PORTB ;Borra posibles valores en PORTB

movlw 0x03 ;Configurar RD0 y RD1 como entradas
movwf TRISD ;TRISD <- W
clrf TRISB ;Configurar PORTD como salida
clrf SecuenC ;Estado de Posicin a 0x00

INICIO
movf SecuenC, W
call MotorPosition
movwf PORTB
call Retardo200ms

49
50
51
52
53
54
55
56
57
58
59
6
0
61
62
63
ButtonRight ;Verificar Botn Derecho
btfss PORTD, 0 ;Verificar RB0 == 1, R == ON
bra ButtonLeft ;RB0 == 0, R == OFF
btfsc PORTD, 1 ;Verificar RB1 == 0, L == OFF
bra INICIO ;Ambos estn Presionados
bra MoveRight ;Entradas RB0 == 1, RB1 == 0
ButtonLeft ;Verificar Botn Izquierdo
btfss PORTD, 1 ;R == OFF ahora Verificar RB1 == 0, L ==
ON
bra INICIO ;Ambos estn Sueltos
bra MoveLeft

MoveRight ;Aumentar indice para la tabla
movf SecuenC, W
xorlw 0x06 ;Verificar el indice Max
btfss STATUS, Z ;Salta si Z == 1, SecuenC = Indice Max
64
65
66
67
6
8
69
70
71
72
73
74
75
76
77
78
bra Continue1
clrf SecuenC
bra INICIO
Continue1
incf SecuenC, F
incf SecuenC, F
bra INICIO

MoveLeft
movf SecuenC, W ;SecuenC -> W
xorlw 0x00 ;Comprobar si W == 0
btfss STATUS, Z ;Salta si Z == 1, SecuenC = Indice Min
bra Continue2 ;Secuence =/= 0
movlw 0x06 ;Rotar hasta Indice Max
movwf SecuenC ;Asignar Indice Max -> SecuenC
bra INICIO
79
8
0
81
82
83
8
4
85
8
6
87
8
8
8
9
9
0
91
Continue2
decf SecuenC, F
decf SecuenC, F
bra INICIO

MotorPosition
addwf PCL, F
retlw 0x0A ;0000 1010
retlw 0x09 ;0000 1001
retlw 0x05 ;0000 0101
retlw 0x06 ;0000 0110

include "Retardo.inc" ;Agregar librera Retardo.inc

END ;Fin de Programa
92
93

You might also like