-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimelapse-pic.asm
127 lines (106 loc) · 2.56 KB
/
timelapse-pic.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
; TCD - Microcontroladores
; Alexandre de Tomy Silva - 151025916
#include "p16f873a.inc"
; Configuracao de bits
__CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
; Variaveis
CBLOCK 0x20
tics ; Contador interrupcoes por minuto
giro ; Variavel que controla giro do motor
passo ; Variavel que define o tamanho do passo do motor
aux_for1 ; Variavel auxilia for
aux_for2 ; Variavel auxilia for
ENDC
ORG 0
GOTO init ; Inicio do programa
;-----Interrupcoes
ORG 4
BANKSEL INTCON
BTFSS INTCON, TMR0IF ; Se interrupcao nao foi do timer, volta
GOTO _retfie
DECFSZ tics,1 ; tics = 0 ?
GOTO loop
MOVLW d'20'
MOVWF tics ; Reseta contador de interrupcoes
CALL gira ; Rotina para girar o motor
GOTO loop
;
_retfie:
RETFIE
init:
CALL configura
MOVLW d'12'
MOVWF giro
MOVLW d'1'
MOVWF passo
loop:
BANKSEL INTCON
MOVLW b'10100000'
MOVWF INTCON
; Recebe via serial (bluetooth)
BANKSEL PIR1
BTFSS PIR1, RCIF ; Testa bit de recepcao (1 se recebeu)
GOTO loop ; Se 0, volta para o loop
BANKSEL RCREG
MOVF RCREG, W
SUBLW d'1'
BTFSS STATUS, Z
GOTO loop
INCF giro,1
GOTO loop
;ROTINAS------------------------------------------------------------------------
gira:
BANKSEL PORTB
BSF PORTB, RB0 ; Liga motor apos 20ms
CALL delay ; Rotina de delay (1-2 us)
BCF PORTB, RB0 ; Desliga motor ate novo pulso
BANKSEL PORTB
BCF PORTB, RB1
RETURN
delay: ; (2 + ((6 + NOPJ)*J) + NOPI + 6)*I = X us
MOVLW D'0'
MOVWF aux_for1
for1:
MOVlW d'0' ; 1 us
MOVWF aux_for2 ; 1 us
for2:
INCF aux_for2,1 ; 1 us
MOVF aux_for2,W ; 1 us
SUBWF giro, 0 ; 1 us
BTFSS STATUS,Z ; 1 us
GOTO for2 ; 2 us
INCF aux_for1,1 ; 1 us
MOVF aux_for1,W ; 1 us
SUBLW D'10' ; 1 us
BTFSS STATUS,Z ; 1 us
GOTO for1 ; 2 us
RETURN
configura:
; Configurar serial
BANKSEL TXSTA ; Registrador de transmissao
MOVLW b'00100110'
MOVWF TXSTA
BANKSEL RCSTA ; Registrador de recepcao
MOVLW b'10010000'
; MOVLW b'10000000'
MOVWF RCSTA
BANKSEL SPBRG ; -> Para obter BPS
MOVLW d'25'
MOVWF SPBRG ; -> baud = 9600
; Configura timer
BANKSEL OPTION_REG
MOVLW b'10000010' ; prescaler = 4
MOVWF OPTION_REG
BANKSEL TMR0
MOVLW d'131' ; -> 1000 interrupcoes por segundo
MOVWF TMR0
; Configura portas
BANKSEL TRISB
MOVLW b'11111100'
MOVWF TRISB
BANKSEL PORTB
MOVLW d'0'
MOVWF PORTB ; Zera porta b
RETURN
;-------------------------------------------------------------------------------
END