--- /dev/null
+;
+; Firmware for the TeleTerra ground station board for TeleMetrum,
+; see http://altusmetrum.org/TeleTerra for more information.
+;
+; Copyright © 2009 Bdale Garbee <bdale@gag.com>
+;
+; This program is free software; you can redistribute it and/or modify
+; it under the terms of the GNU General Public License as published by
+; the Free Software Foundation; version 2 of the License.
+;
+; This program is distributed in the hope that it will be useful, but
+; WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+; General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License along
+; with this program; if not, write to the Free Software Foundation, Inc.,
+; 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+;
+;************************************************************
+; Processor: PIC16F886 using internal oscillator
+;************************************************************
+
+; FIXME - more or less cloned from clock4robert project, not ready for use yet!
+
+ LIST P=18F886, R=DEC ; Use the PIC18F4550 and decimal system
+
+#include "p16f886.inc" ; Include header file
+
+ __config 0x300001, 0x22
+ __config 0x300003, 0xe
+ __config 0x300006, 0x81
+
+ CBLOCK 0x20 ; Declare variable addresses starting at 0x20
+ Loop1,Loop2,Loop3,Counter
+ ENDC
+
+; -----------
+; Vectors
+; -----------
+
+ ORG 0x0800
+ GOTO Start
+
+ ORG 0x0808
+ CALL H_PRIO_ISR
+ RETFIE
+
+ ORG 0x0818
+ RETFIE
+
+; -----------
+; INITIALIZE
+; -----------
+
+Start
+ CLRF PORTA ; Initialize port A
+ CLRF PORTD ; Initialize port D
+ CLRF PORTE ; Initialize port E
+
+ CLRF TRISA ; All pins port A output
+ CLRF TRISD ; All pins port D output
+ CLRF TRISE ; All pins port E output
+
+; CLRF WDTCON
+
+; -----------
+; Timer0
+; -----------
+
+ CLRF TMR0H ; clear timer 0
+ CLRF TMR0L
+
+; this works out to about 1.4 seconds per tick
+; MOVLW b'10000111' ; enable 16 bit timer, 256:1 prescaler
+; this works out to about 350ms per tick
+; MOVLW b'10000101' ; enable 16 bit timer, 64:1 prescaler
+; this works out to about 10.4ms per tick, or 91.6hz
+; MOVLW b'10000000' ; enable 16 bit timer, 2:1 prescaler
+; this works out to 5.46ms per tick, 183.32hz
+ MOVLW b'10001000' ; enable 16 bit timer, no prescaler
+ MOVWF T0CON
+
+ BCF INTCON, TMR0IF ; clear Timer0 interrupt flag
+ BSF INTCON, TMR0IE ; enable Timer0 interrupt
+ BSF INTCON, GIE ; enable interrupts
+
+; ------------------------
+; FUNCTION OF PORT A PINS
+; ------------------------
+;
+; MOVLW 7
+; MOVWF CMCON ; Comparators off, all pins digital I/O
+;
+; ----------
+; MAIN LOOP
+; ----------
+Main CALL LpmOn ; light PM
+ CALL LamOff
+ CALL LsaOn ; light segment A
+ CALL LsbOn ; light segment B
+ CALL LscOn ; light segment C
+ CALL LsdOn ; light segment D
+ CALL LseOn ; light segment E
+ CALL LsfOn ; light segment F
+ CALL LsgOn ; light segment G
+ CALL LcOn ; colon on
+ CALL Drv0On
+ CALL Drv1Off
+ CALL Drv2Off
+ CALL Drv3Off
+ CALL delay
+ CALL LcOff ; colon off
+ CALL Drv0Off
+ CALL Drv1On
+ CALL Drv2Off
+ CALL Drv3Off
+ CALL delay
+ CALL LcOn ; colon on
+ CALL LamOn
+ CALL LpmOff
+ CALL Drv0Off
+ CALL Drv1Off
+ CALL Drv2On
+ CALL Drv3Off
+ CALL delay
+ CALL LcOff ; colon off
+ CALL Drv0Off
+ CALL Drv1Off
+ CALL Drv2Off
+ CALL Drv3On
+ CALL delay
+ GOTO Main
+
+; digit select 0
+Drv0On BSF LATA,2
+ RETURN
+
+Drv0Off BCF LATA,2
+ RETURN
+
+; digit select 1
+Drv1On BSF LATA,3
+ RETURN
+
+Drv1Off BCF LATA,3
+ RETURN
+
+; digit select 2
+Drv2On BSF LATA,4
+ RETURN
+
+Drv2Off BCF LATA,4
+ RETURN
+
+; digit select 3
+Drv3On BSF LATA,5
+ RETURN
+
+Drv3Off BCF LATA,5
+ RETURN
+
+; control digit segment A
+LsaOn BSF LATD,0
+ RETURN
+
+LsaOff BCF LATD,0
+ RETURN
+
+; control digit segment B
+LsbOn BSF LATD,1
+ RETURN
+
+LsbOff BCF LATD,1
+ RETURN
+
+; control digit segment C
+LscOn BSF LATD,2
+ RETURN
+
+LscOff BCF LATD,2
+ RETURN
+
+; control digit segment D
+LsdOn BSF LATD,3
+ RETURN
+
+LsdOff BCF LATD,3
+ RETURN
+
+; control digit segment E
+LseOn BSF LATD,4
+ RETURN
+
+LseOff BCF LATD,4
+ RETURN
+
+; control digit segment F
+LsfOn BSF LATD,5
+ RETURN
+
+LsfOff BCF LATD,5
+ RETURN
+
+; control digit segment G
+LsgOn BSF LATD,6
+ RETURN
+
+LsgOff BCF LATD,6
+ RETURN
+
+; control the "AM" LED
+LamOn BSF LATE,1
+ RETURN
+
+LamOff BCF LATE,1
+ RETURN
+
+; control the "PM" LED
+LpmOn BSF LATE,2
+ RETURN
+
+LpmOff BCF LATE,2
+ RETURN
+
+; control the "colon" LED
+LcOn BSF LATD,7
+ RETURN
+
+LcOff BCF LATD,7
+ RETURN
+
+; control the "alarm" LED
+LaOn BSF LATE,0
+ RETURN
+
+LaOff BCF LATE,0
+ RETURN
+
+; ---------------
+; DELAY 0.5 SEC
+; ---------------
+;
+;delay MOVLW 20
+delay MOVLW 10
+ MOVWF Loop1
+Outer MOVLW 250
+ MOVWF Loop2
+Middle MOVLW 239
+ MOVWF Loop3
+Inner NOP
+ NOP
+ DECFSZ Loop3,F
+ GOTO Inner
+ DECFSZ Loop2,F
+ GOTO Middle
+ DECFSZ Loop1,F
+ GOTO Outer
+ RETURN
+
+; ---------------
+; High priority interrupt service route
+; ---------------
+H_PRIO_ISR
+ BCF INTCON, TMR0IF ; clear Timer0 interrupt flag
+ INCF Counter,1
+ BTFSC Counter,6 ; test bit 6
+ GOTO TurnItOn
+ CALL LaOff ; turn alarm LED off
+ GOTO End_ISR
+TurnItOn
+ CALL LaOn ; turn alarm LED on
+End_ISR
+ RETURN
+
+ END