annotate src/hwos.asm @ 614:a32212cd5ea9

work on new battery menu
author heinrichsweikamp
date Wed, 30 Jan 2019 21:46:42 +0100
parents 6dd6b37da7c8
children 7b3903536213
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
614
a32212cd5ea9 work on new battery menu
heinrichsweikamp
parents: 612
diff changeset
3 ; File hwos.asm V2.99g
0
heinrichsweikamp
parents:
diff changeset
4 ;
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 209
diff changeset
5 ; Definition of the hwOS dive computer platform.
0
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
11 ; 2011-06-24 : [MH] Added clock speeds
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
12
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
13
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 209
diff changeset
14 #include "hwos.inc"
0
heinrichsweikamp
parents:
diff changeset
15
heinrichsweikamp
parents:
diff changeset
16 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
17 ;----------------------------- CONFIG ---------------------------------
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
18 CONFIG RETEN = OFF ; disabled - controlled by SRETEN bit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
19 CONFIG SOSCSEL = HIGH ; High Power SOSC circuit selected
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
20 CONFIG XINST = OFF ; code won't execute in extended mode
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
21 CONFIG FOSC = INTIO2 ; internal RC oscillator, no clock-out
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
22 CONFIG PLLCFG = OFF
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
23 CONFIG IESO = OFF ; disabled
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
24 CONFIG PWRTEN = OFF ; disabled, because incompatible with ICD3 (Ri-400)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
25 CONFIG BOREN = ON ; controlled with SBOREN bit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
26 CONFIG BORV = 2 ; 2.0V
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
27 CONFIG BORPWR = MEDIUM ; BORMV set to medium power level
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
28 CONFIG WDTEN = ON ; WDT controlled by SWDTEN bit setting
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
29 CONFIG WDTPS = 128 ; 1:128
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
30 CONFIG RTCOSC = SOSCREF ; RTCC uses SOSC
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
31 CONFIG MCLRE = ON ; MCLR Enabled, RG5 Disabled
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
32 CONFIG CCP2MX = PORTBE ; RE7-microcontroller mode/RB3-all other modes
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
33
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
34 hwos CODE
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
35
0
heinrichsweikamp
parents:
diff changeset
36 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
37
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
38 global init_ostc
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 209
diff changeset
39 init_ostc:
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
40 ; init oscillator
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
41 banksel common ; bank 1
0
heinrichsweikamp
parents:
diff changeset
42 movlw b'01110010'
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
43 movwf OSCCON ; 16 MHz INTOSC
0
heinrichsweikamp
parents:
diff changeset
44 movlw b'00001000'
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
45 movwf OSCCON2 ; secondary oscillator running
0
heinrichsweikamp
parents:
diff changeset
46 movlw b'00000000'
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
47 movwf OSCTUNE ; 4x PLL disable (Bit 6) - only works with 8 or 16MHz (=32 or 64MHz)
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
48
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
49 movlw d'2' ; coding for speed normal
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
50 movff WREG,cpu_speed_request ; CPU shall run with normal speed
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
51 movff WREG,cpu_speed_state ; CPU does run with normal speed
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
52
612
6dd6b37da7c8 TODO: screendump debug
heinrichsweikamp
parents: 611
diff changeset
53 ; bcf RCON,SBOREN ; brown-out off (Not needed, set in bootloader)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
54 bcf RCON,IPEN ; priority interrupts off
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
55
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
56 banksel WDTCON
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
57 movlw b'10000000'
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
58 movwf WDTCON ; setup watchdog
0
heinrichsweikamp
parents:
diff changeset
59
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
60
0
heinrichsweikamp
parents:
diff changeset
61 ; I/O Ports
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
62 banksel 0xF16 ; addresses, F16h through F5Fh, are also used by SFRs, but are not part of the access RAM
0
heinrichsweikamp
parents:
diff changeset
63
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
64 clrf REFOCON ; no reference oscillator active on REFO pin
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
65 clrf ODCON1 ; disable open drain capability
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
66 clrf ODCON2 ; disable open drain capability
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
67 clrf ODCON3 ; disable open drain capability
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
68 clrf CM1CON ; disable
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
69 clrf CM2CON ; disable
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
70 clrf CM3CON ; disable
0
heinrichsweikamp
parents:
diff changeset
71
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
72 movlw b'11000000' ; ANSEL, AN7 and AN6 -> Analog inputs, PORTA is digital
0
heinrichsweikamp
parents:
diff changeset
73 movwf ANCON0
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
74 movlw b'00000111' ; ANSEL, AN8, AN9, AN10 -> Analog input
0
heinrichsweikamp
parents:
diff changeset
75 movwf ANCON1
heinrichsweikamp
parents:
diff changeset
76 movlw b'00000010' ; ANSEL, AN17 -> Analog input
heinrichsweikamp
parents:
diff changeset
77 movwf ANCON2
heinrichsweikamp
parents:
diff changeset
78
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
79 banksel common
0
heinrichsweikamp
parents:
diff changeset
80
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
81 ; movlw b'00000000' ; 1= input -> Data TFT_high
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
82 clrf TRISA
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
83 ; movlw b'00000000' ; init port
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
84 clrf PORTA
0
heinrichsweikamp
parents:
diff changeset
85
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
86 movlw b'00000011' ; 1= input, (RB0, RB1) -> switches, RB2 -> Power_MCP, RB3 -> s8_npower, RB4 -> LED_green/rx_nreset, RB5 -> /TFT_POWER
0
heinrichsweikamp
parents:
diff changeset
87 movwf TRISB
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
88 movlw b'00111000' ; init port, rx_nreset=1 -> hard reset RX
0
heinrichsweikamp
parents:
diff changeset
89 movwf PORTB
heinrichsweikamp
parents:
diff changeset
90
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
91 movlw b'10011010' ; 1= input, (RC0, RC1) -> SOSC, RC2 -> TFT_LED_PWM, (RC3,RC4) -> I²C, RC5 -> MOSI_MS5541, (RC6, RC7) -> UART1
0
heinrichsweikamp
parents:
diff changeset
92 movwf TRISC
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
93 ; movlw b'00000000' ; init port
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
94 clrf PORTC
0
heinrichsweikamp
parents:
diff changeset
95
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
96 movlw b'00100000' ; 1= input, RD0 -> TFT_NCS, RD1 -> TFT_RS, RD2 -> TFT_NWR, RD3 -> TFT_RD, RD4 -> MOSI_Flash, RD5 -> MISO_Flash, RD6 -> CLK_Flash, RD7 -> TFT_NRESET
0
heinrichsweikamp
parents:
diff changeset
97 movwf TRISD
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
98 ; movlw b'00000000' ; init port
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
99 clrf PORTD
0
heinrichsweikamp
parents:
diff changeset
100
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
101 ; movlw b'00000000' ; 1= input, RE1 -> Power_IR, RE2 -> CS_MCP, RE3 -> LED_blue, RE4 -> power_sw1, RE5 -> Set to 1 for cR hardware
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
102 clrf TRISE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
103 movlw b'00110001' ; init port
0
heinrichsweikamp
parents:
diff changeset
104 movwf PORTE
heinrichsweikamp
parents:
diff changeset
105
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
106 movlw b'01111110' ; 1= input, (RF1, RF2, RF3, RF4, RF5) -> Analog
0
heinrichsweikamp
parents:
diff changeset
107 movwf TRISF
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
108 ; movlw b'00000000' ; init port
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
109 clrf PORTF
0
heinrichsweikamp
parents:
diff changeset
110
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
111 movlw b'00001110' ; 1= input, <7:6> not implemented, RG0 -> TX3_PIEZO_CFG, RG2 -> RX2, RG3 -> AN17_RSSI, RG4 -> SOSC_OUT, RG5 -> /RESET
0
heinrichsweikamp
parents:
diff changeset
112 movwf TRISG
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
113 movlw b'00000001' ; init port
0
heinrichsweikamp
parents:
diff changeset
114 movwf PORTG
heinrichsweikamp
parents:
diff changeset
115
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
116 ; movlw b'00000000' ; 1= input -> Data TFT_low
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
117 clrf TRISH
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
118 ; movlw b'00000000' ; init port
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
119 clrf PORTH
0
heinrichsweikamp
parents:
diff changeset
120
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
121 movlw b'10011011' ; 1= input, RJ4 -> vusb_in, RJ5 -> power_sw2, RJ6 -> CLK_MS5541, RJ7 -> MISO_MS5541
0
heinrichsweikamp
parents:
diff changeset
122 movwf TRISJ
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
123 movlw b'00100000' ; init port
0
heinrichsweikamp
parents:
diff changeset
124 movwf PORTJ
heinrichsweikamp
parents:
diff changeset
125
614
a32212cd5ea9 work on new battery menu
heinrichsweikamp
parents: 612
diff changeset
126 ; disable charger by default
a32212cd5ea9 work on new battery menu
heinrichsweikamp
parents: 612
diff changeset
127 bsf charge_disable
0
heinrichsweikamp
parents:
diff changeset
128
heinrichsweikamp
parents:
diff changeset
129 ; Timer 0
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
130 movlw b'00000001' ; timer0 with 1:4 prescaler
0
heinrichsweikamp
parents:
diff changeset
131 movwf T0CON
heinrichsweikamp
parents:
diff changeset
132
heinrichsweikamp
parents:
diff changeset
133 ; Timer 1 - Button hold-down timer
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
134 movlw b'10001100' ; 32768Hz clock source, 1:1 prescaler -> ; 30.51757813 µs/bit in TMR1L:TMR1H
0
heinrichsweikamp
parents:
diff changeset
135 movwf T1CON
heinrichsweikamp
parents:
diff changeset
136
heinrichsweikamp
parents:
diff changeset
137 ; RTCC
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
138 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM.
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
139 movlw 0x55
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
140 movwf EECON2
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
141 movlw 0xAA
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
142 movwf EECON2
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
143 bsf RTCCFG,RTCWREN ; Unlock sequence for RTCWREN
0
heinrichsweikamp
parents:
diff changeset
144 bsf RTCCFG,RTCPTR1
heinrichsweikamp
parents:
diff changeset
145 bsf RTCCFG,RTCPTR0
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
146 bsf RTCCFG,RTCEN ; Module enable
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
147 bsf RTCCFG,RTCOE ; Output enable
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
148 movlw b'00000100' ; 32768Hz SOCS on RTCC pin (PORTG,4) Bit7-5: Pullups for Port D, E and J
0
heinrichsweikamp
parents:
diff changeset
149 movwf PADCFG1
heinrichsweikamp
parents:
diff changeset
150 movlw b'11000100'
heinrichsweikamp
parents:
diff changeset
151 movwf ALRMCFG ; 1 second alarm
heinrichsweikamp
parents:
diff changeset
152 movlw d'1'
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
153 movwf ALRMRPT ; Alarm repeat counter
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
154 movlw 0x55
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
155 movwf EECON2
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
156 movlw 0xAA
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
157 movwf EECON2
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
158 bcf RTCCFG,RTCWREN ; Lock sequence for RTCWREN
0
heinrichsweikamp
parents:
diff changeset
159 banksel common
614
a32212cd5ea9 work on new battery menu
heinrichsweikamp
parents: 612
diff changeset
160
0
heinrichsweikamp
parents:
diff changeset
161 ; A/D Converter
heinrichsweikamp
parents:
diff changeset
162 movlw b'00011000' ; power off ADC, select AN6
heinrichsweikamp
parents:
diff changeset
163 movwf ADCON0
heinrichsweikamp
parents:
diff changeset
164 movlw b'00100000' ; 2.048V Vref+
heinrichsweikamp
parents:
diff changeset
165 movwf ADCON1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
166 movlw b'10001101' ; right aligned
0
heinrichsweikamp
parents:
diff changeset
167 movwf ADCON2
heinrichsweikamp
parents:
diff changeset
168
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
169 ; init serial port1 (TRISC6/7)
0
heinrichsweikamp
parents:
diff changeset
170 movlw b'00001000' ; BRG16=1
heinrichsweikamp
parents:
diff changeset
171 movwf BAUDCON1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
172 movlw .34 ; SPBRGH:SPBRG = .34 : 114285 BAUD @ 16MHz (+0.79% Error to 115200 BAUD)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
173 movwf SPBRG1 ; SPBRGH:SPBRG = .207 : 19230 BAUD @ 16MHz (-0.16% Error to 19200 BAUD)
0
heinrichsweikamp
parents:
diff changeset
174 clrf SPBRGH1 ;
204
heinrichsweikamp
parents: 200
diff changeset
175
heinrichsweikamp
parents: 200
diff changeset
176 clrf RCSTA1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
177 clrf TXSTA1 ; UART disable
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
178 bcf PORTC,6 ; TX hard to GND
0
heinrichsweikamp
parents:
diff changeset
179
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
180 ; init serial port2 (TRISG2)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
181 banksel BAUDCON2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
182 movlw b'00100000' ; BRG16=0 ; inverted for IR
0
heinrichsweikamp
parents:
diff changeset
183 movwf BAUDCON2
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
184 movlw b'00100000' ; BRGH=0, SYNC=0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
185 movwf TXSTA2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
186 movlw .102 ; SPBRGH:SPBRG = .102 : 2403 BAUD @ 16MHz
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
187 movwf SPBRG2
0
heinrichsweikamp
parents:
diff changeset
188 clrf SPBRGH2
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
189 movlw b'10010000'
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
190 movwf RCSTA2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
191 banksel common
0
heinrichsweikamp
parents:
diff changeset
192
heinrichsweikamp
parents:
diff changeset
193 ; Timer3 for IR-RX Timeout
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
194 clrf T3GCON ; reset Timer3 gate control register
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
195 movlw b'10001001' ; 1:1 prescaler -> 2 seconds@32768Hz, synced
0
heinrichsweikamp
parents:
diff changeset
196 ; 30,51757813µs/bit in TMR3L:TMR3H
heinrichsweikamp
parents:
diff changeset
197 movwf T3CON
heinrichsweikamp
parents:
diff changeset
198
heinrichsweikamp
parents:
diff changeset
199 ; SPI Module(s)
heinrichsweikamp
parents:
diff changeset
200 ; SPI2: External Flash
heinrichsweikamp
parents:
diff changeset
201 movlw b'00110000'
heinrichsweikamp
parents:
diff changeset
202 movwf SSP2CON1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
203 ; movlw b'00000000'
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
204 clrf SSP2STAT
0
heinrichsweikamp
parents:
diff changeset
205 ; ->0,25MHz Bit clock @1MHz mode (Eco)
heinrichsweikamp
parents:
diff changeset
206 ; -> 4MHz Bit clock @16MHz mode (Normal)
heinrichsweikamp
parents:
diff changeset
207 ; -> 16MHz Bit clock @64MHz mode (Fastest)
heinrichsweikamp
parents:
diff changeset
208
heinrichsweikamp
parents:
diff changeset
209 ; MSSP1 Module: I2C Master
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
210 movlw b'00101000' ; I2C master mode
0
heinrichsweikamp
parents:
diff changeset
211 movwf SSP1CON1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
212 ; movlw b'00000000'
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
213 clrf SSP1CON2
0
heinrichsweikamp
parents:
diff changeset
214 movlw 0x27
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
215 movwf SSP1ADD ; 100kHz @ 16MHz Fosc
0
heinrichsweikamp
parents:
diff changeset
216
heinrichsweikamp
parents:
diff changeset
217 ; PWM Module(s)
heinrichsweikamp
parents:
diff changeset
218 ; PWM1 for LED dimming
heinrichsweikamp
parents:
diff changeset
219 movlw b'00001100'
heinrichsweikamp
parents:
diff changeset
220 movwf CCP1CON
heinrichsweikamp
parents:
diff changeset
221 movlw b'00000001'
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
222 movwf PSTR1CON ; pulse steering disabled
0
heinrichsweikamp
parents:
diff changeset
223 movlw d'255'
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
224 movwf PR2 ; period
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
225 ; 255 is max brightness (300 mW)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
226 clrf CCPR1L ; duty cycle
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
227 clrf CCPR1H ; duty cycle
0
heinrichsweikamp
parents:
diff changeset
228 movlw T2CON_NORMAL
heinrichsweikamp
parents:
diff changeset
229 movwf T2CON
heinrichsweikamp
parents:
diff changeset
230
heinrichsweikamp
parents:
diff changeset
231 ; Timer5 for ISR-independent wait routines
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
232 clrf T5GCON ; reset Timer5 gate control register
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
233 movlw b'10001001' ; 1:1 prescaler -> 2 seconds@32768Hz, synced
0
heinrichsweikamp
parents:
diff changeset
234 ; 30,51757813µs/bit in TMR5L:TMR5H
heinrichsweikamp
parents:
diff changeset
235 movwf T5CON
heinrichsweikamp
parents:
diff changeset
236
heinrichsweikamp
parents:
diff changeset
237 ; Timer7 for 62,5ms Interrupt (Sensor states)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
238 banksel 0xF16 ; addresses, F16h through F5Fh, are also used by SFRs, but are not part of the access RAM
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
239 clrf T7GCON ; reset Timer7 gate control register
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
240 movlw b'10001001' ; 1:1 prescaler -> 2 seconds@32768Hz, synced
0
heinrichsweikamp
parents:
diff changeset
241 movwf T7CON
heinrichsweikamp
parents:
diff changeset
242 clrf TMR7L
heinrichsweikamp
parents:
diff changeset
243 movlw .248
heinrichsweikamp
parents:
diff changeset
244 movwf TMR7H ; -> Rollover after 2048 cycles -> 62,5ms
heinrichsweikamp
parents:
diff changeset
245
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
246 ; Turn off unused timer
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
247 movlw b'11000000'
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
248 movwf PMD0
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
249 movlw b'11010001'
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
250 movwf PMD1
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
251 movlw b'11010111'
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
252 movwf PMD2
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
253 movlw b'11111111'
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
254 movwf PMD3
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
255
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
256 ; CTMU
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
257 clrf CTMUCONH
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
258 clrf CTMUCONL
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
259 clrf CTMUICON
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
260 banksel common
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
261
0
heinrichsweikamp
parents:
diff changeset
262 ; Interrupts
50
ec4d8503ec45 NEW: user-selectable color schemes
heinrichsweikamp
parents: 28
diff changeset
263 movlw b'11010000'
0
heinrichsweikamp
parents:
diff changeset
264 movwf INTCON
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
265 movlw b'00001000' ; BIT7=1: pullup for PORTB disabled
0
heinrichsweikamp
parents:
diff changeset
266 movwf INTCON2
77
131e6dd9e201 BUGFIX: Potential bug to freeze the OSTC3 after battery change or update
heinrichsweikamp
parents: 58
diff changeset
267 movlw b'00000000'
0
heinrichsweikamp
parents:
diff changeset
268 movwf INTCON3
heinrichsweikamp
parents:
diff changeset
269 movlw b'00000001' ; Bit0: TMR1
heinrichsweikamp
parents:
diff changeset
270 movwf PIE1
heinrichsweikamp
parents:
diff changeset
271 movlw b'00000010' ; Bit1: TMR3
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
272 movwf PIE2
0
heinrichsweikamp
parents:
diff changeset
273 movlw b'00000000' ; Bit1: TMR5
heinrichsweikamp
parents:
diff changeset
274 movwf PIE5
heinrichsweikamp
parents:
diff changeset
275 movlw b'00100001' ; Bit0: RTCC, Bit5: UART2
heinrichsweikamp
parents:
diff changeset
276 movwf PIE3
heinrichsweikamp
parents:
diff changeset
277 movlw b'00001000' ; Bit3: TMR7
heinrichsweikamp
parents:
diff changeset
278 movwf PIE5
heinrichsweikamp
parents:
diff changeset
279
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
280 bsf power_sw1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
281 btfss power_sw1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
282 bra $-4
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
283 bsf power_sw2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
284 btfss power_sw2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
285 bra $-4
0
heinrichsweikamp
parents:
diff changeset
286
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
287 bcf active_reset_ostc_rx ; start RX from RESET
204
heinrichsweikamp
parents: 200
diff changeset
288
0
heinrichsweikamp
parents:
diff changeset
289 return
heinrichsweikamp
parents:
diff changeset
290
heinrichsweikamp
parents:
diff changeset
291 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
292 global speed_eco
heinrichsweikamp
parents:
diff changeset
293 speed_eco:
heinrichsweikamp
parents:
diff changeset
294 movlw d'1'
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
295 movff WREG,cpu_speed_request ; bank-independent
0
heinrichsweikamp
parents:
diff changeset
296 ; Done in ISR
heinrichsweikamp
parents:
diff changeset
297 return
heinrichsweikamp
parents:
diff changeset
298 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
299 global speed_normal
heinrichsweikamp
parents:
diff changeset
300 speed_normal:
heinrichsweikamp
parents:
diff changeset
301 movlw d'2'
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
302 movff WREG,cpu_speed_request ; bank-independent
0
heinrichsweikamp
parents:
diff changeset
303 ; Done in ISR
heinrichsweikamp
parents:
diff changeset
304 return
heinrichsweikamp
parents:
diff changeset
305 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
306 global speed_fastest
heinrichsweikamp
parents:
diff changeset
307 speed_fastest:
heinrichsweikamp
parents:
diff changeset
308 movlw d'3'
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
309 movff WREG,cpu_speed_request ; bank-independent
0
heinrichsweikamp
parents:
diff changeset
310 ; Done in ISR
heinrichsweikamp
parents:
diff changeset
311 return
heinrichsweikamp
parents:
diff changeset
312 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
313
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
314 END