annotate src/hwos.asm @ 623:c40025d8e750

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