annotate src/hwos.asm @ 632:0347acdf6d8e

changelog updates
author heinrichsweikamp
date Sat, 29 Feb 2020 16:57:45 +0100
parents 185ba2f91f59
children 4050675965ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
3 ; File hwos.asm combined next generation V3.08.8
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)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
46
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
47 ;---- Flags - Hardware States
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
48 HW_flags_state1 res 1 ; hardware - states 1
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
49 HW_flags_state2 res 1 ; hardware - states 2
623
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 ;---- Profile Recording
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
87 sampling_rate res 1 ; configured sampling rate
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
88 sampling_timer res 1 ; sampling timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
89
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
90 ;---- Simulator Mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
91 simulatormode_depth res 1 ; depth in simulator mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
92
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
93 ;---- HUD / Sensor Data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
94 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
95 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
96
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
97
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
98 ; 28 byte user data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
99 ; 32 byte tmp data placed by C compiler
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
100 ; 20 byte variables placed by math library
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
101 ; ==
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
102 ; 80 byte used, 16 byte free (96 byte total available)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
103
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
104
623
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
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
107 global HW_flags_state1
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
108 global HW_flags_state2
623
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
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
201 movlw b'00100000' ; 1= input, RE0 -> not_Power_BLE, RE1 -> Power_IR, RE2 -> CS_MCP, RE3 -> LED_blue, RE4 -> power_sw1, RE5 -> leave as input
627
bf5fee575701 minor cleanup, reset rx circuity
heinrichsweikamp
parents: 624
diff changeset
202 movwf TRISE
bf5fee575701 minor cleanup, reset rx circuity
heinrichsweikamp
parents: 624
diff changeset
203 movlw b'00010001' ; 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
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
211 movlw b'00001110' ; 1= input, <7:6> not implemented, RG0 -> TX3_PIEZO_CFG, , RG1 -> TX2, RG2 -> RX2, RG3 -> AN17_RSSI, RG4 -> SOSC_OUT, RG5 -> /RESET
0
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
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
272 movlw b'10111010' ; right aligned, 20 x T_AD acquisition time, FOSC/32 -> max. 40 MHz device clock speed
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)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
277 movlw b'00001000' ; switch baud generator to 16 bit mode (BRG16=1)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
278 movwf BAUDCON1 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
279 ; SPBRGH:SPBRG = .34 : 114285 BAUD @ 16MHz (+0.79% error at 115200 baud)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
280 ; SPBRGH:SPBRG = .207 : 19230 BAUD @ 16MHz (-0.16% error at 19200 baud)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
281 movlw .34 ; select 114285 baud (low byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
282 movwf SPBRG1 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
283 clrf SPBRGH1 ; ... (high byte)
204
heinrichsweikamp
parents: 200
diff changeset
284
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
285 clrf RCSTA1 ; disable UART RX
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
286 clrf TXSTA1 ; disable UART TX
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
287 bcf PORTC,6 ; tie TX output hard to GND
0
heinrichsweikamp
parents:
diff changeset
288
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
289
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
290 ; serial Port 2 (TRISG2) for IR/S8 digital interface
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
291 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
292 ; - 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
293
0
heinrichsweikamp
parents:
diff changeset
294
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
295 ; Timer 3 for IR-RX Timeout
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
296 IFDEF _external_sensor
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
297 clrf T3GCON ; reset Timer3 gate control register
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
298 movlw b'10001101' ; not synced, 1:1 prescaler -> 2 seconds till overrun @ 32768 Hz,
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
299 ; incrementing by 1 bit each 30.51757813 µs
0
heinrichsweikamp
parents:
diff changeset
300 movwf T3CON
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
301 ENDIF
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
302
0
heinrichsweikamp
parents:
diff changeset
303
heinrichsweikamp
parents:
diff changeset
304 ; SPI Module(s)
heinrichsweikamp
parents:
diff changeset
305 ; SPI2: External Flash
heinrichsweikamp
parents:
diff changeset
306 movlw b'00110000'
heinrichsweikamp
parents:
diff changeset
307 movwf SSP2CON1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
308 ; movlw b'00000000'
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
309 clrf SSP2STAT
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
310 ; -> 0.25 MHz Bit clock @ 1 MHz mode (Eco)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
311 ; -> 4 MHz Bit clock @ 16 MHz mode (Normal)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
312 ; -> 16 MHz Bit clock @ 64 MHz mode (Fastest)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
313
0
heinrichsweikamp
parents:
diff changeset
314
heinrichsweikamp
parents:
diff changeset
315 ; MSSP1 Module: I2C Master
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
316 movlw b'00101000' ; I2C master mode
0
heinrichsweikamp
parents:
diff changeset
317 movwf SSP1CON1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
318 ; movlw b'00000000'
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 383
diff changeset
319 clrf SSP1CON2
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
320 movlw 0x9C
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
321 movwf SSP1ADD ; 100kHz @ 64MHz Fosc
0
heinrichsweikamp
parents:
diff changeset
322
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
323
0
heinrichsweikamp
parents:
diff changeset
324 ; PWM Module(s)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
325 ; PWM 1 for LED dimming
0
heinrichsweikamp
parents:
diff changeset
326 movlw b'00001100'
heinrichsweikamp
parents:
diff changeset
327 movwf CCP1CON
heinrichsweikamp
parents:
diff changeset
328 movlw b'00000001'
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
329 movwf PSTR1CON ; pulse steering disabled
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 627
diff changeset
330 movlw d'254'
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
331 movwf PR2 ; period
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
332 ; 255 is max brightness (300 mW)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
333 clrf CCPR1L ; duty cycle
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
334 clrf CCPR1H ; duty cycle
0
heinrichsweikamp
parents:
diff changeset
335 movlw T2CON_NORMAL
heinrichsweikamp
parents:
diff changeset
336 movwf T2CON
heinrichsweikamp
parents:
diff changeset
337
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
338
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
339 ; Timer 5 for ISR-independent wait routines
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
340 clrf T5GCON ; reset Timer5 gate control register
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
341 movlw b'10001111' ; not synced, 16 bit mode, 1:1 prescaler -> 2 seconds till overrun @ 32768 Hz,
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
342 movwf T5CON ; incrementing by 1 bit each 30.51757813 µs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
343
0
heinrichsweikamp
parents:
diff changeset
344
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
345 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
346
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
347 ; 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
348 clrf T7GCON ; reset Timer7 gate control register
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
349 movlw b'10001101' ; 1:1 prescaler -> 2 seconds @ 32768 Hz, not synced
0
heinrichsweikamp
parents:
diff changeset
350 movwf T7CON
heinrichsweikamp
parents:
diff changeset
351 clrf TMR7L
heinrichsweikamp
parents:
diff changeset
352 movlw .248
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
353 movwf TMR7H ; -> rollover after 2048 cycles -> 62.5 ms
0
heinrichsweikamp
parents:
diff changeset
354
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
355
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
356 ; turn off unused timers
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
357 movlw b'11000000'
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
358 movwf PMD0
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
359 IFDEF _external_sensor
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
360 movlw b'11010001'
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
361 ELSE
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
362 movlw b'11011001' ; includes turning off timer 3
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
363 ENDIF
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
364 movwf PMD1
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
365 movlw b'11010111'
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
366 movwf PMD2
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
367 movlw b'11111111'
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
368 movwf PMD3
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
369
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
370
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
371 ; turn off unused CTMU
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
372 clrf CTMUCONH
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
373 clrf CTMUCONL
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
374 clrf CTMUICON
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
375
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
376 banksel common
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
377
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
378
0
heinrichsweikamp
parents:
diff changeset
379 ; Interrupts
50
ec4d8503ec45 NEW: user-selectable color schemes
heinrichsweikamp
parents: 28
diff changeset
380 movlw b'11010000'
0
heinrichsweikamp
parents:
diff changeset
381 movwf INTCON
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
382 movlw b'00001000' ; Bit7=1: pull-up for PORTB disabled
0
heinrichsweikamp
parents:
diff changeset
383 movwf INTCON2
77
131e6dd9e201 BUGFIX: Potential bug to freeze the OSTC3 after battery change or update
heinrichsweikamp
parents: 58
diff changeset
384 movlw b'00000000'
0
heinrichsweikamp
parents:
diff changeset
385 movwf INTCON3
heinrichsweikamp
parents:
diff changeset
386 movlw b'00000001' ; Bit0: TMR1
heinrichsweikamp
parents:
diff changeset
387 movwf PIE1
heinrichsweikamp
parents:
diff changeset
388 movlw b'00000010' ; Bit1: TMR3
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
389 movwf PIE2
0
heinrichsweikamp
parents:
diff changeset
390 movlw b'00000000' ; Bit1: TMR5
heinrichsweikamp
parents:
diff changeset
391 movwf PIE5
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
392 movlw b'00000001' ; Bit0: RTCC, Bit5: UART2 (Default OFF)
0
heinrichsweikamp
parents:
diff changeset
393 movwf PIE3
heinrichsweikamp
parents:
diff changeset
394 movlw b'00001000' ; Bit3: TMR7
heinrichsweikamp
parents:
diff changeset
395 movwf PIE5
heinrichsweikamp
parents:
diff changeset
396
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
397 bcf active_reset_ostc_rx ; release RESET from RX circuitry
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
398 ;bra power_up_switches
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
399
0
heinrichsweikamp
parents:
diff changeset
400
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
401 global power_up_switches
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
402 power_up_switches:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
403 bsf power_sw1 ; switch on power supply for switch 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
404 btfss power_sw1 ; power established?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
405 bra $-4 ; NO - wait
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
406 bsf power_sw2 ; switch on power supply for switch 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
407 btfss power_sw2 ; power established?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
408 bra $-4 ; NO - wait
204
heinrichsweikamp
parents: 200
diff changeset
409
0
heinrichsweikamp
parents:
diff changeset
410 return
heinrichsweikamp
parents:
diff changeset
411
heinrichsweikamp
parents:
diff changeset
412 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
413 ; CPU speed change request functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
414
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
415 global request_speed_eco
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
416 request_speed_eco:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
417 movlw coding_speed_eco ; load coding for eco speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
418 movwf cpu_speed_request ; request ISR to change the CPU speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
419 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
420
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
421 global request_speed_normal
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
422 request_speed_normal:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
423 movlw coding_speed_normal ; load coding for normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
424 movwf cpu_speed_request ; request ISR to change the CPU speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
425 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
426
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
427 global request_speed_fastest
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
428 request_speed_fastest:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
429 movlw coding_speed_fastest ; load coding for fastest speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
430 movwf cpu_speed_request ; request ISR to change the CPU speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
431 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
432
0
heinrichsweikamp
parents:
diff changeset
433 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
434 ; Backup the first 128 bytes from program memory to EEPROM
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
435 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
436 global backup_flash_page
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
437 backup_flash_page:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
438 banksel common
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
439
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
440 ; set start address in internal program memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
441 movlw 0x00 ; set 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
442 movwf TBLPTRL ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
443 movwf TBLPTRH ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
444 movwf TBLPTRU ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
445 TBLRD*- ; dummy read to be in 128 byte block
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
446
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
447 ; set start address in EEPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
448 EEPROM_SET_ADDRESS eeprom_prog_page0_backup
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
449
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
450 movlw .128 ; copy 1 block = 128 byte
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
451 movwf eeprom_loop ; initialize loop counter
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
452 backup_flash_loop:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
453 tblrd+* ; read one byte from program memory (with pre-increment)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
454 movff TABLAT,EEDATA ; transfer byte from program memory read to EEPROM write
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
455 call write_eeprom ; execute EEPROM write
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
456 incf EEADR,F ; increment EEPROM address
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
457 decfsz eeprom_loop,F ; all 128 byte done?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
458 bra backup_flash_loop ; NO - loop
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
459 return ; YES - done
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
460
0
heinrichsweikamp
parents:
diff changeset
461 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
462 ; Restore the first 128 bytes from EEPROM to program memory
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
463 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
464 global restore_flash
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
465 restore_flash:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
466 banksel common
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
467
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
468 ;set start address in internal program memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
469 movlw 0x00 ; set 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
470 movwf TBLPTRL ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
471 movwf TBLPTRH ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
472 movwf TBLPTRU ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
473 TBLRD*- ; dummy read to be in 128 byte block
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
474
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
475 movlw b'10010100' ; setup block erase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
476 rcall restore_write ; execute block erase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
477
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
478 ; set start address in EEPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
479 EEPROM_SET_ADDRESS eeprom_prog_page0_backup
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
480
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
481 movlw .128 ; copy 1 block = 128 byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
482 movwf eeprom_loop ; initialize loop counter
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
483 restore_flash_loop:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
484 call read_eeprom ; execute EEPROM read
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
485 incf EEADR,F ; increment EEPROM address
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
486 movff EEDATA,TABLAT ; transfer byte from EEPROM read to program memory write
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
487 tblwt+* ; execute program memory write (with pre-increment)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
488 decfsz eeprom_loop,F ; all 128 bytes done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
489 bra restore_flash_loop ; NO - loop
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
490 movlw b'10000100' ; YES - setup block write
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
491 rcall restore_write ; - execute block write
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
492 reset ; - done, reset CPU
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
493
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
494 restore_write:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
495 movwf EECON1 ; configure operation
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
496 movlw 0x55 ; unlock sequence
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
497 movwf EECON2 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
498 movlw 0xAA ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
499 movwf EECON2 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
500 bsf EECON1,WR ; execute operation
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
501 nop ; wait for operation to complete
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
502 nop ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
503 return ; done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
504
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
505 ;=============================================================================
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
506 ; Memory clear and move functions, to be used through macros
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
507 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
508 global memory_clear
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
509 memory_clear:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
510 clrf POSTINC1 ; clear address
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
511 decfsz WREG ; decrement loop counter, became zero?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
512 bra memory_clear ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
513 return ; YES - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
514
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
515 global memory_move
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
516 memory_move:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
517 movff POSTINC1,POSTINC2 ; copy from-to
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
518 decfsz WREG ; decrement loop counter, became zero?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
519 bra memory_move ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
520 return ; YES - done
0
heinrichsweikamp
parents:
diff changeset
521
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 501
diff changeset
522 END