629d42c057ae20b21ca4d4a973bb26805341e192
[hw/teleterra] / teleterra.asm
1 ;
2 ; Firmware for the TeleTerra ground station board for TeleMetrum,
3 ; see http://altusmetrum.org/TeleTerra for more information.
4 ;
5 ; Copyright © 2009 Bdale Garbee <bdale@gag.com>
6 ;
7 ; This program is free software; you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation; version 2 of the License.
10 ;
11 ; This program is distributed in the hope that it will be useful, but
12 ; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ; General Public License for more details.
15 ;
16 ; You should have received a copy of the GNU General Public License along
17 ; with this program; if not, write to the Free Software Foundation, Inc.,
18 ; 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 ;
20 ;************************************************************ 
21 ; Processor: PIC16F886 using internal oscillator
22 ;************************************************************ 
23
24 ; FIXME - more or less cloned from clock4robert project, not ready for use yet!
25
26         LIST P=18F886, R=DEC    ; Use the PIC18F4550 and decimal system 
27
28 #include "p16f886.inc"          ; Include header file 
29
30         __config 0x300001, 0x22
31         __config 0x300003, 0xe
32         __config 0x300006, 0x81
33
34         CBLOCK 0x20          ; Declare variable addresses starting at 0x20
35           Loop1,Loop2,Loop3,Counter
36         ENDC 
37
38 ; ----------- 
39 ; Vectors
40 ; ----------- 
41
42         ORG    0x0800
43         GOTO    Start
44
45         ORG     0x0808
46         CALL    H_PRIO_ISR
47         RETFIE
48
49         ORG     0x0818
50         RETFIE
51
52 ; ----------- 
53 ; INITIALIZE 
54 ; ----------- 
55
56 Start
57         CLRF   PORTA           ; Initialize port A 
58         CLRF   PORTD           ; Initialize port D 
59         CLRF   PORTE           ; Initialize port E 
60  
61         CLRF   TRISA           ; All pins port A output 
62         CLRF   TRISD           ; All pins port D output 
63         CLRF   TRISE           ; All pins port E output 
64
65 ;       CLRF    WDTCON
66
67 ; -----------
68 ; Timer0
69 ; -----------
70
71         CLRF    TMR0H           ; clear timer 0
72         CLRF    TMR0L
73
74 ;  this works out to about 1.4 seconds per tick
75 ;       MOVLW   b'10000111'     ; enable 16 bit timer, 256:1 prescaler
76 ;  this works out to about 350ms per tick
77 ;       MOVLW   b'10000101'     ; enable 16 bit timer, 64:1 prescaler
78 ;  this works out to about 10.4ms per tick, or 91.6hz
79 ;       MOVLW   b'10000000'     ; enable 16 bit timer, 2:1 prescaler
80 ;  this works out to 5.46ms per tick, 183.32hz
81         MOVLW   b'10001000'     ; enable 16 bit timer, no prescaler
82         MOVWF   T0CON
83
84         BCF     INTCON, TMR0IF  ; clear Timer0 interrupt flag
85         BSF     INTCON, TMR0IE  ; enable Timer0 interrupt 
86         BSF     INTCON, GIE     ; enable interrupts
87
88 ; ------------------------ 
89 ; FUNCTION OF PORT A PINS 
90 ; ------------------------ 
91
92 ;       MOVLW    7 
93 ;       MOVWF    CMCON         ; Comparators off, all pins digital I/O 
94
95 ; ---------- 
96 ; MAIN LOOP 
97 ; ---------- 
98 Main    CALL    LpmOn   ; light PM
99         CALL    LamOff
100         CALL    LsaOn   ; light segment A
101         CALL    LsbOn   ; light segment B
102         CALL    LscOn   ; light segment C
103         CALL    LsdOn   ; light segment D
104         CALL    LseOn   ; light segment E
105         CALL    LsfOn   ; light segment F
106         CALL    LsgOn   ; light segment G
107         CALL    LcOn    ; colon on
108         CALL    Drv0On  
109         CALL    Drv1Off  
110         CALL    Drv2Off 
111         CALL    Drv3Off 
112         CALL    delay
113         CALL    LcOff   ; colon off
114         CALL    Drv0Off
115         CALL    Drv1On
116         CALL    Drv2Off 
117         CALL    Drv3Off 
118         CALL    delay
119         CALL    LcOn    ; colon on
120         CALL    LamOn
121         CALL    LpmOff
122         CALL    Drv0Off 
123         CALL    Drv1Off  
124         CALL    Drv2On
125         CALL    Drv3Off 
126         CALL    delay
127         CALL    LcOff   ; colon off
128         CALL    Drv0Off 
129         CALL    Drv1Off  
130         CALL    Drv2Off 
131         CALL    Drv3On
132         CALL    delay
133         GOTO    Main 
134
135 ; digit select 0
136 Drv0On  BSF     LATA,2
137         RETURN
138
139 Drv0Off BCF     LATA,2
140         RETURN
141
142 ; digit select 1
143 Drv1On  BSF     LATA,3
144         RETURN
145
146 Drv1Off BCF     LATA,3
147         RETURN
148
149 ; digit select 2
150 Drv2On  BSF     LATA,4
151         RETURN
152
153 Drv2Off BCF     LATA,4
154         RETURN
155
156 ; digit select 3
157 Drv3On  BSF     LATA,5
158         RETURN
159
160 Drv3Off BCF     LATA,5
161         RETURN
162
163 ; control digit segment A
164 LsaOn   BSF     LATD,0
165         RETURN
166
167 LsaOff  BCF     LATD,0
168         RETURN
169
170 ; control digit segment B
171 LsbOn   BSF     LATD,1
172         RETURN
173
174 LsbOff  BCF     LATD,1
175         RETURN
176
177 ; control digit segment C
178 LscOn   BSF     LATD,2
179         RETURN
180
181 LscOff  BCF     LATD,2
182         RETURN
183
184 ; control digit segment D
185 LsdOn   BSF     LATD,3
186         RETURN
187
188 LsdOff  BCF     LATD,3
189         RETURN
190
191 ; control digit segment E
192 LseOn   BSF     LATD,4
193         RETURN
194
195 LseOff  BCF     LATD,4
196         RETURN
197
198 ; control digit segment F
199 LsfOn   BSF     LATD,5
200         RETURN
201
202 LsfOff  BCF     LATD,5
203         RETURN
204
205 ; control digit segment G
206 LsgOn   BSF     LATD,6
207         RETURN
208
209 LsgOff  BCF     LATD,6
210         RETURN
211
212 ; control the "AM" LED
213 LamOn   BSF     LATE,1
214         RETURN
215
216 LamOff  BCF     LATE,1
217         RETURN
218
219 ; control the "PM" LED
220 LpmOn   BSF     LATE,2
221         RETURN
222
223 LpmOff  BCF     LATE,2
224         RETURN
225
226 ; control the "colon" LED
227 LcOn    BSF     LATD,7
228         RETURN
229
230 LcOff   BCF     LATD,7
231         RETURN
232
233 ; control the "alarm" LED
234 LaOn    BSF     LATE,0
235         RETURN
236
237 LaOff   BCF     LATE,0
238         RETURN
239
240 ; --------------- 
241 ; DELAY 0.5 SEC 
242 ; --------------- 
243
244 ;delay   MOVLW   20 
245 delay   MOVLW   10 
246         MOVWF   Loop1 
247 Outer   MOVLW   250 
248         MOVWF   Loop2 
249 Middle  MOVLW   239 
250         MOVWF   Loop3 
251 Inner   NOP 
252         NOP 
253         DECFSZ  Loop3,F
254         GOTO    Inner
255         DECFSZ  Loop2,F 
256         GOTO    Middle
257         DECFSZ  Loop1,F 
258         GOTO    Outer 
259         RETURN 
260
261 ; --------------- 
262 ; High priority interrupt service route
263 ; --------------- 
264 H_PRIO_ISR
265         BCF     INTCON, TMR0IF  ; clear Timer0 interrupt flag
266         INCF    Counter,1
267         BTFSC   Counter,6       ; test bit 6
268         GOTO    TurnItOn
269         CALL    LaOff           ; turn alarm LED off
270         GOTO    End_ISR
271 TurnItOn
272         CALL    LaOn            ; turn alarm LED on
273 End_ISR
274         RETURN
275
276         END