switch to PIC16F722, add pull-up on MCLR as Microchip suggests
[hw/teleterra] / teleterra.c
1 //
2 // Firmware for the PIC on the TeleTerra ground station board for 
3 // TeleMetrum, see http://altusmetrum.org/TeleTerra for more info.
4 // 
5 // Copyright © 2010 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 - cloned from clock4robert project, not ready for use yet!
25
26 #include "pic16f886.h"
27 // #include "signal.h"          // interrupt handler / signal techniques
28
29
30 // FIXME - these are probably not correct!
31 code char at _CONFIG1 conf1 = 0x22;   // select HS OSC
32 code char at _CONFIG2 conf2 = 0x0e;   // disable WDT
33
34 #define LED_TRIS  TRISA7
35 #define LED_PIN   RA7
36
37 // a simple delay function
38 void delay_ms(long ms)
39 {
40     long i;
41
42     while (ms--)
43         for (i=0; i < 330; i++)
44             ;
45 }
46
47
48 void main()
49 {
50
51     // set pins to output to wiggle LEDs
52     LED_TRIS = 0;
53
54 //    // Enable high and low priority interrupts
55 //    RCON = 0;
56 //    RCONbits.IPEN = 1;
57 //
58 //    // Configure timer0
59 //    T0CON = 0x88;       // enable 16 bit timer, no prescaler
60 //
61 //    // enable timer0 interrupt as a high priority source
62 //    INTCON2bits.TMR0IP = 1;
63 //    INTCONbits.TMR0IE = 1;
64 //    
65 //    // Enable interrupts
66 //    INTCONbits.GIE = 1;
67
68     // sit in an endless loop blinking the alarm led
69     for (;;)
70     {
71         LED_PIN = 0;
72         delay_ms(250);
73         LED_PIN = 1;
74         delay_ms(250);
75     }
76 }
77
78 // ; ; ----------- 
79 // ; ; Vectors
80 // ; ; ----------- 
81 // ; 
82 // ;         ORG    0x0800
83 // ;    GOTO    Start
84 // ; 
85 // ;    ORG     0x0808
86 // ;    CALL    H_PRIO_ISR
87 // ;    RETFIE
88 // ; 
89 // ;    ORG     0x0818
90 // ;    RETFIE
91 // ; 
92 // ; ; ----------- 
93 // ; ; INITIALIZE 
94 // ; ; ----------- 
95 // ; 
96 // ; Start
97 // ;         CLRF   PORTA           ; Initialize port A 
98 // ;         CLRF   PORTD           ; Initialize port D 
99 // ;         CLRF   PORTE           ; Initialize port E 
100 // ;  
101 // ;         CLRF   TRISA           ; All pins port A output 
102 // ;         CLRF   TRISD           ; All pins port D output 
103 // ;         CLRF   TRISE           ; All pins port E output 
104 // ; 
105 // ; ;  CLRF    WDTCON
106 // ; 
107 // ; ; -----------
108 // ; ; Timer0
109 // ; ; -----------
110 // ; 
111 // ;    CLRF    TMR0H           ; clear timer 0
112 // ;    CLRF    TMR0L
113 // ; 
114 // ; ;  this works out to about 1.4 seconds per tick
115 // ; ;  MOVLW   b'10000111'     ; enable 16 bit timer, 256:1 prescaler
116 // ; ;  this works out to about 350ms per tick
117 // ; ;  MOVLW   b'10000101'     ; enable 16 bit timer, 64:1 prescaler
118 // ; ;  this works out to about 10.4ms per tick, or 91.6hz
119 // ; ;  MOVLW   b'10000000'     ; enable 16 bit timer, 2:1 prescaler
120 // ; ;  this works out to 5.46ms per tick, 183.32hz
121 // ;    MOVLW   b'10001000'     ; enable 16 bit timer, no prescaler
122 // ;    MOVWF   T0CON
123 // ; 
124 // ;    BCF     INTCON, TMR0IF  ; clear Timer0 interrupt flag
125 // ;    BSF     INTCON, TMR0IE  ; enable Timer0 interrupt 
126 // ;    BSF     INTCON, GIE     ; enable interrupts
127 // ; 
128 // ; ; ------------------------ 
129 // ; ; FUNCTION OF PORT A PINS 
130 // ; ; ------------------------ 
131 // ; ; 
132 // ; ;       MOVLW    7 
133 // ; ;       MOVWF    CMCON         ; Comparators off, all pins digital I/O 
134 // ; ; 
135 // ; ; ---------- 
136 // ; ; MAIN LOOP 
137 // ; ; ---------- 
138 // ; Main       CALL    LpmOn   ; light PM
139 // ;    CALL    LamOff
140 // ;    CALL    LsaOn   ; light segment A
141 // ;    CALL    LsbOn   ; light segment B
142 // ;    CALL    LscOn   ; light segment C
143 // ;    CALL    LsdOn   ; light segment D
144 // ;    CALL    LseOn   ; light segment E
145 // ;    CALL    LsfOn   ; light segment F
146 // ;    CALL    LsgOn   ; light segment G
147 // ;    CALL    LcOn    ; colon on
148 // ;    CALL    Drv0On  
149 // ;    CALL    Drv1Off  
150 // ;    CALL    Drv2Off 
151 // ;    CALL    Drv3Off 
152 // ;    CALL    delay
153 // ;    CALL    LcOff   ; colon off
154 // ;    CALL    Drv0Off
155 // ;    CALL    Drv1On
156 // ;    CALL    Drv2Off 
157 // ;    CALL    Drv3Off 
158 // ;    CALL    delay
159 // ;    CALL    LcOn    ; colon on
160 // ;    CALL    LamOn
161 // ;    CALL    LpmOff
162 // ;    CALL    Drv0Off 
163 // ;    CALL    Drv1Off  
164 // ;    CALL    Drv2On
165 // ;    CALL    Drv3Off 
166 // ;    CALL    delay
167 // ;    CALL    LcOff   ; colon off
168 // ;    CALL    Drv0Off 
169 // ;    CALL    Drv1Off  
170 // ;    CALL    Drv2Off 
171 // ;    CALL    Drv3On
172 // ;    CALL    delay
173 // ;         GOTO    Main 
174 // ; 
175 // ; ; digit select 0
176 // ; Drv0On     BSF     LATA,2
177 // ;    RETURN
178 // ; 
179 // ; Drv0Off    BCF     LATA,2
180 // ;    RETURN
181 // ; 
182 // ; ; digit select 1
183 // ; Drv1On     BSF     LATA,3
184 // ;    RETURN
185 // ; 
186 // ; Drv1Off    BCF     LATA,3
187 // ;    RETURN
188 // ; 
189 // ; ; digit select 2
190 // ; Drv2On     BSF     LATA,4
191 // ;    RETURN
192 // ; 
193 // ; Drv2Off    BCF     LATA,4
194 // ;    RETURN
195 // ; 
196 // ; ; digit select 3
197 // ; Drv3On     BSF     LATA,5
198 // ;    RETURN
199 // ; 
200 // ; Drv3Off    BCF     LATA,5
201 // ;    RETURN
202 // ; 
203 // ; ; control digit segment A
204 // ; LsaOn      BSF     LATD,0
205 // ;    RETURN
206 // ; 
207 // ; LsaOff     BCF     LATD,0
208 // ;    RETURN
209 // ; 
210 // ; ; control digit segment B
211 // ; LsbOn      BSF     LATD,1
212 // ;    RETURN
213 // ; 
214 // ; LsbOff     BCF     LATD,1
215 // ;    RETURN
216 // ; 
217 // ; ; control digit segment C
218 // ; LscOn      BSF     LATD,2
219 // ;    RETURN
220 // ; 
221 // ; LscOff     BCF     LATD,2
222 // ;    RETURN
223 // ; 
224 // ; ; control digit segment D
225 // ; LsdOn      BSF     LATD,3
226 // ;    RETURN
227 // ; 
228 // ; LsdOff     BCF     LATD,3
229 // ;    RETURN
230 // ; 
231 // ; ; control digit segment E
232 // ; LseOn      BSF     LATD,4
233 // ;    RETURN
234 // ; 
235 // ; LseOff     BCF     LATD,4
236 // ;    RETURN
237 // ; 
238 // ; ; control digit segment F
239 // ; LsfOn      BSF     LATD,5
240 // ;    RETURN
241 // ; 
242 // ; LsfOff     BCF     LATD,5
243 // ;    RETURN
244 // ; 
245 // ; ; control digit segment G
246 // ; LsgOn      BSF     LATD,6
247 // ;    RETURN
248 // ; 
249 // ; LsgOff     BCF     LATD,6
250 // ;    RETURN
251 // ; 
252 // ; ; control the "AM" LED
253 // ; LamOn      BSF     LATE,1
254 // ;    RETURN
255 // ; 
256 // ; LamOff     BCF     LATE,1
257 // ;    RETURN
258 // ; 
259 // ; ; control the "PM" LED
260 // ; LpmOn      BSF     LATE,2
261 // ;    RETURN
262 // ; 
263 // ; LpmOff     BCF     LATE,2
264 // ;    RETURN
265 // ; 
266 // ; ; control the "colon" LED
267 // ; LcOn       BSF     LATD,7
268 // ;    RETURN
269 // ; 
270 // ; LcOff      BCF     LATD,7
271 // ;    RETURN
272 // ; 
273 // ; ; control the "alarm" LED
274 // ; LaOn       BSF     LATE,0
275 // ;    RETURN
276 // ; 
277 // ; LaOff      BCF     LATE,0
278 // ;    RETURN
279 // ; 
280 // ; ; --------------- 
281 // ; ; DELAY 0.5 SEC 
282 // ; ; --------------- 
283 // ; ; 
284 // ; ;delay   MOVLW   20 
285 // ; delay   MOVLW   10 
286 // ;         MOVWF   Loop1 
287 // ; Outer   MOVLW   250 
288 // ;         MOVWF   Loop2 
289 // ; Middle  MOVLW   239 
290 // ;         MOVWF   Loop3 
291 // ; Inner   NOP 
292 // ;         NOP 
293 // ;    DECFSZ  Loop3,F
294 // ;    GOTO    Inner
295 // ;         DECFSZ  Loop2,F 
296 // ;         GOTO    Middle
297 // ;         DECFSZ  Loop1,F 
298 // ;         GOTO    Outer 
299 // ;         RETURN 
300 // ; 
301 // ; ; --------------- 
302 // ; ; High priority interrupt service route
303 // ; ; --------------- 
304 // ; H_PRIO_ISR
305 // ;    BCF     INTCON, TMR0IF  ; clear Timer0 interrupt flag
306 // ;    INCF    Counter,1
307 // ;    BTFSC   Counter,6       ; test bit 6
308 // ;    GOTO    TurnItOn
309 // ;    CALL    LaOff           ; turn alarm LED off
310 // ;    GOTO    End_ISR
311 // ; TurnItOn
312 // ;    CALL    LaOn            ; turn alarm LED on
313 // ; End_ISR
314 // ;    RETURN
315 //  
316 //          END