Mercurial > public > hwos_code
annotate src/hwos.asm @ 631:185ba2f91f59
3.09 beta 1 release
author | heinrichsweikamp |
---|---|
date | Fri, 28 Feb 2020 15:45:07 +0100 |
parents | 4cd81bdbf15c |
children | 4050675965ea |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
631 | 3 ; File hwos.asm combined next generation V3.08.8 |
0 | 4 ; |
275 | 5 ; Definition of the hwOS dive computer platform. |
0 | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
604 | 10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code |
11 ; 2011-06-24 : [MH] Added clock speeds | |
12 | |
623 | 13 ;============================================================================= |
14 | |
15 #DEFINE ACCESS_RAM_VARS ; the access RAM variables are declared in this file | |
604 | 16 |
275 | 17 #include "hwos.inc" |
623 | 18 #include "eeprom_rs232.inc" |
0 | 19 |
623 | 20 ;----------------------------- CONFIG ---------------------------------------- |
21 CONFIG RETEN = OFF ; disabled - controlled by SRETEN bit | |
604 | 22 CONFIG SOSCSEL = HIGH ; High Power SOSC circuit selected |
623 | 23 CONFIG XINST = OFF ; code won't execute in extended mode |
24 CONFIG FOSC = INTIO2 ; internal RC oscillator, no clock-out | |
25 CONFIG PLLCFG = OFF ; | |
26 CONFIG IESO = OFF ; disabled | |
27 CONFIG PWRTEN = OFF ; disabled, because incompatible with ICD3 (Ri-400) | |
28 CONFIG BOREN = ON ; controlled with SBOREN bit | |
29 CONFIG BORV = 2 ; 2.0V | |
30 CONFIG BORPWR = MEDIUM ; BORMV set to medium power level | |
31 CONFIG WDTEN = ON ; WDT controlled by SWDTEN bit setting | |
32 CONFIG WDTPS = 128 ; 1:128 | |
33 CONFIG RTCOSC = SOSCREF ; RTCC uses SOSC | |
34 CONFIG MCLRE = ON ; MCLR Enabled, RG5 Disabled | |
35 CONFIG CCP2MX = PORTBE ; RE7 micro-controller mode/RB3-all other modes | |
36 | |
37 | |
38 ;---------------------------- Bank0 ACCESS RAM ------------------------------- | |
39 ac_ram equ 0x000 | |
40 ac_ram udata_acs ac_ram ; access RAM data | |
41 | |
42 | |
43 ;---- Flags - Hardware Descriptors | |
44 HW_descriptor res 1 ; OSTC - model descriptor (cleared & rebuilt in restart) | |
45 HW_variants res 1 ; OSTC - model variants (NOT cleared in restart) | |
628 | 46 |
623 | 47 ;---- Flags - Hardware States |
628 | 48 HW_flags_state1 res 1 ; hardware - states 1 |
49 HW_flags_state2 res 1 ; hardware - states 2 | |
623 | 50 |
51 ;--- Flags - Operating System | |
52 OS_flags_persist res 1 ; system - persistent settings (NOT cleared in restart) | |
53 OS_flags_ISR1 res 1 ; system - ISR control 1 | |
54 OS_flags_ISR2 res 1 ; system - ISR control 2 | |
55 | |
56 ;---- Flags - Operating Modes | |
57 OM_flags_mode res 1 ; operating modes | |
58 | |
59 ;---- Flags - Dive Modes | |
60 DM_flags_deco res 1 ; dive mode - main dive & deco mode | |
61 | |
62 ;---- CPU Speed | |
63 cpu_speed_request res 1 ; requested CPU speed: =1: eco, =2: normal, =3: fastest | |
64 cpu_speed_state res 1 ; current CPU speed: =1: eco, =2: normal, =3: fastest | |
65 | |
66 ;---- Timebase & Eventbase | |
67 timebase res 1 ; timed trigger flags and running timebase | |
68 eventbase res 1 ; event trigger flags | |
69 | |
70 ;---- Timeout-Timer Service | |
71 isr_timeout_timer res 1 ; timeout timer | |
72 isr_timeout_reload res 1 ; timeout reload value | |
73 | |
74 ;---- Dive Times | |
75 total_divetime_secs res 2 ; total dive time, seconds | |
76 counted_divetime_mins res 2 ; counted dive time, minutes | Attention: do not change the position of | |
77 counted_divetime_secs res 1 ; counted dive time, seconds | these 2 Variables relative to each other! | |
604 | 78 |
623 | 79 ;---- Dive Times / Apnoe |
80 apnoe_surface_mins res 1 ; surface time minutes | Attention: do not change the position of | |
81 apnoe_surface_secs res 1 ; surface time seconds | these 2 Variables relative to each other! | |
82 | |
83 apnoe_dive_mins res 1 ; dive time minutes | Attention: do not change the position of | |
84 apnoe_dive_secs res 1 ; dive time seconds | these 2 Variables relative to each other! | |
85 | |
86 ;---- Profile Recording | |
87 sampling_rate res 1 ; configured sampling rate | |
88 sampling_timer res 1 ; sampling timer | |
89 | |
90 ;---- Simulator Mode | |
91 simulatormode_depth res 1 ; depth in simulator mode | |
92 | |
93 ;---- HUD / Sensor Data | |
94 hud_status_byte res 1 ; HUD status byte, see definition of flags | Attention: keep relative position | |
95 hud_battery_mv res 2 ; hud/ppo2 monitor battery voltage in mV | between these two variables! | |
96 | |
97 | |
98 ; 28 byte user data | |
99 ; 32 byte tmp data placed by C compiler | |
100 ; 20 byte variables placed by math library | |
101 ; == | |
628 | 102 ; 80 byte used, 16 byte free (96 byte total available) |
623 | 103 |
631 | 104 |
623 | 105 global HW_descriptor |
106 global HW_variants | |
628 | 107 global HW_flags_state1 |
108 global HW_flags_state2 | |
623 | 109 global OS_flags_persist |
110 global OS_flags_ISR1 | |
111 global OS_flags_ISR2 | |
112 global OM_flags_mode | |
113 global DM_flags_deco | |
114 global cpu_speed_request | |
115 global cpu_speed_state | |
116 global timebase | |
117 global eventbase | |
118 global isr_timeout_timer | |
119 global isr_timeout_reload | |
120 global total_divetime_secs | |
121 global counted_divetime_mins | |
122 global counted_divetime_secs | |
123 global apnoe_surface_secs | |
124 global apnoe_surface_mins | |
125 global apnoe_dive_secs | |
126 global apnoe_dive_mins | |
127 global sampling_rate | |
128 global sampling_timer | |
129 global simulatormode_depth | |
130 global hud_status_byte | |
131 global hud_battery_mv | |
132 | |
133 ;----------------------------------------------------------------------------- | |
134 | |
135 hwos CODE | |
604 | 136 |
0 | 137 ;============================================================================= |
138 | |
604 | 139 global init_ostc |
275 | 140 init_ostc: |
623 | 141 |
142 ; Oscillator | |
143 banksel common ; select bank common | |
0 | 144 movlw b'01110010' |
604 | 145 movwf OSCCON ; 16 MHz INTOSC |
0 | 146 movlw b'00001000' |
604 | 147 movwf OSCCON2 ; secondary oscillator running |
0 | 148 movlw b'00000000' |
604 | 149 movwf OSCTUNE ; 4x PLL disable (Bit 6) - only works with 8 or 16MHz (=32 or 64MHz) |
608 | 150 |
623 | 151 movlw coding_speed_normal ; coding for normal CPU speed |
152 movwf cpu_speed_request ; store CPU shall run with normal speed | |
153 movwf cpu_speed_state ; store CPU does run with normal speed | |
608 | 154 |
623 | 155 ;bcf RCON,SBOREN ; brown-out off (not needed here, is handled in bootloader) |
604 | 156 bcf RCON,IPEN ; priority interrupts off |
608 | 157 |
604 | 158 banksel WDTCON |
159 movlw b'10000000' | |
160 movwf WDTCON ; setup watchdog | |
0 | 161 |
608 | 162 |
0 | 163 ; I/O Ports |
604 | 164 banksel 0xF16 ; addresses, F16h through F5Fh, are also used by SFRs, but are not part of the access RAM |
165 clrf REFOCON ; no reference oscillator active on REFO pin | |
166 clrf ODCON1 ; disable open drain capability | |
167 clrf ODCON2 ; disable open drain capability | |
168 clrf ODCON3 ; disable open drain capability | |
608 | 169 clrf CM1CON ; disable |
604 | 170 clrf CM2CON ; disable |
171 clrf CM3CON ; disable | |
0 | 172 |
604 | 173 movlw b'11000000' ; ANSEL, AN7 and AN6 -> Analog inputs, PORTA is digital |
0 | 174 movwf ANCON0 |
604 | 175 movlw b'00000111' ; ANSEL, AN8, AN9, AN10 -> Analog input |
0 | 176 movwf ANCON1 |
177 movlw b'00000010' ; ANSEL, AN17 -> Analog input | |
178 movwf ANCON2 | |
604 | 179 banksel common |
0 | 180 |
604 | 181 ; movlw b'00000000' ; 1= input -> Data TFT_high |
448 | 182 clrf TRISA |
604 | 183 ; movlw b'00000000' ; init port |
448 | 184 clrf PORTA |
0 | 185 |
604 | 186 movlw b'00000011' ; 1= input, (RB0, RB1) -> switches, RB2 -> Power_MCP, RB3 -> s8_npower, RB4 -> LED_green/rx_nreset, RB5 -> /TFT_POWER |
0 | 187 movwf TRISB |
604 | 188 movlw b'00111000' ; init port, rx_nreset=1 -> hard reset RX |
0 | 189 movwf PORTB |
190 | |
604 | 191 movlw b'10011010' ; 1= input, (RC0, RC1) -> SOSC, RC2 -> TFT_LED_PWM, (RC3,RC4) -> I²C, RC5 -> MOSI_MS5541, (RC6, RC7) -> UART1 |
0 | 192 movwf TRISC |
604 | 193 ; movlw b'00000000' ; init port |
448 | 194 clrf PORTC |
0 | 195 |
604 | 196 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 | 197 movwf TRISD |
604 | 198 ; movlw b'00000000' ; init port |
448 | 199 clrf PORTD |
0 | 200 |
628 | 201 movlw b'00100000' ; 1= input, RE0 -> not_Power_BLE, RE1 -> Power_IR, RE2 -> CS_MCP, RE3 -> LED_blue, RE4 -> power_sw1, RE5 -> leave as input |
627 | 202 movwf TRISE |
203 movlw b'00010001' ; init port | |
0 | 204 movwf PORTE |
205 | |
604 | 206 movlw b'01111110' ; 1= input, (RF1, RF2, RF3, RF4, RF5) -> Analog |
0 | 207 movwf TRISF |
604 | 208 ; movlw b'00000000' ; init port |
448 | 209 clrf PORTF |
0 | 210 |
628 | 211 movlw b'00001110' ; 1= input, <7:6> not implemented, RG0 -> TX3_PIEZO_CFG, , RG1 -> TX2, RG2 -> RX2, RG3 -> AN17_RSSI, RG4 -> SOSC_OUT, RG5 -> /RESET |
0 | 212 movwf TRISG |
604 | 213 movlw b'00000001' ; init port |
0 | 214 movwf PORTG |
215 | |
604 | 216 ; movlw b'00000000' ; 1= input -> Data TFT_low |
448 | 217 clrf TRISH |
604 | 218 ; movlw b'00000000' ; init port |
448 | 219 clrf PORTH |
0 | 220 |
623 | 221 movlw b'10011011' ; 1= input, RJ4 -> vusb_in, RJ5 -> power_sw2, RJ6 -> CLK_MS5541, RJ7 -> MISO_MS5541 |
0 | 222 movwf TRISJ |
604 | 223 movlw b'00100000' ; init port |
0 | 224 movwf PORTJ |
225 | |
623 | 226 |
618 | 227 ; disable Charger by default |
623 | 228 bsf charge_disable ; set charging-inhibit signal |
229 bcf charge_enable ; activate charging-inhibit signal | |
230 | |
231 | |
0 | 232 ; Timer 0 |
604 | 233 movlw b'00000001' ; timer0 with 1:4 prescaler |
0 | 234 movwf T0CON |
235 | |
623 | 236 |
0 | 237 ; Timer 1 - Button hold-down timer |
623 | 238 movlw b'10001100' ; 32768 Hz clock source, 1:1 prescaler -> ; 30.51757813 µs/bit in TMR1L:TMR1H |
0 | 239 movwf T1CON |
240 | |
623 | 241 |
0 | 242 ; RTCC |
623 | 243 banksel 0xF16 ; addresses, F16h through F5Fh, are also used by SFRs, but are not part of the access RAM |
244 movlw 0x55 | |
245 movwf EECON2 | |
246 movlw 0xAA | |
247 movwf EECON2 | |
248 bsf RTCCFG,RTCWREN ; unlock sequence for RTCWREN | |
0 | 249 bsf RTCCFG,RTCPTR1 |
250 bsf RTCCFG,RTCPTR0 | |
623 | 251 bsf RTCCFG,RTCEN ; module enable |
252 bsf RTCCFG,RTCOE ; output enable | |
253 movlw b'00000100' ; 32768 Hz SOCS on RTCC pin (PORTG,4) Bit7-5: pull-ups for Port D, E and J | |
0 | 254 movwf PADCFG1 |
623 | 255 movlw b'11000000' |
256 movwf ALRMCFG ; 1/2 second alarm | |
0 | 257 movlw d'1' |
623 | 258 movwf ALRMRPT ; alarm repeat counter |
259 movlw 0x55 | |
260 movwf EECON2 | |
261 movlw 0xAA | |
262 movwf EECON2 | |
263 bcf RTCCFG,RTCWREN ; lock sequence for RTCWREN | |
264 banksel common | |
265 | |
614 | 266 |
0 | 267 ; A/D Converter |
268 movlw b'00011000' ; power off ADC, select AN6 | |
269 movwf ADCON0 | |
270 movlw b'00100000' ; 2.048V Vref+ | |
271 movwf ADCON1 | |
631 | 272 movlw b'10111010' ; right aligned, 20 x T_AD acquisition time, FOSC/32 -> max. 40 MHz device clock speed |
0 | 273 movwf ADCON2 |
274 | |
623 | 275 |
276 ; serial Port 1 (TRISC6/7) | |
631 | 277 movlw b'00001000' ; switch baud generator to 16 bit mode (BRG16=1) |
278 movwf BAUDCON1 ; ... | |
279 ; SPBRGH:SPBRG = .34 : 114285 BAUD @ 16MHz (+0.79% error at 115200 baud) | |
280 ; SPBRGH:SPBRG = .207 : 19230 BAUD @ 16MHz (-0.16% error at 19200 baud) | |
281 movlw .34 ; select 114285 baud (low byte) | |
282 movwf SPBRG1 ; ... | |
283 clrf SPBRGH1 ; ... (high byte) | |
204 | 284 |
631 | 285 clrf RCSTA1 ; disable UART RX |
286 clrf TXSTA1 ; disable UART TX | |
287 bcf PORTC,6 ; tie TX output hard to GND | |
0 | 288 |
623 | 289 |
290 ; serial Port 2 (TRISG2) for IR/S8 digital interface | |
291 ; | |
292 ; - will be initialized by enable_ir_s8 (eeprom_rs232.asm) in case IR/S8 shall be available | |
293 | |
0 | 294 |
623 | 295 ; Timer 3 for IR-RX Timeout |
296 IFDEF _external_sensor | |
604 | 297 clrf T3GCON ; reset Timer3 gate control register |
629 | 298 movlw b'10001101' ; not synced, 1:1 prescaler -> 2 seconds till overrun @ 32768 Hz, |
623 | 299 ; incrementing by 1 bit each 30.51757813 µs |
0 | 300 movwf T3CON |
623 | 301 ENDIF |
302 | |
0 | 303 |
304 ; SPI Module(s) | |
305 ; SPI2: External Flash | |
306 movlw b'00110000' | |
307 movwf SSP2CON1 | |
448 | 308 ; movlw b'00000000' |
309 clrf SSP2STAT | |
623 | 310 ; -> 0.25 MHz Bit clock @ 1 MHz mode (Eco) |
311 ; -> 4 MHz Bit clock @ 16 MHz mode (Normal) | |
312 ; -> 16 MHz Bit clock @ 64 MHz mode (Fastest) | |
313 | |
0 | 314 |
315 ; MSSP1 Module: I2C Master | |
604 | 316 movlw b'00101000' ; I2C master mode |
0 | 317 movwf SSP1CON1 |
448 | 318 ; movlw b'00000000' |
319 clrf SSP1CON2 | |
628 | 320 movlw 0x9C |
321 movwf SSP1ADD ; 100kHz @ 64MHz Fosc | |
0 | 322 |
623 | 323 |
0 | 324 ; PWM Module(s) |
623 | 325 ; PWM 1 for LED dimming |
0 | 326 movlw b'00001100' |
327 movwf CCP1CON | |
328 movlw b'00000001' | |
604 | 329 movwf PSTR1CON ; pulse steering disabled |
628 | 330 movlw d'254' |
604 | 331 movwf PR2 ; period |
332 ; 255 is max brightness (300 mW) | |
333 clrf CCPR1L ; duty cycle | |
334 clrf CCPR1H ; duty cycle | |
0 | 335 movlw T2CON_NORMAL |
336 movwf T2CON | |
337 | |
623 | 338 |
339 ; Timer 5 for ISR-independent wait routines | |
604 | 340 clrf T5GCON ; reset Timer5 gate control register |
629 | 341 movlw b'10001111' ; not synced, 16 bit mode, 1:1 prescaler -> 2 seconds till overrun @ 32768 Hz, |
623 | 342 movwf T5CON ; incrementing by 1 bit each 30.51757813 µs |
343 | |
0 | 344 |
623 | 345 banksel 0xF16 ; addresses F16h through F5Fh are also used by SFRs, but are not part of the access RAM |
346 | |
347 ; Timer 7 for 62.5 ms Interrupt (sensor states) | |
604 | 348 clrf T7GCON ; reset Timer7 gate control register |
629 | 349 movlw b'10001101' ; 1:1 prescaler -> 2 seconds @ 32768 Hz, not synced |
0 | 350 movwf T7CON |
351 clrf TMR7L | |
352 movlw .248 | |
623 | 353 movwf TMR7H ; -> rollover after 2048 cycles -> 62.5 ms |
0 | 354 |
623 | 355 |
356 ; turn off unused timers | |
608 | 357 movlw b'11000000' |
358 movwf PMD0 | |
623 | 359 IFDEF _external_sensor |
608 | 360 movlw b'11010001' |
623 | 361 ELSE |
362 movlw b'11011001' ; includes turning off timer 3 | |
363 ENDIF | |
608 | 364 movwf PMD1 |
365 movlw b'11010111' | |
366 movwf PMD2 | |
367 movlw b'11111111' | |
368 movwf PMD3 | |
369 | |
623 | 370 |
371 ; turn off unused CTMU | |
608 | 372 clrf CTMUCONH |
373 clrf CTMUCONL | |
374 clrf CTMUICON | |
623 | 375 |
604 | 376 banksel common |
608 | 377 |
623 | 378 |
0 | 379 ; Interrupts |
50 | 380 movlw b'11010000' |
0 | 381 movwf INTCON |
623 | 382 movlw b'00001000' ; Bit7=1: pull-up for PORTB disabled |
0 | 383 movwf INTCON2 |
77
131e6dd9e201
BUGFIX: Potential bug to freeze the OSTC3 after battery change or update
heinrichsweikamp
parents:
58
diff
changeset
|
384 movlw b'00000000' |
0 | 385 movwf INTCON3 |
386 movlw b'00000001' ; Bit0: TMR1 | |
387 movwf PIE1 | |
388 movlw b'00000010' ; Bit1: TMR3 | |
604 | 389 movwf PIE2 |
0 | 390 movlw b'00000000' ; Bit1: TMR5 |
391 movwf PIE5 | |
629 | 392 movlw b'00000001' ; Bit0: RTCC, Bit5: UART2 (Default OFF) |
0 | 393 movwf PIE3 |
394 movlw b'00001000' ; Bit3: TMR7 | |
395 movwf PIE5 | |
396 | |
623 | 397 bcf active_reset_ostc_rx ; release RESET from RX circuitry |
398 ;bra power_up_switches | |
399 | |
0 | 400 |
623 | 401 global power_up_switches |
402 power_up_switches: | |
403 bsf power_sw1 ; switch on power supply for switch 1 | |
404 btfss power_sw1 ; power established? | |
405 bra $-4 ; NO - wait | |
406 bsf power_sw2 ; switch on power supply for switch 2 | |
407 btfss power_sw2 ; power established? | |
408 bra $-4 ; NO - wait | |
204 | 409 |
0 | 410 return |
411 | |
412 ;============================================================================= | |
623 | 413 ; CPU speed change request functions |
414 | |
415 global request_speed_eco | |
416 request_speed_eco: | |
417 movlw coding_speed_eco ; load coding for eco speed | |
418 movwf cpu_speed_request ; request ISR to change the CPU speed | |
419 return ; done | |
420 | |
421 global request_speed_normal | |
422 request_speed_normal: | |
423 movlw coding_speed_normal ; load coding for normal speed | |
424 movwf cpu_speed_request ; request ISR to change the CPU speed | |
425 return ; done | |
426 | |
427 global request_speed_fastest | |
428 request_speed_fastest: | |
429 movlw coding_speed_fastest ; load coding for fastest speed | |
430 movwf cpu_speed_request ; request ISR to change the CPU speed | |
431 return ; done | |
432 | |
0 | 433 ;============================================================================= |
623 | 434 ; Backup the first 128 bytes from program memory to EEPROM |
435 ; | |
436 global backup_flash_page | |
437 backup_flash_page: | |
438 banksel common | |
631 | 439 |
440 ; set start address in internal program memory | |
441 movlw 0x00 ; set 0x000000 | |
442 movwf TBLPTRL ; ... | |
443 movwf TBLPTRH ; ... | |
444 movwf TBLPTRU ; ... | |
445 TBLRD*- ; dummy read to be in 128 byte block | |
446 | |
447 ; set start address in EEPROM | |
448 EEPROM_SET_ADDRESS eeprom_prog_page0_backup | |
623 | 449 |
450 movlw .128 ; copy 1 block = 128 byte | |
631 | 451 movwf eeprom_loop ; initialize loop counter |
623 | 452 backup_flash_loop: |
453 tblrd+* ; read one byte from program memory (with pre-increment) | |
454 movff TABLAT,EEDATA ; transfer byte from program memory read to EEPROM write | |
631 | 455 call write_eeprom ; execute EEPROM write |
623 | 456 incf EEADR,F ; increment EEPROM address |
631 | 457 decfsz eeprom_loop,F ; all 128 byte done? |
623 | 458 bra backup_flash_loop ; NO - loop |
631 | 459 return ; YES - done |
623 | 460 |
0 | 461 ;============================================================================= |
623 | 462 ; Restore the first 128 bytes from EEPROM to program memory |
463 ; | |
464 global restore_flash | |
465 restore_flash: | |
466 banksel common | |
631 | 467 |
468 ;set start address in internal program memory | |
469 movlw 0x00 ; set 0x000000 | |
470 movwf TBLPTRL ; ... | |
471 movwf TBLPTRH ; ... | |
472 movwf TBLPTRU ; ... | |
473 TBLRD*- ; dummy read to be in 128 byte block | |
623 | 474 |
475 movlw b'10010100' ; setup block erase | |
476 rcall restore_write ; execute block erase | |
477 | |
631 | 478 ; set start address in EEPROM |
479 EEPROM_SET_ADDRESS eeprom_prog_page0_backup | |
623 | 480 |
631 | 481 movlw .128 ; copy 1 block = 128 byte |
482 movwf eeprom_loop ; initialize loop counter | |
623 | 483 restore_flash_loop: |
631 | 484 call read_eeprom ; execute EEPROM read |
623 | 485 incf EEADR,F ; increment EEPROM address |
486 movff EEDATA,TABLAT ; transfer byte from EEPROM read to program memory write | |
487 tblwt+* ; execute program memory write (with pre-increment) | |
631 | 488 decfsz eeprom_loop,F ; all 128 bytes done? |
489 bra restore_flash_loop ; NO - loop | |
623 | 490 movlw b'10000100' ; YES - setup block write |
491 rcall restore_write ; - execute block write | |
492 reset ; - done, reset CPU | |
493 | |
494 restore_write: | |
631 | 495 movwf EECON1 ; configure operation |
496 movlw 0x55 ; unlock sequence | |
497 movwf EECON2 ; ... | |
498 movlw 0xAA ; ... | |
499 movwf EECON2 ; ... | |
500 bsf EECON1,WR ; execute operation | |
501 nop ; wait for operation to complete | |
502 nop ; ... | |
503 return ; done | |
504 | |
505 ;============================================================================= | |
506 ; Memory clear and move functions, to be used through macros | |
507 ; | |
508 global memory_clear | |
509 memory_clear: | |
510 clrf POSTINC1 ; clear address | |
511 decfsz WREG ; decrement loop counter, became zero? | |
512 bra memory_clear ; NO - loop | |
513 return ; YES - done | |
514 | |
515 global memory_move | |
516 memory_move: | |
517 movff POSTINC1,POSTINC2 ; copy from-to | |
518 decfsz WREG ; decrement loop counter, became zero? | |
519 bra memory_move ; NO - loop | |
520 return ; YES - done | |
0 | 521 |
604 | 522 END |