Mercurial > public > hwos_code
annotate src/ostc3.asm @ 199:800f09c9089c
minor
author | heinrichsweikamp |
---|---|
date | Tue, 11 Nov 2014 16:55:39 +0100 |
parents | a004b482604a |
children | dcd513840c6c |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File ostc3.asm | |
4 ; | |
5 ; Definition of the ostc3 dive computer platform. | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code. | |
11 ; 2011-06-24 : [MH] Added clock speeds. | |
12 #include "ostc3.inc" | |
13 | |
14 ;============================================================================= | |
15 ;----------------------------- CONFIG --------------------------------- | |
1 | 16 CONFIG RETEN = OFF ;Disabled - Controlled by SRETEN bit |
17 CONFIG SOSCSEL = HIGH ;High Power SOSC circuit selected | |
199 | 18 CONFIG XINST = OFF ;Code won't excute in extended mode... |
1 | 19 CONFIG FOSC = INTIO2 ;Internal RC oscillator, no clock-out |
20 CONFIG PLLCFG = OFF | |
21 CONFIG IESO = OFF ;Disabled | |
22 CONFIG PWRTEN = OFF ;Disabled, because incompatible with ICD3 (Ri-400) | |
23 CONFIG BOREN = ON ;Controlled with SBOREN bit | |
24 CONFIG BORV = 2 ;2.0V | |
25 CONFIG BORPWR = MEDIUM ;BORMV set to medium power level | |
26 CONFIG WDTEN = ON ;WDT controlled by SWDTEN bit setting | |
27 CONFIG WDTPS = 128 ;1:128 | |
28 CONFIG RTCOSC = SOSCREF ;RTCC uses SOSC | |
29 CONFIG MCLRE = ON ;MCLR Enabled, RG5 Disabled | |
30 CONFIG CCP2MX = PORTBE ;RE7-Microcontroller Mode/RB3-All other modes | |
0 | 31 ;============================================================================= |
32 boot CODE | |
33 global init_ostc3 | |
34 | |
35 init_ostc3: | |
36 banksel common ; Bank1 | |
37 ;init oscillator | |
38 movlw b'01110010' | |
39 movwf OSCCON ; 16MHz INTOSC | |
40 movlw b'00001000' | |
41 movwf OSCCON2 ; Secondary Oscillator running | |
42 movlw b'00000000' | |
43 movwf OSCTUNE ; 4x PLL Disable (Bit6) - only works with 8 or 16MHz (=32 or 64MHz) | |
44 bcf RCON,SBOREN ; Bown-Out off | |
45 bcf RCON,IPEN ; Priority Interrupts off | |
199 | 46 banksel WDTCON |
47 movlw b'10000000' | |
48 movwf WDTCON ; Setup Watchdog | |
0 | 49 |
50 ; I/O Ports | |
51 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
52 | |
53 clrf REFOCON ; No reference oscillator active on REFO pin | |
54 clrf ODCON1 ; Disable Open Drain capability | |
55 clrf ODCON2 ; Disable Open Drain capability | |
56 clrf ODCON3 ; Disable Open Drain capability | |
57 | |
58 movlw b'11000000' ; ANSEL, AN7 and AN6 -> Analog inputs, PORTA is digital. | |
59 movwf ANCON0 | |
113 | 60 movlw b'00000111' ; ANSEL, AN8, AN9, AN10 -> Analog in |
0 | 61 movwf ANCON1 |
62 movlw b'00000010' ; ANSEL, AN17 -> Analog input | |
63 movwf ANCON2 | |
64 | |
65 banksel common | |
66 | |
67 movlw b'00000000' ; 1= Input -> Data TFT_high | |
68 movwf TRISA | |
69 movlw b'00000000' ; Init port | |
70 movwf PORTA | |
71 | |
113 | 72 movlw b'00000011' ; 1= Input, (RB0, RB1) -> Switches, RB2 -> Power_MCP, RB3 -> s8_npower, RB4 -> LED_green, RB5 -> /TFT_POWER |
0 | 73 movwf TRISB |
113 | 74 movlw b'00101000' ; Init port |
0 | 75 movwf PORTB |
76 | |
77 movlw b'10011010' ; 1= Input, (RC0, RC1) -> SOSC, RC2 -> TFT_LED_PWM, (RC3,RC4) -> I²C, RC5 -> MOSI_MS5541, (RC6, RC7) -> UART1 | |
78 movwf TRISC | |
79 movlw b'00000000' ; Init port | |
80 movwf PORTC | |
81 | |
82 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 | |
83 movwf TRISD | |
84 movlw b'00000000' ; Init port | |
85 movwf PORTD | |
86 | |
186 | 87 movlw b'00000000' ; 1= Input, RE1 -> Power_IR, RE2 -> CS_MCP, RE3 -> LED_blue, RE4 -> power_sw1, RE5 -> Set to 1 for C3 hardware |
0 | 88 movwf TRISE |
186 | 89 movlw b'00110000' ; Init port |
0 | 90 movwf PORTE |
91 | |
113 | 92 movlw b'00111110' ; 1= Input, (RF1, RF2, RF3, RF4, RF5) -> Analog |
0 | 93 movwf TRISF |
94 movlw b'00000000' ; Init port | |
95 movwf PORTF | |
96 | |
113 | 97 movlw b'00001110' ; 1= Input, <7:6> not implemented, RG0 -> TX3_PIEZO_CFG, RG2 -> RX2, RG3 -> AN17_RSSI, RG4 -> SOSC_OUT, RG5 -> /RESET |
0 | 98 movwf TRISG |
113 | 99 movlw b'00000001' ; Init port |
0 | 100 movwf PORTG |
101 | |
102 movlw b'00000000' ; 1= Input -> Data TFT_low | |
103 movwf TRISH | |
104 movlw b'00000000' ; Init port | |
105 movwf PORTH | |
106 | |
120 | 107 movlw b'10011011' ; 1= Input, RJ4 -> vusb_in, RJ5 -> power_sw2, RJ6 -> CLK_MS5541, RJ7 -> MISO_MS5541 |
0 | 108 movwf TRISJ |
109 movlw b'00100000' ; Init port | |
110 movwf PORTJ | |
111 | |
112 | |
113 ; Timer 0 | |
28 | 114 movlw b'00000001' ; Timer0 with 1:4 prescaler |
115 ; movlw b'00001000' ; Timer0 with 1:1 prescaler | |
0 | 116 movwf T0CON |
117 | |
118 ; Timer 1 - Button hold-down timer | |
119 movlw b'10001100' ; 32768Hz clock source, 1:1 Prescaler -> ; 30,51757813µs/bit in TMR1L:TMR1H | |
120 movwf T1CON | |
121 | |
122 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
123 | |
124 ; RTCC | |
125 movlw 0x55 | |
126 movwf EECON2 | |
127 movlw 0xAA | |
128 movwf EECON2 | |
129 bsf RTCCFG,RTCWREN ; Unlock sequence for RTCWREN | |
130 bsf RTCCFG,RTCPTR1 | |
131 bsf RTCCFG,RTCPTR0 | |
132 bsf RTCCFG,RTCEN ; Module enable | |
133 bsf RTCCFG,RTCOE ; Output enable | |
134 movlw b'00000100' ; 32768Hz SOCS on RTCC pin (PORTG,4) Bit7-5: Pullups for Port D, E and J | |
135 movwf PADCFG1 | |
136 movlw b'11000100' | |
137 movwf ALRMCFG ; 1 second alarm | |
138 movlw d'1' | |
139 movwf ALRMRPT ; Alarm repeat counter | |
140 movlw 0x55 | |
141 movwf EECON2 | |
142 movlw 0xAA | |
143 movwf EECON2 | |
144 bcf RTCCFG,RTCWREN ; Lock sequence for RTCWREN | |
145 | |
146 banksel common | |
147 ; A/D Converter | |
148 movlw b'00011000' ; power off ADC, select AN6 | |
149 movwf ADCON0 | |
150 movlw b'00100000' ; 2.048V Vref+ | |
151 movwf ADCON1 | |
152 movlw b'10001101' ; Right justified | |
153 movwf ADCON2 | |
154 | |
155 | |
156 ;init serial port1 (TRISC6/7) | |
157 movlw b'00001000' ; BRG16=1 | |
158 movwf BAUDCON1 | |
159 movlw b'00100100' ; BRGH=1, SYNC=0 | |
160 movwf TXSTA1 | |
161 movlw .34 ; SPBRGH:SPBRG = .34 : 114285 BAUD @ 16MHz (+0,79% Error to 115200 BAUD) | |
162 movwf SPBRG1 ; SPBRGH:SPBRG = .207 : 19230 BAUD @ 16MHz (-0,16% Error to 19200 BAUD) | |
163 clrf SPBRGH1 ; | |
164 movlw b'10010000' | |
165 movwf RCSTA1 | |
166 | |
167 ;init serial port2 (TRISG2) | |
168 banksel BAUDCON2 | |
113 | 169 movlw b'00100000' ; BRG16=0 ; inverted for IR |
0 | 170 movwf BAUDCON2 |
171 movlw b'00100000' ; BRGH=0, SYNC=0 | |
172 movwf TXSTA2 | |
173 movlw .102 ; SPBRGH:SPBRG = .102 : 2403 BAUD @ 16MHz | |
174 movwf SPBRG2 | |
175 clrf SPBRGH2 | |
176 movlw b'10010000' | |
177 movwf RCSTA2 | |
178 banksel common | |
179 | |
180 ; Timer3 for IR-RX Timeout | |
181 clrf T3GCON ; Reset Timer3 Gate Control register | |
182 ; movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced | |
183 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced | |
184 ; 30,51757813µs/bit in TMR3L:TMR3H | |
185 movwf T3CON | |
186 | |
187 ; SPI Module(s) | |
188 ; SPI2: External Flash | |
189 movlw b'00110000' | |
190 movwf SSP2CON1 | |
191 movlw b'00000000' | |
192 movwf SSP2STAT | |
193 ; ->0,25MHz Bit clock @1MHz mode (Eco) | |
194 ; -> 4MHz Bit clock @16MHz mode (Normal) | |
195 ; -> 16MHz Bit clock @64MHz mode (Fastest) | |
196 | |
197 ; MSSP1 Module: I2C Master | |
198 movlw b'00101000' ; I2C Master Mode | |
199 movwf SSP1CON1 | |
200 movlw b'00000000' | |
201 movwf SSP1CON2 | |
202 movlw 0x27 | |
203 movwf SSP1ADD ; 100kHz @ 16MHz Fosc | |
204 | |
205 ; PWM Module(s) | |
206 ; PWM1 for LED dimming | |
207 movlw b'00001100' | |
208 movwf CCP1CON | |
209 movlw b'00000001' | |
210 movwf PSTR1CON ; Pulse steering disabled | |
211 movlw d'255' | |
212 movwf PR2 ; Period | |
213 ; 255 is max brightness (300mW) | |
214 clrf CCPR1L ; Duty cycle | |
215 clrf CCPR1H ; Duty cycle | |
216 movlw T2CON_NORMAL | |
217 movwf T2CON | |
218 | |
219 ; Timer5 for ISR-independent wait routines | |
220 clrf T5GCON ; Reset Timer5 Gate Control register | |
221 ; movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced | |
222 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced | |
223 ; 30,51757813µs/bit in TMR5L:TMR5H | |
224 movwf T5CON | |
225 | |
226 ; Timer7 for 62,5ms Interrupt (Sensor states) | |
227 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
228 clrf T7GCON ; Reset Timer7 Gate Control register | |
229 ; movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced | |
230 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced | |
231 movwf T7CON | |
232 clrf TMR7L | |
233 movlw .248 | |
234 movwf TMR7H ; -> Rollover after 2048 cycles -> 62,5ms | |
235 | |
236 banksel common | |
237 ; Interrupts | |
50 | 238 movlw b'11010000' |
0 | 239 movwf INTCON |
77
131e6dd9e201
BUGFIX: Potential bug to freeze the OSTC3 after battery change or update
heinrichsweikamp
parents:
58
diff
changeset
|
240 movlw b'00001000' ; BIT7=1: Pullup for PORTB disabled |
0 | 241 movwf INTCON2 |
77
131e6dd9e201
BUGFIX: Potential bug to freeze the OSTC3 after battery change or update
heinrichsweikamp
parents:
58
diff
changeset
|
242 movlw b'00000000' |
0 | 243 movwf INTCON3 |
244 movlw b'00000001' ; Bit0: TMR1 | |
245 movwf PIE1 | |
246 movlw b'00000010' ; Bit1: TMR3 | |
247 movwf PIE2 | |
248 movlw b'00000000' ; Bit1: TMR5 | |
249 movwf PIE5 | |
250 movlw b'00100001' ; Bit0: RTCC, Bit5: UART2 | |
251 movwf PIE3 | |
252 movlw b'00001000' ; Bit3: TMR7 | |
253 movwf PIE5 | |
254 | |
255 bsf power_sw1 | |
58 | 256 btfss power_sw1 |
257 bra $-4 | |
0 | 258 bsf power_sw2 |
58 | 259 btfss power_sw2 |
260 bra $-4 | |
0 | 261 |
262 return | |
263 | |
264 ;============================================================================= | |
265 global speed_eco | |
266 speed_eco: | |
267 movlw d'1' | |
268 movff WREG,speed_setting ; Bank-independent | |
269 ; Done in ISR | |
270 return | |
271 ;============================================================================= | |
272 global speed_normal | |
273 speed_normal: | |
274 movlw d'2' | |
275 movff WREG,speed_setting ; Bank-independent | |
276 ; Done in ISR | |
277 return | |
278 ;============================================================================= | |
279 global speed_fastest | |
280 speed_fastest: | |
281 movlw d'3' | |
282 movff WREG,speed_setting ; Bank-independent | |
283 ; Done in ISR | |
284 return | |
285 ;============================================================================= | |
286 | |
287 END |