annotate src/hwos.asm @ 624:7bdcc591196c

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