annotate src/hwos.asm @ 644:1e695355dfc4

Merge
author heinrichsweikamp
date Mon, 24 May 2021 18:41:51 +0200
parents 7d8a4c60ec1a
children 070528a88715 357341239438
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
3 ; File hwos.asm * combined next generation V3.09.4e
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
13 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
14
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
15 #DEFINE INSIDE_HWOS_ASM
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
16
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 209
diff changeset
17 #include "hwos.inc"
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
18 #include "eeprom_rs232.inc"
0
heinrichsweikamp
parents:
diff changeset
19
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
20 ;----------------------------- PIC Configuration -----------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
21 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
22 CONFIG RETEN = OFF ; regulator power while in sleep mode controlled by SRETEN bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
23 CONFIG SOSCSEL = HIGH ; high power SOSC circuit selected
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
24 CONFIG XINST = OFF ; extended instruction set disabled
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
25 CONFIG FOSC = INTIO2 ; internal RC oscillator, no clock-out
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
26 CONFIG PLLCFG = OFF ; oscillator used directly
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
27 CONFIG IESO = OFF ; two-speed start-up disabled
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
28 CONFIG PWRTEN = OFF ; power-up timer disabled, because incompatible with ICD3 (Ri-400)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
29 CONFIG BOREN = ON ; brown-out reset controlled with SBOREN bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
30 CONFIG BORV = 2 ; brown-out reset voltage 2.0V
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
31 CONFIG BORPWR = MEDIUM ; brown-out monitoring set to medium power level
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
32 CONFIG WDTEN = ON ; watchdog timer enabled, controlled by SWDTEN bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
33 CONFIG WDTPS = 128 ; watchdog timer post-scaler 1:128
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
34 CONFIG RTCOSC = SOSCREF ; RTCC uses SOSC as ref clock
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
35 CONFIG MCLRE = ON ; MCLR enabled, RG5 disabled
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
36 CONFIG CCP2MX = PORTBE ; ECCP2 muxed with RE7 (micro-controller mode) /RB3 (other modes)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
37
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
38
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
39 ;---------------------------- Bank0 ACCESS RAM -------------------------------
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
40 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
41 ac_ram equ 0x000
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
42 ac_ram udata_acs ac_ram ; access RAM data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
43
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
44
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
45 ;---- Flags - Hardware Descriptors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
46 HW_descriptor res 1 ; OSTC - model descriptor (cleared & rebuilt in restart)
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 642
diff changeset
47 HW_variants res 1 ; OSTC - model variants (NOT cleared in restart)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 642
diff changeset
48 HW_variants2 res 1 ; OSTC - more model variants (NOT cleared in restart)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 642
diff changeset
49
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
50 ;---- Flags - Hardware States
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
51 HW_flags_state1 res 1 ; hardware - states 1
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
52 HW_flags_state2 res 1 ; hardware - states 2
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 642
diff changeset
53 HW_flags_state3 res 1 ; hardware - states 3
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
54
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
55 ;--- Flags - Operating System
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
56 OS_flags_persist res 1 ; system - persistent settings (NOT cleared in restart)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
57 OS_flags_ISR1 res 1 ; system - ISR control 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
58 OS_flags_ISR2 res 1 ; system - ISR control 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
59
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
60 ;---- Flags - Operating Modes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
61 OM_flags_mode res 1 ; operating modes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
62
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
63 ;---- Flags - Dive Modes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
64 DM_flags_deco res 1 ; dive mode - main dive & deco mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
65
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
66 ;---- CPU Speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
67 cpu_speed_request res 1 ; requested CPU speed: =1: eco, =2: normal, =3: fastest
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
68 cpu_speed_state res 1 ; current CPU speed: =1: eco, =2: normal, =3: fastest
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
69
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
70 ;---- Timebase & Eventbase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
71 timebase res 1 ; timed trigger flags and running timebase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
72 eventbase res 1 ; event trigger flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
73
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
74 ;---- Timeout-Timer Service
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
75 isr_timeout_timer res 1 ; timeout timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
76 isr_timeout_reload res 1 ; timeout reload value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
77
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
78 ;---- Dive Times
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
79 total_divetime_secs res 2 ; total dive time, seconds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
80 counted_divetime_mins res 2 ; counted dive time, minutes | Attention: do not change the position of
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
81 counted_divetime_secs res 1 ; counted dive time, seconds | these 2 Variables relative to each other!
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
82
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
83 ;---- Dive Times / Apnoe
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
84 apnoe_surface_mins res 1 ; surface time minutes | Attention: do not change the position of
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
85 apnoe_surface_secs res 1 ; surface time seconds | these 2 Variables relative to each other!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
86
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
87 apnoe_dive_mins res 1 ; dive time minutes | Attention: do not change the position of
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
88 apnoe_dive_secs res 1 ; dive time seconds | these 2 Variables relative to each other!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
89
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
90 ;---- Profile Recording
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
91 sampling_rate res 1 ; configured sampling rate
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
92 sampling_timer res 1 ; sampling timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
93
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
94 ;---- Simulator Mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
95 simulatormode_depth res 1 ; depth in simulator mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
96
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
97 ;---- HUD / Sensor Data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
98 hud_status_byte res 1 ; HUD status byte, see definition of flags | Attention: keep relative position
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
99 hud_battery_mv res 2 ; hud/ppo2 monitor battery voltage in mV | between these two variables!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
100
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
101 ;---- Battery Management
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
102 battery_capacity_internal res 2 ; for internal battery gauging
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
103 battery_capacity res 2 ; for battery gauge IC
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
104 battery_offset res 2 ; for battery gauge IC
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
105 battery_type res 1 ; =0:1.5V, =1:3.6V Saft, =2:LiIon 3.7V/0.8Ah, =3:LiIon 3.7V/3.1Ah, =4: LiIon 3.7V/2.3Ah
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
106 battery_accumulated_charge res 2 ; raw values in battery gauge IC
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
107 battery_temperature res 2 ; battery temperature in 0.1 Kelvin
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
108 gauge_status_byte res 1 ; gauge IC status byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
109
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
110
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
111
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 642
diff changeset
112 ; 44 byte user data
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
113 ; 32 byte tmp data placed by C compiler
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
114 ; 20 byte variables placed by math library
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
115 ; ==
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 642
diff changeset
116 ; 96 byte used, 0 byte free (96 byte total available)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
117
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
118
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
119 global HW_descriptor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
120 global HW_variants
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 642
diff changeset
121 global HW_variants2
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
122 global HW_flags_state1
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
123 global HW_flags_state2
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 642
diff changeset
124 global HW_flags_state3
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
125 global OS_flags_persist
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
126 global OS_flags_ISR1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
127 global OS_flags_ISR2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
128 global OM_flags_mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
129 global DM_flags_deco
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
130 global cpu_speed_request
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
131 global cpu_speed_state
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
132 global timebase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
133 global eventbase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
134 global isr_timeout_timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
135 global isr_timeout_reload
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
136 global total_divetime_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
137 global counted_divetime_mins
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
138 global counted_divetime_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
139 global apnoe_surface_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
140 global apnoe_surface_mins
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
141 global apnoe_dive_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
142 global apnoe_dive_mins
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
143 global sampling_rate
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
144 global sampling_timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
145 global simulatormode_depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
146 global hud_status_byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
147 global hud_battery_mv
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
148 global battery_capacity_internal
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
149 global battery_capacity
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
150 global battery_offset
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
151 global battery_type
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
152 global battery_accumulated_charge
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
153 global battery_temperature
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
154 global gauge_status_byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
155
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
156
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
157 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
158 hwos1 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
159 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
160
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
161 ;-----------------------------------------------------------------------------
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
162 ; Master Initialization of Hardware Resources
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
163 ;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
164 global init_ostc
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 209
diff changeset
165 init_ostc:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
166
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
167 ; Oscillator
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
168 banksel common ; select bank common
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
169 movlw b'01110010' ; select 16 MHz INTOSC
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
170 movwf OSCCON ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
171 movlw b'00001000' ; secondary oscillator running
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
172 movwf OSCCON2 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
173 movlw b'00000000' ; 4x PLL disable (Bit 6) - only works with 8 or 16MHz (=32 or 64MHz)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
174 movwf OSCTUNE ; ...
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
175
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
176 movlw coding_speed_normal ; coding for normal CPU speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
177 movwf cpu_speed_request ; store CPU shall run with normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
178 movwf cpu_speed_state ; store CPU does run with normal speed
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
179
642
a9a0188091e4 fix rare upgrade issue with OSTC sport 2019 hardware
heinrichsweikamp
parents: 640
diff changeset
180 ;bcf RCON,SBOREN ; brown-out off (not needed here, is handled in bootloader)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
181 bcf RCON,IPEN ; priority interrupts off
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
182
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
183 banksel WDTCON
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
184 movlw b'10000000' ; setup watchdog
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
185 movwf WDTCON ; ...
0
heinrichsweikamp
parents:
diff changeset
186
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
187
0
heinrichsweikamp
parents:
diff changeset
188 ; I/O Ports
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
189 banksel 0xF16 ; addresses F16h ... F5Fh are not part of the access RAM
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
190
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
191 clrf REFOCON ; no reference oscillator active on REFO pin
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
192 clrf ODCON1 ; disable open drain capability
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
193 clrf ODCON2 ; disable open drain capability
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
194 clrf ODCON3 ; disable open drain capability
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
195 clrf CM1CON ; disable comparator 1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
196 clrf CM2CON ; disable comparator 2
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
197 clrf CM3CON ; disable comparator 3
0
heinrichsweikamp
parents:
diff changeset
198
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
199 movlw b'11000000' ; ANSEL0: AN7, AN6 -> analog inputs, PORTA is digital
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
200 movwf ANCON0 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
201 movlw b'00000111' ; ANSEL1: AN8, AN9, AN10 -> analog input
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
202 movwf ANCON1 ; ...
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
203 clrf ANCON2
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
204
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
205 banksel common ; back to bank common
0
heinrichsweikamp
parents:
diff changeset
206
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
207 ; movlw b'00000000' ; 1= input -> Data TFT_high
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
208 clrf TRISA ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
209 ; movlw b'00000000' ; init port
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
210 clrf PORTA ; ...
0
heinrichsweikamp
parents:
diff changeset
211
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
212 movlw b'00000011' ; 1= input, (RB0, RB1) -> switches, RB2 -> Power_MCP, RB3 -> s8_npower, RB4 -> LED_green/rx_nreset, RB5 -> /TFT_POWER
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
213 movwf TRISB ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
214 movlw b'00111000' ; init port, rx_nreset=1 -> hard reset RX
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
215 movwf PORTB ; ...
0
heinrichsweikamp
parents:
diff changeset
216
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
217 movlw b'10011010' ; 1= input, (RC0, RC1) -> SOSC, RC2 -> TFT_LED_PWM, (RC3,RC4) -> I²C, RC5 -> MOSI_MS5541, (RC6, RC7) -> UART1
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
218 movwf TRISC ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
219 ; movlw b'00000000' ; init port
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
220 clrf PORTC ; ...
0
heinrichsweikamp
parents:
diff changeset
221
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
222 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
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
223 movwf TRISD ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
224 ; movlw b'00000000' ; init port
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
225 clrf PORTD ; ...
0
heinrichsweikamp
parents:
diff changeset
226
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
227 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
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
228 movwf TRISE ; ...
627
bf5fee575701 minor cleanup, reset rx circuity
heinrichsweikamp
parents: 624
diff changeset
229 movlw b'00010001' ; init port
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
230 movwf PORTE ; ...
0
heinrichsweikamp
parents:
diff changeset
231
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
232 movlw b'01111110' ; 1= input, (RF1, RF2, RF3, RF4, RF5) -> Analog
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
233 movwf TRISF ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
234 ; movlw b'00000000' ; init port
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
235 clrf PORTF ; ...
0
heinrichsweikamp
parents:
diff changeset
236
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
237 movlw b'00000110' ; 1= input, <7:6> not implemented, RG0 -> TX3_PIEZO_CFG, , RG1 -> TX2, RG2 -> RX2, RG3 -> AN17_RSSI, RG4 -> SOSC_OUT, RG5 -> /RESET
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
238 movwf TRISG ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
239 movlw b'00000001' ; init port
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
240 movwf PORTG ; ...
0
heinrichsweikamp
parents:
diff changeset
241
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
242 ; movlw b'00000000' ; 1= input -> Data TFT_low
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
243 clrf TRISH ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
244 ; movlw b'00000000' ; init port
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
245 clrf PORTH ; ...
0
heinrichsweikamp
parents:
diff changeset
246
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
247 movlw b'10011011' ; 1= input, RJ4 -> vusb_in, RJ5 -> power_sw2, RJ6 -> CLK_MS5541, RJ7 -> MISO_MS5541
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
248 movwf TRISJ ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
249 movlw b'00100000' ; init port
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
250 movwf PORTJ ; ...
0
heinrichsweikamp
parents:
diff changeset
251
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
252
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 614
diff changeset
253 ; disable Charger by default
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
254 bsf charge_disable ; set charging-inhibit signal
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
255 bcf charge_enable ; activate charging-inhibit signal
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
256
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
257
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
258 ; Timer 7 for 62.5 ms Interrupt (Sensor States)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
259 banksel 0xF16 ; addresses F16h...F5Fh are not part of the access RAM
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
260 clrf T7GCON ; clear timer 7 gate control register
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
261 movlw b'10001101' ; bit 7-6: 10 = clock source SOSC/SCLKI (with bit 3 = 1)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
262 ; bit 5-4: 00 = 1:1 prescaler
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
263 ; bit 3: 1 = clock source SOSC/SCLKI (with bit 7-6 = 10)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
264 ; bit 2: 1 = DO NOT synchronize external clock input (else OSTC won't wake up from sleep!)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
265 ; bit 1: 0 = 2x 8 bit operation
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
266 ; bit 0: 1 = timer enabled
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
267 ; 32768 Hz clock source, 1:1 prescaler -> timer counts at 30.51757813 µs/bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
268 movwf T7CON ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
269 movlw .248 ; load timer 7, high byte (8x256 ticks -> 62.5 ms)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
270 movwf TMR7H ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
271 clrf TMR7L ; load timer 7, low byte
0
heinrichsweikamp
parents:
diff changeset
272
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
273
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
274 ; Timer 0 - not used
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
275 movlw b'00000001' ; timer0 stopped (1:4 prescaler)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
276 movwf T0CON ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
277
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
278
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
279 ; Timer 1 - Button hold-down Timer
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
280 ; movlw b'10001100' ; old setting
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
281 movlw b'10001010' ; bit 7-6: 10 = clock source SOSC/SCLKI (with bit 3 = 1)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
282 ; bit 5-4: 00 = 1:1 prescaler
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
283 ; bit 3: 1 = clock source SOSC/SCLKI (with bit 7-6 = 10)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
284 ; bit 2: 0 = synchronize external clock input
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
285 ; bit 1: 1 = 16 bit operation
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
286 ; bit 0: 0 = timer stopped
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
287 ; 32768 Hz clock source, 1:1 prescaler -> timer counts at 30.51757813 µs/bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
288 movwf T1CON ; ...
0
heinrichsweikamp
parents:
diff changeset
289
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
290
0
heinrichsweikamp
parents:
diff changeset
291 ; RTCC
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
292 banksel 0xF16 ; addresses, F16h through F5Fh, are also used by SFRs, but are not part of the access RAM
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
293 movlw 0x55 ; unlock sequence for RTCWREN
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
294 movwf EECON2 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
295 movlw 0xAA ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
296 movwf EECON2 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
297 bsf RTCCFG,RTCWREN ; unlock access to RTC
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
298 bsf RTCCFG,RTCPTR1 ; set pointer register to b'11'
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
299 bsf RTCCFG,RTCPTR0 ; ..
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
300 bsf RTCCFG,RTCEN ; module enable
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
301 bsf RTCCFG,RTCOE ; output enable
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
302 movlw b'00000100' ; 32768 Hz SOCS on RTCC pin (PORTG,4) Bit7-5: pull-ups for Port D, E and J
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
303 movwf PADCFG1 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
304 movlw b'11000000' ; 1/2 second alarm
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
305 movwf ALRMCFG ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
306 movlw d'1' ; select alarm repeat counter to 1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
307 movwf ALRMRPT ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
308 movlw 0x55 ; unlock sequence for RTCWREN
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
309 movwf EECON2 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
310 movlw 0xAA ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
311 movwf EECON2 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
312 bcf RTCCFG,RTCWREN ; lock access to RTC
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
313 banksel common ; back to bank common
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
314
614
a32212cd5ea9 work on new battery menu
heinrichsweikamp
parents: 612
diff changeset
315
0
heinrichsweikamp
parents:
diff changeset
316 ; A/D Converter
heinrichsweikamp
parents:
diff changeset
317 movlw b'00011000' ; power off ADC, select AN6
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
318 movwf ADCON0 ; ...
0
heinrichsweikamp
parents:
diff changeset
319 movlw b'00100000' ; 2.048V Vref+
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
320 movwf ADCON1 ; ...
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
321 movlw b'10001111' ; right aligned, 2 x T_AD acquisition time, clock derived from A/D RC oscillator (To be CPU-clock independent)
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
322 movwf ADCON2 ; ...
0
heinrichsweikamp
parents:
diff changeset
323
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
324
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
325 ; Serial Port 1 (TRISC6/7)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
326 movlw b'00001000' ; switch baud generator to 16 bit mode (BRG16=1)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
327 movwf BAUDCON1 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
328 ; SPBRGH:SPBRG = .34 : 114285 BAUD @ 16MHz (+0.79% error at 115200 baud)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
329 ; SPBRGH:SPBRG = .207 : 19230 BAUD @ 16MHz (-0.16% error at 19200 baud)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
330 movlw .34 ; select 114285 baud (low byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
331 movwf SPBRG1 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
332 clrf SPBRGH1 ; ... (high byte)
204
heinrichsweikamp
parents: 200
diff changeset
333
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
334 clrf RCSTA1 ; disable UART RX
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
335 clrf TXSTA1 ; disable UART TX
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
336 bcf PORTC,6 ; tie TX output hard to GND
0
heinrichsweikamp
parents:
diff changeset
337
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
338
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
339 ; Serial Port 2 (TRISG2) for IR/S8 digital Interface
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
340 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
341 ; - will be initialized by enable_ir_s8 (eeprom_rs232.asm) in case IR/S8 shall be available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
342
0
heinrichsweikamp
parents:
diff changeset
343
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
344 ; Timer 3 for IR-RX Timeout
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
345 IFDEF _external_sensor
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
346 clrf T3GCON ; clear Timer3 gate control register
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
347 ; movlw b'10001101' ; old value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
348 movlw b'10001011' ; bit 7-6: 10 = clock source SOSC/SCLKI (with bit 3 = 1)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
349 ; bit 5-4: 00 = 1:1 prescaler
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
350 ; bit 3: 1 = clock source SOSC/SCLKI (with bit 7-6 = 10)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
351 ; bit 2: 0 = synchronize external clock input
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
352 ; bit 1: 1 = 16 bit operation
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
353 ; bit 0: 1 = timer enabled
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
354 ; 32768 Hz clock source, 1:1 prescaler -> timer counts at 30.51757813 µs/bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
355 movwf T3CON ; ...
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
356 ENDIF
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
357
0
heinrichsweikamp
parents:
diff changeset
358
heinrichsweikamp
parents:
diff changeset
359 ; SPI Module(s)
heinrichsweikamp
parents:
diff changeset
360 ; SPI2: External Flash
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
361 movlw b'00110000' ; set up SPI module
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
362 movwf SSP2CON1 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
363 clrf SSP2STAT ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
364 ; resulting bit clocks: 0.25 MHz @ 1 MHz CPU clock (Eco)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
365 ; 4.00 MHz @ 16 MHz CPU clock (Normal)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
366 ; 16.00 MHz @ 64 MHz CPU clock (Fastest)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
367
0
heinrichsweikamp
parents:
diff changeset
368
heinrichsweikamp
parents:
diff changeset
369 ; MSSP1 Module: I2C Master
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
370 movlw b'00101000' ; set up I2C to master mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
371 movwf SSP1CON1 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
372 clrf SSP1CON2 ; ...
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 642
diff changeset
373 movlw i2c_speed_value
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
374 movwf SSP1ADD ; ...
0
heinrichsweikamp
parents:
diff changeset
375
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
376
0
heinrichsweikamp
parents:
diff changeset
377 ; PWM Module(s)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
378 ; PWM 1 for LED dimming
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
379 movlw b'00001100' ; set up PWM module
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
380 movwf CCP1CON ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
381 movlw b'00000001' ; pulse steering disabled
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
382 movwf PSTR1CON ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
383 movlw d'254' ; select period
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
384 movwf PR2 ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
385 ; 255 is max brightness (300 mW)
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
386 clrf CCPR1L ; duty cycle, low byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
387 clrf CCPR1H ; duty cycle, high byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
388 movlw T2CON_NORMAL ; set timer for normal dimming
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
389 movwf T2CON ; ...
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
390
0
heinrichsweikamp
parents:
diff changeset
391
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
392 ; Timer 5 for ISR-independent Wait/Timeout
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
393 clrf T5GCON ; clear Timer5 gate control register
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
394 ; movlw b'10001111' ; old value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
395 movlw b'10001011' ; bit 7-6: 10 = clock source SOSC/SCLKI (with bit 3 = 1)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
396 ; bit 5-4: 00 = 1:1 prescaler
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
397 ; bit 3: 1 = clock source SOSC/SCLKI (with bit 7-6 = 10)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
398 ; bit 2: 0 = synchronize external clock input
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
399 ; bit 1: 1 = 16 bit operation
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
400 ; bit 0: 1 = timer enabled
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
401 ; 32768 Hz clock source, 1:1 prescaler -> timer counts at 30.51757813 µs/bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
402 movwf T5CON ; ...
0
heinrichsweikamp
parents:
diff changeset
403
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
404 ; Timer 4 for debounce of new digital piezo circuity
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
405 movlw b'01111011' ; 1:8 Postscale, Prescale = 1, Timer 4 OFF
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
406 movwf T4CON
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
407 setf PR4
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
408
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
409 ; turn off unused Timers
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
410 banksel 0xF16 ; addresses F16h...F5Fh are not part of the access RAM
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
411 movlw b'11000000' ; disable ECCP3 and ECCP2
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
412 movwf PMD0 ; ...
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
413 IFDEF _external_sensor
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
414 movlw b'11000001' ; disable PSP, CTMU and EMB
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
415 ELSE
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
416 movlw b'11001001' ; disable PSP, CTMU, Timer 3 and EMB
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
417 ENDIF
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
418 movwf PMD1 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
419 movlw b'11010111' ; disable timer 10, timer 8, timer 6 and comparators 1-3
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
420 movwf PMD2 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
421 movlw b'11111111' ; disable CCP 4-10 and timer 12
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
422 movwf PMD3 ; ...
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
423
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
424
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
425 ; turn off unused CTMU
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
426 ;banksel 0xF16 ; addresses F16h...F5Fh are not part of the access RAM
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
427 clrf CTMUCONH ; disable CTMU
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
428 clrf CTMUCONL ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
429 clrf CTMUICON ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
430
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
431
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
432 banksel common
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
433
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
434
0
heinrichsweikamp
parents:
diff changeset
435 ; Interrupts
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
436 bcf PIR5,TMR7IF ; if applicable clear timer 7 IRQ flag
0
heinrichsweikamp
parents:
diff changeset
437
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
438 movlw b'11010000' ; enable global IRQ, peripheral IRQ and external IRQ 0
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
439 movwf INTCON ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
440 movlw b'00001000' ; external IRQ 0 on falling edge, pull-up of PORTB by TRIS register
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
441 movwf INTCON2 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
442 movlw b'00000000' ; disable external IRQs 1,2,3
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
443 movwf INTCON3 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
444 movlw b'00000001' ; enable timer 1 IRQ
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
445 movwf PIE1 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
446 movlw b'00000010' ; enable timer 3 IRQ
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
447 movwf PIE2 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
448 movlw b'00000001' ; enable RTCC IRQ
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
449 movwf PIE3 ; ...
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
450 movlw b'00001001' ; enable timer 7 and timer 4 IRQ
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
451 movwf PIE5 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
452
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
453 ; Release RESET from RX Circuitry
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
454 bcf active_reset_ostc_rx
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
455
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
456 ; Power-up the Switches
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
457 ;bra power_up_switches
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
458
0
heinrichsweikamp
parents:
diff changeset
459
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
460 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
461 ; Power-up the Switches
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
462 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
463 global power_up_switches
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
464 power_up_switches:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
465 bsf power_sw1 ; switch on power supply for switch 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
466 btfss power_sw1 ; power established?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
467 bra $-4 ; NO - wait
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
468
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
469 bsf power_sw2 ; switch on power supply for switch 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
470 btfss power_sw2 ; power established?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
471 bra $-4 ; NO - wait
204
heinrichsweikamp
parents: 200
diff changeset
472
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
473 return ; done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
474
0
heinrichsweikamp
parents:
diff changeset
475
heinrichsweikamp
parents:
diff changeset
476 ;=============================================================================
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
477 hwos2 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
478 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
479
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
480 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
481 ; CPU Speed Change Requests
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
482 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
483 global request_speed_eco
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
484 request_speed_eco:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
485 movlw coding_speed_eco ; load coding for eco speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
486 movwf cpu_speed_request ; request ISR to change the CPU speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
487 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
488
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
489 global request_speed_normal
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
490 request_speed_normal:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
491 movlw coding_speed_normal ; load coding for normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
492 movwf cpu_speed_request ; request ISR to change the CPU speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
493 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
494
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
495 global request_speed_fastest
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
496 request_speed_fastest:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
497 movlw coding_speed_fastest ; load coding for fastest speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
498 movwf cpu_speed_request ; request ISR to change the CPU speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
499 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
500
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
501
0
heinrichsweikamp
parents:
diff changeset
502 ;=============================================================================
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
503 hwos3 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
504 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
505
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
506 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
507 ; Backup the first 128 bytes from program FLASH to EEPROM
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
508 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
509 global backup_flash_page
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
510 backup_flash_page:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
511 banksel common
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
512
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
513 ; set start address in internal program FLASH
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
514 movlw 0x00 ; set 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
515 movwf TBLPTRL ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
516 movwf TBLPTRH ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
517 movwf TBLPTRU ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
518 TBLRD*- ; dummy read to be in 128 byte block
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
519
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
520 ; set start address in EEPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
521 EEPROM_SET_ADDRESS eeprom_prog_page0_backup
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
522
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
523 movlw .128 ; copy 1 block = 128 byte
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
524 movwf eeprom_loop ; initialize loop counter
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
525 backup_flash_loop:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
526 tblrd+* ; read one byte from program FLASH (with pre-increment)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
527 movff TABLAT,EEDATA ; transfer byte from program FLASH read to EEPROM write
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
528 call write_eeprom ; execute EEPROM write
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
529 incf EEADR,F ; increment EEPROM address
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
530 decfsz eeprom_loop,F ; all 128 byte done?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
531 bra backup_flash_loop ; NO - loop
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
532 return ; YES - done
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
533
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
534
0
heinrichsweikamp
parents:
diff changeset
535 ;=============================================================================
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
536 hwos4 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
537 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
538
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
539 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
540 ; Restore the first 128 bytes from EEPROM to program FLASH
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
541 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
542 global restore_flash
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
543 restore_flash:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
544 banksel common
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
545
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
546 ;set start address in internal program FLASH
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
547 movlw 0x00 ; set 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
548 movwf TBLPTRL ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
549 movwf TBLPTRH ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
550 movwf TBLPTRU ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
551 TBLRD*- ; dummy read to be in 128 byte block
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
552
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
553 movlw b'10010100' ; setup block erase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
554 rcall restore_write ; execute block erase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
555
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
556 ; set start address in EEPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
557 EEPROM_SET_ADDRESS eeprom_prog_page0_backup
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
558
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
559 movlw .128 ; copy 1 block = 128 byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
560 movwf eeprom_loop ; initialize loop counter
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
561 restore_flash_loop:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
562 call read_eeprom ; execute EEPROM read
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
563 incf EEADR,F ; increment EEPROM address
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
564 movff EEDATA,TABLAT ; transfer byte from EEPROM read to program FLASH write
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
565 tblwt+* ; execute program FLASH write (with pre-increment)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
566 decfsz eeprom_loop,F ; all 128 bytes done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
567 bra restore_flash_loop ; NO - loop
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
568 movlw b'10000100' ; YES - setup block write
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
569 rcall restore_write ; - execute block write
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
570 reset ; - done, reset CPU
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
571
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
572 restore_write:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
573 movwf EECON1 ; configure operation
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
574 movlw 0x55 ; unlock sequence
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
575 movwf EECON2 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
576 movlw 0xAA ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
577 movwf EECON2 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
578 bsf EECON1,WR ; execute operation
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
579 nop ; wait for operation to complete
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
580 nop ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
581 return ; done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
582
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
583
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
584 ;=============================================================================
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
585 hwos5 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
586 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
587
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
588 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
589 ; Memory clear and move Functions, to be used via Macros
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
590 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
591 global memory_clear
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
592 memory_clear:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
593 clrf POSTINC1 ; clear address
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
594 decfsz WREG ; decrement loop counter, became zero?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
595 bra memory_clear ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
596 return ; YES - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
597
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
598 global memory_move
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
599 memory_move:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
600 movff POSTINC1,POSTINC2 ; copy from-to
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
601 decfsz WREG ; decrement loop counter, became zero?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
602 bra memory_move ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
603 return ; YES - done
0
heinrichsweikamp
parents:
diff changeset
604
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
605
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
606 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
607 hwos6 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
608 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
609
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
610 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
611 ; Read CPU Silicon Version
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
612 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
613 global get_cpu_version
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
614 get_cpu_version:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
615 movlw 0xFE ; select address 0x3FFFFE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
616 movwf TBLPTRL ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
617 movlw 0xFF ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
618 movwf TBLPTRH ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
619 movlw 0x3F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
620 movwf TBLPTRU ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
621 TBLRD*+ ; read DEVID1 byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
622 movlw b'00011111' ; load mask for silicon version
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
623 andwf TABLAT,W ; apply mask and store result in WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
624 return ; done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
625
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
626 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
627
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
628 END