2 // Firmware for the PIC on the TeleTerra ground station board for
3 // TeleMetrum, see http://altusmetrum.org/TeleTerra for more info.
5 // Copyright © 2010 Bdale Garbee <bdale@gag.com>
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.
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.
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.
20 //************************************************************
21 // Processor: PIC16F886 using internal oscillator
22 //************************************************************
24 // FIXME - cloned from clock4robert project, not ready for use yet!
26 #include "pic16f886.h"
27 // #include "signal.h" // interrupt handler / signal techniques
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
34 #define LED_TRIS TRISA7
37 // a simple delay function
38 void delay_ms(long ms)
43 for (i=0; i < 330; i++)
51 // set pins to output to wiggle LEDs
54 // // Enable high and low priority interrupts
58 // // Configure timer0
59 // T0CON = 0x88; // enable 16 bit timer, no prescaler
61 // // enable timer0 interrupt as a high priority source
62 // INTCON2bits.TMR0IP = 1;
63 // INTCONbits.TMR0IE = 1;
65 // // Enable interrupts
66 // INTCONbits.GIE = 1;
68 // sit in an endless loop blinking the alarm led
97 // ; CLRF PORTA ; Initialize port A
98 // ; CLRF PORTD ; Initialize port D
99 // ; CLRF PORTE ; Initialize port E
101 // ; CLRF TRISA ; All pins port A output
102 // ; CLRF TRISD ; All pins port D output
103 // ; CLRF TRISE ; All pins port E output
111 // ; CLRF TMR0H ; clear timer 0
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
124 // ; BCF INTCON, TMR0IF ; clear Timer0 interrupt flag
125 // ; BSF INTCON, TMR0IE ; enable Timer0 interrupt
126 // ; BSF INTCON, GIE ; enable interrupts
128 // ; ; ------------------------
129 // ; ; FUNCTION OF PORT A PINS
130 // ; ; ------------------------
133 // ; ; MOVWF CMCON ; Comparators off, all pins digital I/O
138 // ; Main CALL LpmOn ; light PM
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
153 // ; CALL LcOff ; colon off
159 // ; CALL LcOn ; colon on
167 // ; CALL LcOff ; colon off
175 // ; ; digit select 0
176 // ; Drv0On BSF LATA,2
179 // ; Drv0Off BCF LATA,2
182 // ; ; digit select 1
183 // ; Drv1On BSF LATA,3
186 // ; Drv1Off BCF LATA,3
189 // ; ; digit select 2
190 // ; Drv2On BSF LATA,4
193 // ; Drv2Off BCF LATA,4
196 // ; ; digit select 3
197 // ; Drv3On BSF LATA,5
200 // ; Drv3Off BCF LATA,5
203 // ; ; control digit segment A
204 // ; LsaOn BSF LATD,0
207 // ; LsaOff BCF LATD,0
210 // ; ; control digit segment B
211 // ; LsbOn BSF LATD,1
214 // ; LsbOff BCF LATD,1
217 // ; ; control digit segment C
218 // ; LscOn BSF LATD,2
221 // ; LscOff BCF LATD,2
224 // ; ; control digit segment D
225 // ; LsdOn BSF LATD,3
228 // ; LsdOff BCF LATD,3
231 // ; ; control digit segment E
232 // ; LseOn BSF LATD,4
235 // ; LseOff BCF LATD,4
238 // ; ; control digit segment F
239 // ; LsfOn BSF LATD,5
242 // ; LsfOff BCF LATD,5
245 // ; ; control digit segment G
246 // ; LsgOn BSF LATD,6
249 // ; LsgOff BCF LATD,6
252 // ; ; control the "AM" LED
253 // ; LamOn BSF LATE,1
256 // ; LamOff BCF LATE,1
259 // ; ; control the "PM" LED
260 // ; LpmOn BSF LATE,2
263 // ; LpmOff BCF LATE,2
266 // ; ; control the "colon" LED
270 // ; LcOff BCF LATD,7
273 // ; ; control the "alarm" LED
277 // ; LaOff BCF LATE,0
280 // ; ; ---------------
282 // ; ; ---------------
289 // ; Middle MOVLW 239
301 // ; ; ---------------
302 // ; ; High priority interrupt service route
303 // ; ; ---------------
305 // ; BCF INTCON, TMR0IF ; clear Timer0 interrupt flag
307 // ; BTFSC Counter,6 ; test bit 6
309 // ; CALL LaOff ; turn alarm LED off
312 // ; CALL LaOn ; turn alarm LED on