annotate src/isr.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents 1ad0531e9078
children cd58f7fc86db
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: 621
diff changeset
3 ; File isr.asm combined next generation V3.03.4
0
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; INTERUPT subroutines
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
heinrichsweikamp
parents:
diff changeset
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code.
heinrichsweikamp
parents:
diff changeset
11
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 271
diff changeset
12 #include "hwos.inc"
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c
0
heinrichsweikamp
parents:
diff changeset
14 #include "ms5541.inc"
heinrichsweikamp
parents:
diff changeset
15 #include "adc_lightsensor.inc"
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
16
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
17 extern restore_flash
0
heinrichsweikamp
parents:
diff changeset
18
heinrichsweikamp
parents:
diff changeset
19 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
20 ; Code to be placed at fixed position
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
21 ;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
22 isr_high CODE 0x0008 ; high priority interrupts
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
23 bra HighInt
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
24 nop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
25 nop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
26 nop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
27 nop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
28 nop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
29 nop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
30 bra HighInt
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
31 ; *** low priority interrupts are not used ***
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
32 isr_low CODE 0x00018 ; low priority interrupts
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
33 retfie FAST ; do an immediate return with restore of BSR, STATUS and WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
34
0
heinrichsweikamp
parents:
diff changeset
35
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
36 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
37 ; Interrupt Dispatcher
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
38 ;
0
heinrichsweikamp
parents:
diff changeset
39 HighInt:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
40 ; initialize interrupt code
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
41 banksel isr_backup ; default bank for all ISR code is bank ISR data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
42 rcall isr_registers_backup ; back-up registers
0
heinrichsweikamp
parents:
diff changeset
43
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
44 ; serve buttons
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
45 btfsc PIR1,TMR1IF ; timer 1 interrupt (button hold-down timer)?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
46 rcall timer1int ; YES - reset timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
47 btfsc INTCON,INT0IF ; right button activity?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
48 rcall isr_switch_right ; YES - check right switch
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
49 btfsc INTCON3,INT1IF ; left button activity?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
50 rcall isr_switch_left ; YES - check left switch
0
heinrichsweikamp
parents:
diff changeset
51
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
52 IFDEF _external_sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
53 ; serve IR/S8 link timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
54 btfsc PIR3,RC2IF ; UART 2 interrupt?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
55 rcall isr_uart2 ; YES - get a byte from the IR/S8 link
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
56 btfsc PIR2,TMR3IF ; timer 3 interrupt?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
57 rcall isr_timer3 ; YES - check bytes received from IR/S8 link for being a valid telegram
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
58 ENDIF
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
59
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
60 ; serve pressure and temperature sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
61 btfsc PIR5,TMR7IF ; timer 7 interrupt?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
62 rcall isr_tmr7 ; YES - do every 62.5 ms tasks: read sensors, set CPU speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
63
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
64 ; serve real-time clock (RTCC)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
65 btfsc PIR3,RTCCIF ; real-time-clock interrupt?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
66 rcall isr_rtcc ; YES - do every 1/2 s tasks: read RTC, trigger timed tasks, adjust CPU speed, gauge battery, etc.
113
heinrichsweikamp
parents: 50
diff changeset
67
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
68 ; clean up and exit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
69 rcall isr_registers_restore ; restore registers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
70 bsf trigger_isr_updates ; signal that the ISR had kicked in
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
71 retfie FAST ; return from interrupt restoring BSR, STATUS and WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
72
113
heinrichsweikamp
parents: 50
diff changeset
73
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
74 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
75 ; CPU speed adjustment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
76 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
77 isr_adjust_speed:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
78 movff cpu_speed_request,cpu_speed_state ; acknowledge CPU speed request
0
heinrichsweikamp
parents:
diff changeset
79
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
80 btfsc speed_is_eco ; speed 'eco' requested?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
81 bra isr_set_speed_to_eco ; YES - set eco speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
82 btfsc speed_is_fastest ; NO - speed 'fastest' requested?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
83 bra isr_set_speed_to_fastest ; YES - set fastest speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
84 ;bra isr_set_speed_to_normal ; NO - default to normal speed
0
heinrichsweikamp
parents:
diff changeset
85
410
d3087a8ed7e1 BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents: 378
diff changeset
86 isr_set_speed_to_normal:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
87 movlw b'00000000' ; coding for x4 PLL disabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
88 movwf OSCTUNE ; switch off x4 PLL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
89 movlw b'01110010' ; select 16 MHz
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
90 movwf OSCCON ; set prescaler
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
91 movlw T2CON_NORMAL ; PWM1 dimming factor for speed 'normal'
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
92 movwf T2CON ; adjust PWM1 for LED dimming
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
93 bra isr_adjust_speed_exit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
94
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
95 isr_set_speed_to_eco:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
96 movlw b'00000000' ; coding for x4 PLL disabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
97 movwf OSCTUNE ; switch off x4 PLL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
98 movlw b'00110010' ; select 1 MHz
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
99 movwf OSCCON ; set prescaler
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
100 movlw T2CON_ECO ; PWM1 dimming factor for speed 'eco'
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
101 movwf T2CON ; adjust PWM1 for LED dimming
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
102 bra isr_adjust_speed_exit
410
d3087a8ed7e1 BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents: 378
diff changeset
103
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
104 isr_set_speed_to_fastest:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
105 movlw b'01110010' ; select 16 MHz by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
106 btfsc lv_core ; on OSTC with low voltage core?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
107 movlw b'01100010' ; YES - reduce to 8 MHz
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
108 movwf OSCCON ; set prescaler
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
109 movlw b'01000000' ; coding for x4 PLL enable
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
110 movwf OSCTUNE ; switch on x4 PLL -> 64 MHz on high voltage core, 32 MHz on low voltage core
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
111 movlw T2CON_FASTEST ; PWM1 dimming factor for speed 'fastest'
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
112 movwf T2CON ; adjust PWM1 for LED dimming
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
113 ;bra isr_adjust_speed_exit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
114
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
115 isr_adjust_speed_exit:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
116 btfss OSCCON,HFIOFS ; PLL stabilized?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
117 bra isr_adjust_speed_exit ; NO - loop to give it some more time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
118 return ; YES - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
119
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
120 ; Attention: fill-up the gap between the end of this section
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
121 ; and the next section which starts at 0x00080 !!
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
122 nop
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
123
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
124 block_0_code_end: ; marker to find end of code in block 0 in linker report file
410
d3087a8ed7e1 BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents: 378
diff changeset
125
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
126 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
127 ; jump vector for the bootloader, placed at an appointed position here
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
128 ;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
129 isr_restore CODE 0x00080 ; restore first flash page from EEPROM
410
d3087a8ed7e1 BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents: 378
diff changeset
130 restore_flash_0x00080:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
131 goto restore_flash
410
d3087a8ed7e1 BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents: 378
diff changeset
132
0
heinrichsweikamp
parents:
diff changeset
133
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
134 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
135 ; back-up and restore registers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
136 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
137 isr_registers_backup:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
138 MOVII PRODL,PROD_backup ; back-up PRODH:PRODL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
139 return
113
heinrichsweikamp
parents: 50
diff changeset
140
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
141 isr_registers_restore:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
142 MOVII PROD_backup,PRODL ; restore PRODH:PRODL
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
143 return
0
heinrichsweikamp
parents:
diff changeset
144
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
145
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
146 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
147 ; routines for handling digital-attached external sensors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
148 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
149 IFDEF _external_sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
150
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
151 ; Take a byte received on IR/S8 link and slot it into the RX buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
152 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
153 isr_uart2:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
154 banksel RCREG2 ; RC*2 is outside access RAM
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
155 movff RCREG2,isr_lo ; copy received byte to isr_lo
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
156 bcf RCSTA2,CREN ; clear receiver status
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
157 bsf RCSTA2,CREN ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
158 banksel isr_backup ; back to default ISR bank
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
159 movlw .18 ; size of the buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
160 cpfslt ir_s8_counter ; number of received bytes < buffer size?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
161 bra isr_uart2_1 ; NO - buffer full, do not store the byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
162 movf ir_s8_counter,W ; YES - copy number of received bytes to WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
163 MOVII FSR0L,FSR0_backup ; - back-up FSR0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
164 lfsr FSR0,ir_s8_buffer ; - load base address of buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
165 movff isr_lo,PLUSW0 ; - store received byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
166 MOVII FSR0_backup,FSR0L ; - restore FSR0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
167 incf ir_s8_counter,F ; - increment number of received bytes by 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
168 isr_uart2_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
169 clrf TMR3L ; reload timer 3
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
170 movlw .253 ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
171 movwf TMR3H ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
172 bsf T3CON,TMR3ON ; (re)start timeout timer 3
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
173 return
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
174
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
175
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
176 ; Timeout on IR/S8 link: check the checksum and gather the received data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
177 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
178 isr_timer3:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
179 bcf T3CON,TMR3ON ; stop timer 3
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
180 movlw .15
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
181 cpfseq ir_s8_counter ; got exactly 15 bytes?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
182 bra isr_timer3_1 ; NO - test for 16 bytes
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
183 bra isr_timer3_ir ; YES - got 15 bytes, compute local checksum
0
heinrichsweikamp
parents:
diff changeset
184 isr_timer3_1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
185 movlw .16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
186 cpfseq ir_s8_counter ; got exactly 16 bytes?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
187 bra isr_timer3_2 ; NO - test for 17 bytes
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
188 tstfsz ir_s8_buffer+.15 ; YES - last byte = 0x00 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
189 bra isr_timer3_exit ; No - exit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
190 bra isr_timer3_ir ; YES - got 16 bytes, compute local checksum
113
heinrichsweikamp
parents: 50
diff changeset
191 isr_timer3_2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
192 movlw .17
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
193 cpfseq ir_s8_counter ; got exactly 17 bytes?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
194 bra isr_timer3_exit ; NO - exit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
195 bra isr_timer3_s8 ; YES - S8 data
0
heinrichsweikamp
parents:
diff changeset
196
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
197 ; Process telegram received on IR link
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
198 isr_timer3_ir:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
199 movlw .12 ; checksum shall be computed for 1st and next 12 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
200 rcall compute_IR_S8_checksum ; compute checksum
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
201 movf ir_s8_buffer+.13,W ; get low byte of the received checksum
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
202 cpfseq isr_mpr+0 ; = low byte of the calculated local checksum?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
203 bra isr_timer3_exit ; NO - exit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
204 movf ir_s8_buffer+.14,W ; get high byte of the received checksum
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
205 cpfseq isr_mpr+1 ; = high byte of the calculated local checksum?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
206 bra isr_timer3_exit ; NO - exit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
207 ; YES to both - received telegram valid, copy data
0
heinrichsweikamp
parents:
diff changeset
208
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
209 movff ir_s8_buffer+.1, hud_status_byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
210 movff ir_s8_buffer+.2, sensor1_mv+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
211 movff ir_s8_buffer+.3, sensor1_mv+1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
212 movff ir_s8_buffer+.4, sensor2_mv+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
213 movff ir_s8_buffer+.5, sensor2_mv+1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
214 movff ir_s8_buffer+.6, sensor3_mv+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
215 movff ir_s8_buffer+.7, sensor3_mv+1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
216 movff ir_s8_buffer+.8, sensor1_ppO2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
217 movff ir_s8_buffer+.9, sensor2_ppO2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
218 movff ir_s8_buffer+.10,sensor3_ppO2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
219 movff ir_s8_buffer+.11,hud_battery_mv+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
220 movff ir_s8_buffer+.12,hud_battery_mv+1
0
heinrichsweikamp
parents:
diff changeset
221
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
222 bsf hud_connection_ok ; set manually for hwHUD w/o the HUD module
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
223 bra isr_timer3_reload ; reload timer and exit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
224
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
225 ; Process telegram received on S8 link
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
226 isr_timer3_s8:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
227 movlw .14 ; checksum shall be computed for 1st and next 14 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
228 rcall compute_IR_S8_checksum ; compute checksum
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
229
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
230 movf ir_s8_buffer+.15,W ; get low byte of the received checksum
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
231 cpfseq isr_mpr+0 ; = low byte of the calculated local checksum?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
232 bra isr_timer3_exit ; NO - exit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
233 movf ir_s8_buffer+.16,W ; get high byte of the received checksum
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
234 cpfseq isr_mpr+1 ; = high byte of the calculated local checksum?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
235 bra isr_timer3_exit ; NO - exit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
236 ; YES to both - received telegram valid, copy data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
237 movff ir_s8_buffer+.3, hud_status_byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
238 movff ir_s8_buffer+.13,hud_battery_mv+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
239 movff ir_s8_buffer+.14,hud_battery_mv+1
227
03946aa48fa5 NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents: 204
diff changeset
240
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
241 btfsc trigger_S8_data_update ; last data already processed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
242 bra isr_timer3_reload ; NO - skip copying new results
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
243 bsf trigger_S8_data_update ; YES - set flag for new data available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
244 ; - copy more data
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
245
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
246 movff ir_s8_buffer+.4, s8_rawdata_sensor1+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
247 movff ir_s8_buffer+.5, s8_rawdata_sensor1+1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
248 movff ir_s8_buffer+.6, s8_rawdata_sensor1+2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
249 movff ir_s8_buffer+.7, s8_rawdata_sensor2+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
250 movff ir_s8_buffer+.8, s8_rawdata_sensor2+1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
251 movff ir_s8_buffer+.9, s8_rawdata_sensor2+2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
252 movff ir_s8_buffer+.10,s8_rawdata_sensor3+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
253 movff ir_s8_buffer+.11,s8_rawdata_sensor3+1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
254 movff ir_s8_buffer+.12,s8_rawdata_sensor3+2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
255
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
256 isr_timer3_reload:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
257 movlw ir_timeout_value ; in multiples of 62.5 ms
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
258 movwf ir_s8_timeout ; reload timeout
0
heinrichsweikamp
parents:
diff changeset
259 isr_timer3_exit:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
260 clrf ir_s8_counter ; clear pointer
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
261 bcf PIR2,TMR3IF ; clear flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
262 return
0
heinrichsweikamp
parents:
diff changeset
263
heinrichsweikamp
parents:
diff changeset
264
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
265 ; compute checksum on data in RX buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
266 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
267 compute_IR_S8_checksum:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
268 movwf ir_s8_counter ; initialize loop counter from WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
269 movff ir_s8_buffer+0,isr_mpr+0 ; initialize low byte of the local checksum with first byte in buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
270 clrf isr_mpr+1 ; clear the high byte of the local checksum
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
271 lfsr FSR0,ir_s8_buffer ; load base address of the buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
272 compute_IR_S8_checksum_loop:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
273 movf PREINC0,W ; get next byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
274 addwf isr_mpr+0,F ; add it to the to checksum, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
275 movlw .0 ; no explicit data to add to the high byte...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
276 addwfc isr_mpr+1,F ; ... besides the carry
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
277 decfsz ir_s8_counter ; decrement number of bytes yet to do, all done?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
278 bra compute_IR_S8_checksum_loop ; NO - loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
279 return ; YES - done
113
heinrichsweikamp
parents: 50
diff changeset
280
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
281 ENDIF ; _external_sensor
113
heinrichsweikamp
parents: 50
diff changeset
282
0
heinrichsweikamp
parents:
diff changeset
283 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
284
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
285 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
286 ; Tasks every 62.5 ms: buttons, dimming, pressure/temp sensor and CPU speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
287 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
288 isr_tmr7:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
289 bcf PIR5,TMR7IF ; clear flag
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
290 movlw .248 ; rollover after 248 cycles -> 62.5 ms
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
291 movff WREG,TMR7H ; timer 7 is outside access RAM
0
heinrichsweikamp
parents:
diff changeset
292
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
293 call get_analog_switches ; get analog readings, CAUTION: returns in bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
294 banksel isr_backup ;back to ISR default bank
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
295
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 410
diff changeset
296 btfss INTCON3,INT1IE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
297 bra isr_tmr7_a
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 410
diff changeset
298 btfsc analog_sw2_pressed
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
299 rcall isr_switch_left ; get digital readings of left switch
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 410
diff changeset
300 isr_tmr7_a:
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 410
diff changeset
301 btfss INTCON,INT0IE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
302 bra isr_tmr7_b
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 410
diff changeset
303 btfsc analog_sw1_pressed
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
304 rcall isr_switch_right ; get digital readings of right switch
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 410
diff changeset
305 isr_tmr7_b:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
306 btfss block_sensor_interrupt ; sensor interrupts disabled?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
307 bra isr_tmr7_c ; NO - continue
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
308 return ; YES - done
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 469
diff changeset
309 isr_tmr7_c:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
310 movf max_CCPR1L,W ; dim value
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
311 cpfseq CCPR1L ; = current PWM value?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
312 rcall isr_dimm_tft ; NO - adjust until max_CCPR1L = CCPR1L
0
heinrichsweikamp
parents:
diff changeset
313
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
314 IFDEF _external_sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
315 decfsz ir_s8_timeout,F ; IR / S8 digital data still valid?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
316 bra isr_tmr7_2 ; YES - continue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
317 movlw ir_timeout_value ; NO - get timer reload in multiples of 62.5 ms
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
318 movwf ir_s8_timeout ; - reload the timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
319 btfss analog_o2_input ; - analog input available?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
320 bra isr_tmr7_1a ; NO - clear data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
321 btfss s8_digital_avail ; YES - S8 digital interface available?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
322 bra isr_tmr7_2 ; NO - must be analog interface in use, keep data
113
heinrichsweikamp
parents: 50
diff changeset
323 isr_tmr7_1a:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
324 clrf hud_status_byte ; S8/IR timeout clears all analog input readings to zero -> fallback will be triggered when in sensor mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
325 CLRI hud_battery_mv ; clear battery voltage
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
326
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
327 banksel sensor1_mv ; select bank where sensor data are stored
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
328 CLRI sensor1_mv ; clear all sensor data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
329 CLRI sensor2_mv ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
330 CLRI sensor3_mv ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
331 clrf sensor1_ppO2 ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
332 clrf sensor2_ppO2 ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
333 clrf sensor3_ppO2 ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
334 banksel isr_backup ; back to ISR default bank
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
335
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
336 bsf trigger_S8_data_update ; signal a data update
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
337 ENDIF
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
338
0
heinrichsweikamp
parents:
diff changeset
339 isr_tmr7_2:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
340 btfsc block_sensor_interrupt ; sensor interrupts disabled?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
341 return ; YES - abort
0
heinrichsweikamp
parents:
diff changeset
342
heinrichsweikamp
parents:
diff changeset
343 isr_sensor_state2:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
344 btfss sensor_state_counter,0 ; every 1/4 second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
345 bsf trigger_quarter_second ; set flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
346
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
347 btfss speed_is_normal ; CPU running on normal speed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
348 rcall isr_set_speed_to_normal ; NO - set CPU speed to normal
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
349
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
350 ; update surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
351 btfss update_surface_pressure ; shall update the surface pressure?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
352 bra isr_sensor_state2_1 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
353 bcf update_surface_pressure ; YES - clear request flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
354 MOVII pressure_abs_ref,pressure_surf ; - update surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
355
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
356 isr_sensor_state2_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
357 incf sensor_state_counter,F ; counts to eight for state machine
0
heinrichsweikamp
parents:
diff changeset
358
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
359 ; State 1: clear flags and average registers, get temperature (51 us) and start pressure integration (73.5 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
360 ; State 2: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
361 ; State 3: get temperature (51 us) and start pressure integration (73.5 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
362 ; State 4: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
363 ; State 5: get temperature (51 us) and start pressure integration (73.5 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
364 ; State 6: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
365 ; State 7: get temperature (51 us) and start pressure integration (73.5 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
366 ; State 8: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us) and build average for half-second update of temperature and pressure
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
367
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
368 movff sensor_state_counter,WREG ; WREG used as temp here...
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
369 dcfsnz WREG,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
370 bra sensor_int_state1_plus_restart ; do state 1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
371 dcfsnz WREG,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
372 bra sensor_int_state2 ; do state 2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
373 dcfsnz WREG,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
374 bra sensor_int_state1 ; do state 3
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
375 dcfsnz WREG,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
376 bra sensor_int_state2 ; do state 4
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
377 dcfsnz WREG,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
378 bra sensor_int_state1 ; do state 5
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
379 dcfsnz WREG,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
380 bra sensor_int_state2 ; do state 6
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
381 dcfsnz WREG,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
382 bra sensor_int_state1 ; do state 7
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
383
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
384 ; first, do state 2:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
385 call get_pressure_value ; state 2: get pressure (51 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
386 call get_temperature_start ; and start temperature integration (73.5 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
387 call calculate_compensation ; calculate temperature compensated pressure (27 us)
0
heinrichsweikamp
parents:
diff changeset
388
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
389 ; build average for pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
390 bcf STATUS,C ; clear carry bit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
391 rrcf pressure_abs_avg+1 ; divide by 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
392 rrcf pressure_abs_avg+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
393 bcf STATUS,C ; clear carry bit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
394 rrcf pressure_abs_avg+1 ; divide by 2, again
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
395 rrcf pressure_abs_avg+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
396
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
397 ; copy into result register
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
398 MOVII pressure_abs_avg,pressure_abs
0
heinrichsweikamp
parents:
diff changeset
399
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
400 ; build average for temperature
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
401 bcf STATUS,C ; clear carry bit by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
402 btfsc temperature_avg+1,7 ; sign bit set?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
403 bsf STATUS,C ; YES - copy sign bit to carry bit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
404 rrcf temperature_avg+1 ; divide signed temperature by 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
405 rrcf temperature_avg+0 ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
406 bcf STATUS,C ; clear carry bit by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
407 btfsc temperature_avg+1,7 ; sign bit set?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
408 bsf STATUS,C ; YES - copy sign bit to carry bit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
409 rrcf temperature_avg+1 ; divide signed temperature by 2 again (by 4 in total now)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
410 rrcf temperature_avg+0 ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
411 MOVII temperature_avg,temperature_cur ; store final result
0
heinrichsweikamp
parents:
diff changeset
412
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
413 ; check for temperature change
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
414 movf temperature_cur+0,W ; get current temperature, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
415 cpfseq temperature_last+0 ; compare with last temperature, equal?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
416 bra isr_sensor_state2_2 ; NO - temperature has changed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
417 movf temperature_cur+1,W ; get current temperature, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
418 cpfseq temperature_last+1 ; compare with last temperature, equal?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
419 bra isr_sensor_state2_2 ; NO - temperature has changed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
420 bra isr_sensor_state2_3 ; YES to both - no change
0
heinrichsweikamp
parents:
diff changeset
421
heinrichsweikamp
parents:
diff changeset
422 isr_sensor_state2_2:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
423 MOVII temperature_cur,temperature_last ; store current temperature as last temperature for next round
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
424 bsf trigger_temp_changed ; set flag for temperature change
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
425
0
heinrichsweikamp
parents:
diff changeset
426 isr_sensor_state2_3:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
427 ; reset state counter and set update flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
428 clrf sensor_state_counter ; reset state counter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
429 bsf trigger_pres_update ; signal a pressure update
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
430 btfss reset_max_pressure ; shall clear the max pressure?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
431 bra isr_sensor_state2_3a ; NO - continue with checking for pressure change
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
432 bcf reset_max_pressure ; YES - clear request flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
433 CLRI pressure_rel_max ; - clear max. pressure
0
heinrichsweikamp
parents:
diff changeset
434
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
435 isr_sensor_state2_3a:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
436 ; check for pressure change
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
437 movf pressure_abs+0,W ; get current pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
438 cpfseq pressure_abs_last+0 ; compare with last pressure, equal?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
439 bra isr_sensor_state2_4 ; NO - pressure has changed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
440 movf pressure_abs+1,W ; YES - get current pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
441 cpfseq pressure_abs_last+1 ; - compare with last pressure, equal?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
442 bra isr_sensor_state2_4 ; NO - pressure has changed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
443 bra isr_sensor_state2_5 ; YES - no change
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
444
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
445 isr_sensor_state2_4:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
446 MOVII pressure_abs,pressure_abs_last ; store current pressure as last pressure for next round
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
447 bsf trigger_pres_cur_changed ; signal a pressure change
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
448
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
449 isr_sensor_state2_5:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
450 ; compute relative pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
451 movf pressure_surf+0,W ; get surface pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
452 subwf pressure_abs+0,W ; WREG = pressure_abs - pressure_surf (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
453 movwf pressure_rel_cur+0 ; store relative pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
454 movf pressure_surf+1,W ; get surface pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
455 subwfb pressure_abs+1,W ; WREG = pressure_abs - pressure_surf (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
456 movwf pressure_rel_cur+1 ; store relative pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
457 btfss STATUS,N ; relative pressure < 0 ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
458 bra isr_sensor_state2_6 ; NO - OK, keep result
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
459 CLRI pressure_rel_cur ; YES - set relative pressure to zero
0
heinrichsweikamp
parents:
diff changeset
460
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
461 isr_sensor_state2_6:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
462 ; check for new max relative pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
463 movf pressure_rel_cur+0,W ; get current relative pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
464 subwf pressure_rel_max+0,W ; WREG = pressure_rel_max - pressure_rel_cur (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
465 movf pressure_rel_cur+1,W ; get current relative pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
466 subwfb pressure_rel_max+1,W ; WREG = pressure_rel_max - pressure_rel_cur (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
467 btfss STATUS,N ; result < 0, i.e. new max rel pressure?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
468 bra isr_sensor_state2_6a ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
469 MOVII pressure_rel_cur,pressure_rel_max ; YES - set new max rel pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
470 bsf trigger_pres_max_changed ; - signal a pressure max change
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
471
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
472 isr_sensor_state2_6a:
0
heinrichsweikamp
parents:
diff changeset
473
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
474 IFDEF _min_depth_option
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
475 ; check if min/max pressures shall be reset
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
476 btfss reset_trip_pressure ; shall reset the resettable min/max pressures?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
477 bra isr_sensor_state2_6b ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
478 bcf reset_trip_pressure ; YES - clear request flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
479 CLRI pressure_rel_max_trip ; - set max pressure to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
480 SETI pressure_rel_min_trip ; - set min pressure to biggest value possible
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
481 isr_sensor_state2_6b:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
482 ; check for new resettable max relative pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
483 movf pressure_rel_cur+0,W ; get current relative pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
484 subwf pressure_rel_max_trip+0,W ; WREG = pressure_rel_max - pressure_rel_cur (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
485 movf pressure_rel_cur+1,W ; get current relative pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
486 subwfb pressure_rel_max_trip+1,W ; WREG = pressure_rel_max - pressure_rel_cur (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
487 btfss STATUS,N ; result < 0, i.e. new max rel pressure?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
488 bra isr_sensor_state2_6c ; NO - continue checking for min depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
489 MOVII pressure_rel_cur,pressure_rel_max_trip ; YES - set new max rel pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
490 isr_sensor_state2_6c:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
491 ; check for new resettable min relative pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
492 movf pressure_rel_cur+0,W ; get current relative pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
493 subwf pressure_rel_min_trip+0,W ; WREG = pressure_rel_min - pressure_rel_cur (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
494 movf pressure_rel_cur+1,W ; get current relative pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
495 subwfb pressure_rel_min_trip+1,W ; WREG = pressure_rel_min - pressure_rel_cur (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
496 btfss STATUS,C ; result > 0, i.e. new min rel pressure?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
497 bra sensor_int_state_exit ; NO - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
498 MOVII pressure_rel_cur,pressure_rel_min_trip ; YES - set new min rel pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
499 ENDIF ; _min_depth_option
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
500 bra sensor_int_state_exit ; done
0
heinrichsweikamp
parents:
diff changeset
501
heinrichsweikamp
parents:
diff changeset
502
heinrichsweikamp
parents:
diff changeset
503 sensor_int_state1_plus_restart:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
504 ; clear average registers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
505 CLRI pressure_abs_avg
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
506 CLRI temperature_avg
0
heinrichsweikamp
parents:
diff changeset
507
heinrichsweikamp
parents:
diff changeset
508 sensor_int_state1:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
509 call get_temperature_value ; state 1: get temperature...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
510 call get_pressure_start ; ...and start pressure integration
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
511 bra sensor_int_state_exit
0
heinrichsweikamp
parents:
diff changeset
512
heinrichsweikamp
parents:
diff changeset
513 sensor_int_state2:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
514 call get_pressure_value ; state 2: get pressure (51 us)...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
515 call get_temperature_start ; ...and start temperature integration (73.5 us)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
516 call calculate_compensation ; .. and calculate temperature compensated pressure (233 us)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
517
0
heinrichsweikamp
parents:
diff changeset
518 sensor_int_state_exit:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
519 bra isr_adjust_speed ; set/restore CPU speed and return
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
520
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
521
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
522 isr_dimm_tft: ; adjust until max_CCPR1L = CCPR1L
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
523 btfsc tft_is_dimming ; is the display dimming?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
524 return ; YES - ignore
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
525 movf max_CCPR1L,W ; NO - proceed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
526 cpfsgt CCPR1L ; CCPR1L > max_CCPR1L ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
527 bra isr_dimm_tft2 ; NO - dim up
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
528 decf CCPR1L,F ; YES - dim down
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
529 return ; - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
530 isr_dimm_tft2:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
531 movf max_CCPR1L,W
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
532 sublw ambient_light_min_eco
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
533 cpfsgt CCPR1L ; CCPR1L > max_CCPR1L - ambient_light_min_eco ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
534 bra isr_dimm_tft3 ; NO - dim up slow
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
535 movlw .10 ; YES - dim up faster
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
536 addwf CCPR1L,F
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
537 isr_dimm_tft3:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
538 incf CCPR1L,F ; +1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
539 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
540
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
541
0
heinrichsweikamp
parents:
diff changeset
542 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
543 ; RTC interrupt on every 1/2 second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
544 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
545 isr_rtcc:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
546 bcf PIR3,RTCCIF ; clear flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
547 bsf trigger_half_second ; set flag for a new 1/2 second has begun
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
548 btfsc reset_timebase ; shall reset the timebase?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
549 bra isr_rtcc_1 ; YES - warp to new full second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
550 btg timebase_0sec ; NO - toggle the 1/2 second timebase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
551 btfsc timebase_0sec ; - did it toggled 1 -> 0 ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
552 return ; NO - on half second, done
0
heinrichsweikamp
parents:
diff changeset
553
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
554 isr_rtcc_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
555 ; new full second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
556 bsf trigger_full_second ; set flag for a new 1/1 second has begun
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
557
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
558 btfsc block_rtc_access ; ISR suspended from accessing the RTC?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
559 bra isr_rtcc_2 ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
560
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
561 banksel RTCCFG ; RTC registers are outside access RAM
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
562 bsf RTCCFG,RTCPTR1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
563 bsf RTCCFG,RTCPTR0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
564 banksel isr_backup ; back to ISR default bank
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
565
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
566 movff RTCVALL,rtc_year ; read year in BCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
567 movff RTCVALH,rtc_day ; dummy read
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
568 movff RTCVALL,rtc_day ; read day in BCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
569 movff RTCVALH,rtc_month ; read month in BCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
570 movff RTCVALL,rtc_hour ; read hour in BCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
571 movff RTCVALH,rtc_secs ; dummy read
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
572 movff RTCVALL,rtc_secs ; read seconds in BCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
573 movff RTCVALH,rtc_mins ; read minutes in BCD
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
574
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
575 ; Convert BCD to DEC and set registers
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
576 movf rtc_mins,W
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
577 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
578 movwf rtc_mins
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
579 movf rtc_secs,W
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
580 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
581 movwf rtc_secs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
582 movf rtc_hour,W
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
583 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
584 movwf rtc_hour
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
585 movf rtc_month,W
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
586 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
587 movwf rtc_month
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
588 movf rtc_day,W
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
589 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
590 movwf rtc_day
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
591 movf rtc_year,W
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
592 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
593 movwf rtc_year
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
594
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
595 isr_rtcc_2:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
596 ; get ambient light level and set max_CCPR1L
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
597 call get_ambient_level ; get ambient light level and set max_CCPR1L
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
598 banksel isr_backup ; back to ISR default bank (for safety only)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
599
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
600 rcall isr_battery_gauge ; calculate the current charge consumption and add it to the battery gauge
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
601 rcall isr_update_uptime ; increment overall OSTC uptime
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
602 rcall isr_update_timeout ; process the timeout timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
603
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
604 btfsc divemode ; in dive mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
605 rcall isr_divemode_1sec ; YES - do the every second dive mode tasks
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
606
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
607 btfsc divemode ; in dive mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
608 btfsc simulatormode ; YES - in simulator mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
609 rcall isr_update_lastdive_time ; NO - YES - increment the last dive time
0
heinrichsweikamp
parents:
diff changeset
610
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
611 ; reset the timebase if requested
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
612 btfss reset_timebase ; shall reset the timebase?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
613 bra isr_rtcc_3 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
614 bcf reset_timebase ; YES - clear request flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
615 clrf eventbase ; - clear all pending events
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
616 clrf timebase ; - clear all timebase flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
617 clrf timebase_secs ; - clear seconds timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
618 clrf timebase_mins ; - clear minutes timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
619 clrf simulator_time ; - clear minutes timer of simulator runtime as well
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
620 bsf trigger_half_second ; - set flag for a new 1/2 second has begun
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
621 bsf trigger_full_second ; - set flag for a new 1/1 second has begun
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
622 return ; - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
624 isr_rtcc_3:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
625 ; count-up the 2 seconds timebase timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
626 btg timebase_1sec ; toggle the 1 second timer bit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
627 btfss timebase_1sec ; did it toggled 1 -> 0 ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
628 btg timebase_2sec ; YES - toggle the 2 seconds timer bit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
629
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
630 ; count-up the seconds timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
631 incf timebase_secs,F ; increment seconds timer (may temporary become 60 here)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
632 movlw .59 ; max. for seconds timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
633 cpfsgt timebase_secs ; seconds timer > max.?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
634 return ; NO - done
0
heinrichsweikamp
parents:
diff changeset
635
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
636 ; new full minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
637 clrf timebase_secs ; YES - reset timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
638 bsf trigger_full_minute ; - set flag for a new minute has begun
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
639
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
640 btfsc divemode ; - in dive mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
641 btfsc simulatormode ; YES - in simulator mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
642 rcall inc_surface_interval ; NO - YES - increment surface interval
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
643
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
644 btfss simulatormode ; - in simulator mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
645 bra isr_rtcc_4 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
646 infsnz simulator_time,F ; YES - increment real runtime of the simulator, did wrap around (became zero)?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
647 setf simulator_time ; YES - disallow wrap-around, keep at 255 instead
0
heinrichsweikamp
parents:
diff changeset
648
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
649 isr_rtcc_4:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
650 incf timebase_mins,F ; - increment minutes timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
651 movlw .59 ; - max. for minutes timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
652 cpfsgt timebase_mins ; - minutes timer > max.?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
653 return ; NO - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
654
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
655 ; new full hour
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
656 clrf timebase_mins ; YES - reset timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
657 bsf trigger_full_hour ; - set flag for a new hour has begun
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
658 return ; - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
659
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
660
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
661 ; increment overall OSTC uptime
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
662 isr_update_uptime:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
663 incf uptime+0,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
664 clrf WREG
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
665 addwfc uptime+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
666 addwfc uptime+2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
667 addwfc uptime+3,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
668 return
0
heinrichsweikamp
parents:
diff changeset
669
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
670 ; increment time since last dive, called every second when not in dive mode (or when in simulator mode)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
671 isr_update_lastdive_time:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
672 incf lastdive_time+0,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
673 clrf WREG
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
674 addwfc lastdive_time+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
675 addwfc lastdive_time+2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
676 addwfc lastdive_time+3,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
677 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
678
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
679 ; process the timeout timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
680 isr_update_timeout:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
681 btfsc reset_timeout ; shall reset the timeout?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
682 bra isr_update_timeout_1 ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
683 tstfsz isr_timeout_timer ; NO - timeout timer already at zero?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
684 decfsz isr_timeout_timer ; NO - decrement timer, reached zero now?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
685 return ; YES / NO - nothing further to do
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
686 bsf trigger_timeout ; YES - set timeout flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
687 return ; - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
688 isr_update_timeout_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
689 bcf reset_timeout ; clear request flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
690 bcf trigger_timeout ; clear pending timeout trigger, if any
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
691 movff isr_timeout_reload,isr_timeout_timer ; reload timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
692 return ; done
0
heinrichsweikamp
parents:
diff changeset
693
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
694 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
695 ; Calculate charge drawn from the battery
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
696 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
697 isr_battery_gauge:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
698 btfsc block_battery_gauge ; access to battery gauge suspended?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
699 return ; YES - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
700 MOVLI current_sleepmode,isr_mpr ; NO - default to sleep mode with 100µA/3600 -> nAs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
701 btfss sleepmode ; - in sleep mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
702 rcall isr_battery_gauge2 ; NO - compute current consumption value into isr_lo and isr_hi
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
703 movf isr_mpr+0,W ; - 48 bit add of isr_mpr:2 with battery_gauge:6
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
704 addwf battery_gauge+0,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
705 movf isr_mpr+1,W
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
706 addwfc battery_gauge+1,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
707 clrf WREG
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
708 addwfc battery_gauge+2,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
709 addwfc battery_gauge+3,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
710 addwfc battery_gauge+4,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
711 addwfc battery_gauge+5,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
712 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
713
0
heinrichsweikamp
parents:
diff changeset
714 isr_battery_gauge2:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
715 ; set consumption rate in nAs - nano Ampere per second
0
heinrichsweikamp
parents:
diff changeset
716 ; Example:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
717 ; MOVLI .55556,isr_mpr ; 0.2 Ah / 3600 seconds per hour * 1e9s = nAs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
718 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
719 ; Remark: although all the constants are named current_xxxx, in reality they mean charge!
0
heinrichsweikamp
parents:
diff changeset
720
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
721 ; Calculate current consumption for LED backlight: 47*CCPR1L+272 (according to values in hwos.inc: 115*CCPR1L+216)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
722 movf CCPR1L,W ; get CCPR1L into WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
723 mullw current_backlight_multi ; PRODH:PRODL = k * WREG = current_backlight_multi * CCPR1L
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
724 ADDLI current_backlight_offset,PRODL ; PRODH:PRODL += current_backlight_offset
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
725 MOVII PRODL,isr_mpr ; copy result to isr_mpr
0
heinrichsweikamp
parents:
diff changeset
726
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
727 ; Add current for CPU and GPU
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
728 ; cpu_speed_state = ECO 3.10 mA -> 861 nAs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
729 ; = NORMAL 5.50 mA -> 1528 nAs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
730 ; = FASTEST 8.04 mA -> 2233 nAs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
731 btfss speed_is_eco ; speed = eco ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
732 bra isr_battery_gauge3 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
733 ADDLI current_speed_eco,isr_mpr ; YES - add current_speed_eco to isr_mpr
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
734 bra isr_battery_gauge5
0
heinrichsweikamp
parents:
diff changeset
735 isr_battery_gauge3:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
736 btfss speed_is_normal ; speed = normal?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
737 bra isr_battery_gauge4 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
738 ADDLI current_speed_normal,isr_mpr ; YES - add current_speed_normal to isr_mpr
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
739 bra isr_battery_gauge5
0
heinrichsweikamp
parents:
diff changeset
740 isr_battery_gauge4:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
741 ADDLI current_speed_fastest,isr_mpr ; speed is fastest, add current_speed_fastest to isr_mpr
0
heinrichsweikamp
parents:
diff changeset
742 isr_battery_gauge5:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
743 btfss ir_power ; IR enabled?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
744 bra isr_battery_gauge6 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
745 ADDLI current_ir_receiver,isr_mpr ; YES - add current_ir_receiver to isr_mpr
0
heinrichsweikamp
parents:
diff changeset
746 isr_battery_gauge6:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
747 btfss compass_enabled ; compass active?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
748 bra isr_battery_gauge7 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
749 ADDLI current_compass,isr_mpr ; YES - add current_compass to isr_mpr
0
heinrichsweikamp
parents:
diff changeset
750 isr_battery_gauge7:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
751 return
0
heinrichsweikamp
parents:
diff changeset
752
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
753
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
754 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
755 ; Every second tasks while in dive mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
756 ;
0
heinrichsweikamp
parents:
diff changeset
757 isr_divemode_1sec:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
758 decfsz sampling_timer,F ; decrement sampling timer, became zero?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
759 bra isr_divemode_1sec_1 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
760 bsf trigger_sample_divedata ; YES - set trigger flag for sampling dive data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
761 movff sampling_rate,sampling_timer; - reload timer
0
heinrichsweikamp
parents:
diff changeset
762
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
763 isr_divemode_1sec_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
764 btfss reset_timebase ; shall reset the timebase? (request flag will be cleared later)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
765 bra isr_divemode_1sec_2 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
766 CLRI total_divetime_secs ; YES - reset total dive time, seconds (2 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
767 clrf counted_divetime_secs ; - reset counted dive time, seconds (1 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
768 CLRI counted_divetime_mins ; - reset counted dive time, minutes (2 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
769 clrf apnoe_dive_secs ; - reset apnoe dive time, seconds (1 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
770 clrf apnoe_dive_mins ; - reset apnoe dive time, minutes (1 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
771 bcf apnoe_at_surface ; - apnoe mode starts in submerged state
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
772 return ; - done
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
773
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
774 isr_divemode_1sec_2:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
775 INCI total_divetime_secs ; increase total dive time (regardless of start_dive_threshold)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
776 btfss count_divetime ; shall the dive time be counted (regarding start_dive_threshold)?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
777 bra isr_divemode_1sec_4 ; NO (too shallow / apnoe at surface)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
778 incf counted_divetime_secs,F ; YES - increase dive time (displayed dive time)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
779 movlw d'59' ; - 60 seconds make a minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
780 cpfsgt counted_divetime_secs ; - next full minute reached?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
781 bra isr_divemode_1sec_3 ; NO - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
782 clrf counted_divetime_secs ; YES - reset seconds to 0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
783 INCI counted_divetime_mins ; - increase dive minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
784 bsf divetime_longer_1min ; - set flag for dive time exceeding 1 minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
785 ;bra isr_divemode_1sec_3 ; - done
0
heinrichsweikamp
parents:
diff changeset
786
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
787 isr_divemode_1sec_3: ; submerged
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
788 btfss FLAG_apnoe_mode ; in apnoe mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
789 return ; NO - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
790 btfss apnoe_at_surface ; - been at surface before?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
791 bra isr_divemode_1sec_3a ; NO - increment the dive time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
792 bcf apnoe_at_surface ; YES - a new dive has begun
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
793 bsf apnoe_new_dive ; - signal a new dive has begun
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
794 clrf apnoe_surface_secs ; - clear surface seconds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
795 clrf apnoe_surface_mins ; - clear surface minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
796 clrf apnoe_dive_secs ; - clear dive seconds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
797 clrf apnoe_dive_mins ; - clear dive minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
798 MOVII pressure_rel_cur,pressure_rel_max ; - reset max pressure to current pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
799 bsf trigger_pres_max_changed ; - signal a new maximum pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
800 isr_divemode_1sec_3a:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
801 incf apnoe_dive_secs,F ; increment dive time, seconds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
802 movlw d'59' ; 60 seconds make a minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
803 cpfsgt apnoe_dive_secs ; next full minute reached?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
804 return ; NO - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
805 clrf apnoe_dive_secs ; YES - reset seconds to 0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
806 incf apnoe_dive_mins,F ; - increment dive time, minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
807 return ; - done
0
heinrichsweikamp
parents:
diff changeset
808
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
809 isr_divemode_1sec_4: ; at surface
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
810 btfss FLAG_apnoe_mode ; in apnoe mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
811 return ; NO - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
812 bsf apnoe_at_surface ; YES - memorize been at the surface
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
813 incf apnoe_surface_secs,F ; - increment surface time, seconds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
814 movlw d'59' ; - 60 seconds make a minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
815 cpfsgt apnoe_surface_secs ; - next full minute reached?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
816 return ; NO - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
817 clrf apnoe_surface_secs ; YES - reset seconds to 0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
818 incf apnoe_surface_mins,F ; - increment surface time, minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
819 return ; - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
820
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
821
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
822
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
823
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
824
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
825
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
826 isr_divemode_1sec_3_dive:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
827
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
828
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
829 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
830 ; BCD to Binary conversion
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
831 ; Input WREG = value in BCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
832 ; Output WREG = value in binary
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
833 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
834 isr_rtcc_convert_BCD_DEC:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
835 movwf isr_lo
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
836 swapf isr_lo, W
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
837 andlw 0x0F ; W = tens
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
838 rlncf WREG, W ; W = 2 * tens
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
839 subwf isr_lo, F ; 16 * tens + ones - 2*tens
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
840 subwf isr_lo, F ; 14 * tens + ones - 2*tens
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
841 subwf isr_lo, W ; 12 * tens + ones - 2*tens
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
842 return
0
heinrichsweikamp
parents:
diff changeset
843
heinrichsweikamp
parents:
diff changeset
844
heinrichsweikamp
parents:
diff changeset
845 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
846 ; Check buttons
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
847 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
848 isr_switch_right:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
849 bcf INTCON,INT0IE ; disable INT0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
850 btfss flip_screen ; 180° flipped?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
851 bsf switch_right ; set flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
852 btfsc flip_screen ; 180° flipped?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
853 bsf switch_left ; set flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
854 bra isr_switch_common ; continue...
0
heinrichsweikamp
parents:
diff changeset
855
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
856 isr_switch_left:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
857 bcf INTCON3,INT1IE ; disable INT1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
858 btfss flip_screen ; 180° flipped?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
859 bsf switch_left ; set flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
860 btfsc flip_screen ; 180° flipped?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
861 bsf switch_right ; set flag
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
862 ;bra isr_switch_common ; continue...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
863
0
heinrichsweikamp
parents:
diff changeset
864 isr_switch_common:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
865 clrf TMR1L ; load timer1 for first press
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
866 movlw TMR1H_VALUE_FIRST ; in steps of 7.8125 ms
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
867 movwf TMR1H ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
868 bsf T1CON,TMR1ON ; start timer 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
869 bcf INTCON3,INT1IF ; clear flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
870 bcf INTCON,INT0IF ; clear flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
871 return
0
heinrichsweikamp
parents:
diff changeset
872
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
873
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
874 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
875 ; Button hold-down interrupt
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
876 ;
0
heinrichsweikamp
parents:
diff changeset
877 timer1int:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
878 bcf PIR1,TMR1IF ; clear flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
879 bcf INTCON,INT0IF ; clear flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
880 bcf INTCON3,INT1IF ; clear flag
451
66049b6f2c0b speedup analog presses
heinrichsweikamp
parents: 448
diff changeset
881 ; digital
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
882 btfss switch_left1 ; left button hold-down?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
883 bra timer1int_left ; YES
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
884 btfss switch_right2 ; right button hold-down?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
885 bra timer1int_right ; YES
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
886
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
887 ; analog
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
888 btfsc analog_sw2_pressed ; left button hold-down?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
889 bra timer1int_left ; YES
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
890 btfsc analog_sw1_pressed ; right button hold-down?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
891 bra timer1int_right ; YES
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
892
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
893 ; no button hold-down, stop Timer 1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
894 bcf T1CON,TMR1ON ; stop timer 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
895 bsf INTCON,INT0IE ; enable INT0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
896 bsf INTCON3,INT1IE ; enable INT1
451
66049b6f2c0b speedup analog presses
heinrichsweikamp
parents: 448
diff changeset
897 return
0
heinrichsweikamp
parents:
diff changeset
898
heinrichsweikamp
parents:
diff changeset
899 timer1int_left:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
900 btfss flip_screen ; 180° flipped?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
901 bsf switch_left ; (re-)set flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
902 btfsc flip_screen ; 180° flipped?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
903 bsf switch_right ; (re-)set flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
904 bra timer1int_common ; continue
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
905
0
heinrichsweikamp
parents:
diff changeset
906 timer1int_right:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
907 btfss flip_screen ; 180° flipped?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
908 bsf switch_right ; set flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
909 btfsc flip_screen ; 180° flipped?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
910 bsf switch_left ; (re-)set flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
911 ;bra timer1int_common ; continue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
912
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
913 timer1int_common: ; load timer1 for next pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
914 clrf TMR1L ; clear timer, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
915 movlw TMR1H_VALUE_CONT ; default to surface mode value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
916 btfsc divemode ; in dive mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
917 movlw TMR1H_VALUE_CONT_DIVE ; YES - overwrite with dive mode value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
918 movwf TMR1H ; write value to timer, high byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
919 return ; return from timer1int with timer1 kept running
0
heinrichsweikamp
parents:
diff changeset
920
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
921
0
heinrichsweikamp
parents:
diff changeset
922 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
923 ; Increment surface interval (counted in minutes) while still in desaturation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
924 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
925 ; int_O_desaturation_time is only computed while in start, surface mode,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
926 ; menue_tree or ghostwriter. So the ISR may clock surface_interval past
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
927 ; the actual surface interval time. But TFT_surface_lastdive will check
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
928 ; int_O_desaturation_time and in case int_O_desaturation_time is zero it
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
929 ; will not show surface_interval but lastdive_time instead. Thus the glitch
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
930 ; will remain invisible.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
931 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
932 inc_surface_interval: ; called every minute when not in dive mode (in banksel common context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
933 btfsc reset_surface_interval ; shall reset the surface interval timer?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
934 bra inc_surface_interval_1 ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
935 movff int_O_desaturation_time+0,isr_lo ; NO - check desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
936 movff int_O_desaturation_time+1,WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
937 iorwf isr_lo,W ; - inclusive-or low & high byte, desaturation time = 0 ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
938 bz inc_surface_interval_1 ; YES - reset surface interval timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
939 INCI surface_interval ; NO - increment surface interval
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
940 return ; - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
941 inc_surface_interval_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
942 bcf reset_surface_interval ; reset request flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
943 CLRI surface_interval ; reset surface interval timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
944 return ; done
0
heinrichsweikamp
parents:
diff changeset
945
heinrichsweikamp
parents:
diff changeset
946 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
947
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 570
diff changeset
948 END