changeset 361:88660a400338 64kByte Logbook

Updated 64K logbook to changeset 360.
author JeanDo
date Wed, 08 Jun 2011 01:37:14 +0200
parents 562f1bc79f3c (diff) d4ca9196e830 (current diff)
children 64da813d4726
files code_part1/OSTC_code_asm_part1/changelog.txt code_part1/OSTC_code_asm_part1/divemode.asm code_part1/OSTC_code_asm_part1/divemode_menu.asm code_part1/OSTC_code_asm_part1/isr.asm code_part1/OSTC_code_asm_part1/menu_reset.asm code_part1/OSTC_code_asm_part1/sleepmode.asm
diffstat 16 files changed, 209 insertions(+), 135 deletions(-) [+]
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/changelog.txt	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/changelog.txt	Wed Jun 08 01:37:14 2011 +0200
@@ -2,8 +2,12 @@
 BETA Version - Do NOT use for diving!
 BUGFIX: Ignore depths>130m in PC simulation
 BUGFIX: Avoid spurious CF55 stops with 3 gas or more
+BUGFIX: Average depth in Logbook (For dives made with >=1.91)
+CHANGE: CF02 now allows delay of more then 240seconds
+NEW: "Quit Sim" in divemode simulator menu for exiting the simulation
 NEW: Allow -2:00 to +2:00 adjustement per day (CF48).
 NEW: 1/10/100 steps in CF menu
+NEW: 64kByte Logbook (Doubled capacity compared to 1.90)
 
 New in 1.90 Stable:
 Stable release
--- a/code_part1/OSTC_code_asm_part1/definitions.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/definitions.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -36,7 +36,7 @@
 
 ;#DEFINE	__DEBUG	; 
 
-#DEFINE	logbook_profile_version	0x20        ; Do not touch!
+#DEFINE	logbook_profile_version	0x21        ; Do not touch!
 #DEFINE	T0CON_debounce	b'00000000'         ; Timer0 Switch Debounce
 
 #DEFINE		FT_SMALL		.0
@@ -333,6 +333,7 @@
 time_correction_value   res 1   ; Adds to Seconds on midnight
 gaslist_active          res 1	; Holds flags for active gases
 desaturation_time_buffer res 2	; buffer for desat time
+total_divetime_seconds	res 2	; counts dive seconds regardless of CF01 (18h max.)
 
 ;=============================================================================
 ; C-code Routines
@@ -425,7 +426,7 @@
 #DEFINE	second_FD			flag4,7	; 2nd 0xFD in EEPROM found
 #DEFINE	second_FA			flag4,7	; 2nd 0xFA in EEPROM found
 
-#DEfINE	eeprom_overflow		flag5,0	; EEPROM overflowed (>32KB)
+;#DEfINE	unused flag5,0	; unused
 #DEFINE	eeprom_blockwrite	flag5,1	; EEPROM blockwrite active
 #DEFINE Flag_4      		flag5,2	; unused
 #DEFINE	low_battery_state	flag5,3	;=1 if battery low
--- a/code_part1/OSTC_code_asm_part1/divemode.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/divemode.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -589,7 +589,7 @@
 
 ; shift address for header
 ; the header will be stored after the dive
-	incf_eeprom_address	d'47'				; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000
+	incf_eeprom_address	d'57'				; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000
 
 store_dive_data2:
     SAFE_2BYTE_COPY rel_pressure, lo
@@ -1333,7 +1333,28 @@
 	movff	char_O_CNS_fraction,WREG	; copy into bank1
 	call	write_external_eeprom		; Stores CNS%
 
-; Add additional 10bytes here.... mH
+	movff	avr_rel_pressure_total+0,WREG	; Average Depth
+	call	write_external_eeprom
+	movff	avr_rel_pressure_total+1,WREG	; Average Depth
+	call	write_external_eeprom
+
+	movff	total_divetime_seconds+0,WREG	; Total dive time (Regardless of CF01)
+	call	write_external_eeprom
+	movff	total_divetime_seconds+1,WREG	; Total dive time (Regardless of CF01)
+	call	write_external_eeprom
+
+	clrf	WREG
+	call	write_external_eeprom			; Spare6
+	clrf	WREG
+	call	write_external_eeprom			; Spare5
+	clrf	WREG
+	call	write_external_eeprom			; Spare4
+	clrf	WREG
+	call	write_external_eeprom			; Spare3
+	clrf	WREG
+	call	write_external_eeprom			; Spare2
+	clrf	WREG
+	call	write_external_eeprom			; Spare1
 
 	movlw	0xFB						; Header stop
 	call	write_external_eeprom
@@ -1404,13 +1425,16 @@
 	
 	bcf		divemode
 	incf	timeout_counter,F
-	GETCUSTOM8	d'2'					; diveloop_timeout
-	addlw	d'2'						; adds two seconds in case timout=zero!
-	btfsc	STATUS,C					; > 255?
-	movlw	d'255'						; Set to 255...
-	decf	WREG,F						; Limit to 254
-	cpfsgt	timeout_counter
-	bsf		divemode
+	movlw	d'0'
+	addwfc	timeout_counter2,F			; timeout is 15bits
+	GETCUSTOM15	d'2'					; diveloop_timeout
+	movff	lo,sub_a+0
+	movff	hi,sub_a+1
+	movff	timeout_counter, sub_b+0
+	movff	timeout_counter2, sub_b+1
+	call	sub16						;  sub_c = sub_a - sub_b
+	btfss	neg_flag					; Result negative?
+	bsf		divemode					; No, set flag
 	return
 
 timeout_divemode2:
@@ -1695,13 +1719,15 @@
 	clrf	apnoe_secs
 	clrf	divemins+0
 	clrf	divemins+1
+	clrf 	total_divetime_seconds+0
+	clrf 	total_divetime_seconds+1
 	clrf	menupos3
 	bcf		menu3_active
 	clrf	divesecs
 	clrf	samplesecs
 	clrf	apnoe_timeout_counter		; timeout in minutes
-	clrf 	timeout_counter				; takes care of the timeout
-	clrf 	timeout_counter2			; Here: counts to six, then store deco data and temperature
+	clrf 	timeout_counter				; takes care of the timeout (Low byte)
+	clrf 	timeout_counter2			; takes care of the timeout (High byte)
 	clrf	AlarmType					; Clear all alarms
 	bcf		event_occured				; clear flag
 	bcf		setpoint_changed			; clear flag
--- a/code_part1/OSTC_code_asm_part1/divemode_menu.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/divemode_menu.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -131,6 +131,8 @@
 	movlw	d'7'						; Number of entries for this menu+1 = 7
 	btfsc	display_set_xgas			; Are we in the Gas6 menu?
 	movlw	d'7'						; Number of entries for this menu+1 = 7
+	btfsc	display_set_simulator		; Are we in the simulator menu?
+	movlw	d'7'						; Number of entries for this menu+1 = 7
 	cpfseq	menupos						; =limit?
 	bra		test_switches_divemode_menu1; No!
 	movlw	d'1'						; Yes, reset to position 1!
@@ -348,6 +350,8 @@
 	bra		divemode_menu_simulator_p10	; Adjust +10m
 	dcfsnz	menupos,F
 	bra		divemode_menu_simulator_m10	; Adjust -10m
+	dcfsnz	menupos,F
+	bra		divemode_menu_simulator_quit; Adjust to zero m
 	bra		timeout_divemenu2			; quit underwater menu!
 
 divemode_menu_simulator_common:
@@ -366,7 +370,6 @@
 	movlw	HIGH	d'14000'
 	movwf	sim_pressure+1
 	return
-
 divemode_menu_simulator_common2:
 	movlw	LOW		d'1000'             ; Compare to 1bar == 0m == 1000 mbar.
 	subwf   sim_pressure+0,W
@@ -401,6 +404,13 @@
 	movwf	menupos						; reset cursor
 	bra		divemode_menu_simulator_common
 
+divemode_menu_simulator_quit:
+	movlw	LOW		d'1000'
+	movwf	sim_pressure+0
+	movlw	HIGH	d'1000'
+	movwf	sim_pressure+1
+	bra		timeout_divemenu2			; quit menu
+
 divemode_menu_simulator_p1:
 	movlw	d'100'
 	addwf	sim_pressure+0,F
--- a/code_part1/OSTC_code_asm_part1/english_text.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/english_text.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -96,7 +96,7 @@
 ; 32 custom function descriptors I (FIXED LENGTH = 15 chars).
     TCODE    .40,  .35,      "Start Dive  [m]"           ;036 Start Dive  [m]	(depth to switch to dive mode)
     TCODE    .40,  .35,      "End Dive    [m]"           ;037 End Dive    [m]	(depth to switch back to surface mode)
-    TCODE    .40,  .35,      "End Delay [min]"           ;038 End Delay [min]  	(duration dive screen stays after end of dive)
+    TCODE    .40,  .35,      "End Delay [sec]"           ;038 End Delay [sec]  	(duration dive screen stays after end of dive)
     TCODE    .40,  .35,      "Power Off [min]"           ;039 Power Off [min]
     TCODE    .40,  .35,      "Pre-menu  [min]"           ;040 Pre-menu  [min]	(Delais to keep surface-mode menus displayed)
     TCODE    .40,  .35,      "velocity[m/min]"           ;041 velocity[m/min]
@@ -391,4 +391,5 @@
 	TCODE	 .50,	.130,	 "Aborted!"					 ;304 Aborted
 ;@5 variant
     TCODE    .0,    .0,      "Future TTS"                ;305 Future TTS            (=10 chars. Title for @5 customview).
+    TCODE    .100,  .125,    "Quit Sim"                  ;306 Quit Sim (=8char max. Quit Simulator mode)
 ;=============================================================================
--- a/code_part1/OSTC_code_asm_part1/french_text.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/french_text.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -97,7 +97,7 @@
 ; 32 custom function descriptors I (FIXED LENGTH = 15 chars).
     TCODE    .40,  .35,      "Début Plong.[m]"           ;036 Start Dive  [m]	(depth to switch to dive mode)
     TCODE    .40,  .35,      "Fin Plongée [m]"           ;037 End Dive    [m]	(depth to switch back to surface mode)
-    TCODE    .40,  .35,      "Délai Fin [min]"           ;038 End Delay [min]  	(duration dive screen stays after end of dive)
+    TCODE    .40,  .35,      "Délai Fin [sec]"           ;038 End Delay [sec]  	(duration dive screen stays after end of dive)
     TCODE    .40,  .35,      "Eteindre  [min]"           ;039 Power Off [min]
     TCODE    .40,  .35,      "Pré-menu  [min]"           ;040 Pre-menu  [min]	(Delais to keep surface-mode menus displayed)
     TCODE    .40,  .35,      "Vitesse [m/min]"           ;041 velocity[m/min]
@@ -392,4 +392,5 @@
 	TCODE	 .50,	.130,	 "Aborted!"					 ;304 Aborted
 ;@5 variant
     TCODE    .0,    .0,      "DTR Réchap"                ;305 Future TTS            (=10 chars. Title for @5 customview).
+    TCODE    .100,  .125,    "Quit Sim"                  ;306 Quit Sim 				(=8char max. Quit Simulator mode)
 ;=============================================================================
--- a/code_part1/OSTC_code_asm_part1/german_text.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/german_text.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -97,7 +97,7 @@
 ; 32 custom function descriptors I (FIXED LENGTH = 15 chars).
     TCODE    .40,  .35,      "TG Start    [m]"           ;036 Start Dive  [m]	(depth to switch to dive mode)
     TCODE    .40,  .35,      "TG Ende     [m]"           ;037 End Dive    [m]	(depth to switch back to surface mode)
-    TCODE    .40,  .35,      "TGNachlauf[min]"           ;038 End Delay [min]  	(duration dive screen stays after end of dive)
+    TCODE    .40,  .35,      "TGNachlauf[sek]"           ;038 End Delay [sec]  	(duration dive screen stays after end of dive)
     TCODE    .40,  .35,      "Standby   [min]"           ;039 Power Off [min]
     TCODE    .40,  .35,      "Pre-Menü  [min]"           ;040 Pre-menu  [min]	(Delais to keep surface-mode menus displayed)
     TCODE    .40,  .35,      "Geschw. [m/min]"           ;041 velocity[m/min]
@@ -392,4 +392,5 @@
 	TCODE	 .40,	.130,	 "Abgebrochen!"				 ;304 Aborted
 ;@5 variant
     TCODE    .0,    .0,      "TTS @+Min."                ;305 Future TTS            (=10 chars. Title for @5 customview).
+    TCODE    .100,  .125,    "Ende Sim"                  ;306 Quit Sim (=8char max. Quit Simulator mode)
 ;=============================================================================
--- a/code_part1/OSTC_code_asm_part1/i2c_eeprom.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/i2c_eeprom.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -18,8 +18,8 @@
 ; known bugs:
 ; ToDo: use 2nd 32KB from external EEPROM for something
 
-incf_eeprom_address	macro	ext_ee_temp1	; Will increase eeprom_address:2 with the 8Bit value "ext_ee_temp1" and takes
-    	movlw	ext_ee_temp1                ; care of bank switching at 0x8000
+incf_eeprom_address	macro	ext_ee_temp1	; Will increase eeprom_address:2 with the 8Bit value "ext_ee_temp1"
+    	movlw	ext_ee_temp1                
     	call 	incf_eeprom_address0
 	endm
 
@@ -27,18 +27,18 @@
     	addwf		eeprom_address+0,F      ; increase address
     	movlw		d'0'
     	addwfc		eeprom_address+1,F
+		return
+;    	btfss		eeprom_address+1,7		; at address 8000?
+;    	return                              ; No, continue
+;    
+;    	; Yes, clear eeprom_address:2
+;    	clrf		eeprom_address+0		; Clear eeprom address
+;    	clrf		eeprom_address+1
+;    	return								; Done.
+;
+;=============================================================================
+; Will decrease eeprom_address:2 with the 8Bit value "ext_ee_temp1"
 
-    	btfss		eeprom_address+1,7		; at address 8000?
-    	return                              ; No, continue
-    
-    	; Yes, clear eeprom_address:2
-    	clrf		eeprom_address+0		; Clear eeprom address
-    	clrf		eeprom_address+1
-    	return								; Done.
-
-;=============================================================================
-; Will decrease eeprom_address:2 with the 8Bit value "ext_ee_temp1" and takes
-; care of bank switching at 0x8000
 
 decf_eeprom_address	macro	ext_ee_temp1
         movlw	ext_ee_temp1
@@ -49,13 +49,14 @@
         subwf		eeprom_address+0,F      ; decrease address: do a 16-8bits substract.
         movlw		d'0'
         subwfb		eeprom_address+1,F
-
-        btfss		eeprom_address+1,7		; at address 8000?
-        return                              ; No, done.
-
-        movlw		b'01111111'             ; yes, reset highbyte
-        movwf		eeprom_address+1
-    	return								; Done.
+		return
+;
+;        btfss		eeprom_address+1,7		; at address 8000?
+;        return                              ; No, done.
+;
+;        movlw		b'01111111'             ; yes, reset highbyte
+;        movwf		eeprom_address+1
+;    	return								; Done.
 
 ;=============================================================================
 
@@ -72,15 +73,14 @@
 	addwf		eeprom_address+0,F
 	movlw		d'0'
 	addwfc		eeprom_address+1,F
-	bcf			eeprom_overflow		
-	btfss		eeprom_address+1,7		; at address 8000?
-	return								; no, return
-
-	clrf		eeprom_address+0		; Clear eeprom address
-	clrf		eeprom_address+1
-	bsf			eeprom_overflow			; and set overflow bit
 	return
-
+;	btfss		eeprom_address+1,7		; at address 8000?
+;	return								; no, return
+;
+;	clrf		eeprom_address+0		; Clear eeprom address
+;	clrf		eeprom_address+1
+;	return
+;
 write_external_eeprom_block:			; Writes a block of 64Byte (one page in external EEPROM without stop condition
 #ifdef TESTING
 	; When Simulating with MPLabSIM, there is no way to emulate external EEPROM...
@@ -96,20 +96,21 @@
 	movlw		d'0'				; increase address
 	incf		eeprom_address+0,F	
 	addwfc		eeprom_address+1,F
-	bcf			eeprom_overflow		
-	
-	btfss		eeprom_address+1,7	; at address 8000
-	return						; no, return
-	
-	clrf		eeprom_address+0		; Clear eeprom address
-	clrf		eeprom_address+1
-	bsf			eeprom_overflow		; and set overflow bit
 	return
+
+;	btfss		eeprom_address+1,7	; at address 8000
+;	return						; no, return
+;	
+;	clrf		eeprom_address+0		; Clear eeprom address
+;	clrf		eeprom_address+1
+;	return
 I2CWRITE_BLOCK:
 	movwf		ext_ee_temp1				; Data byte in WREG
 	bsf			SSPCON2,SEN			; Start condition
 	rcall		WaitMSSP
-	movlw		b'10100110'			; Bit0=0: WRITE, Bit0=1: READ
+	movlw		b'10101110'			; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
+	btfss		eeprom_address+1,7		; Access Block2?
+	movlw		b'10100110'			; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
 	movwf		SSPBUF				; control byte
 	rcall		WaitMSSP	
 	rcall		I2C_WaitforACK
@@ -145,7 +146,9 @@
 	rcall		WaitMSSP	
 	bsf			SSPCON2,SEN			; Start condition
 	rcall		WaitMSSP
-	movlw		b'10100110'			; Bit0=0: WRITE, Bit0=1: READ
+	movlw		b'10101110'			; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
+	btfss		ext_ee_temp2,7		; Access Block2?
+	movlw		b'10100110'			; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
 	movwf		SSPBUF				; control byte
 	rcall		WaitMSSP	
 	btfsc		SSPCON2,ACKSTAT
@@ -160,8 +163,10 @@
 	
 	bsf			SSPCON2,RSEN		; Start condition
 	rcall		WaitMSSP
-	movlw		b'10100111'			; Bit0=0: WRITE, Bit0=1: READ
-	movwf		SSPBUF			; control byte
+	movlw		b'10101111'			; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
+	btfss		ext_ee_temp2,7		; Access Block2?
+	movlw		b'10100111'			; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
+	movwf		SSPBUF				; control byte
 	rcall		WaitMSSP	
 	rcall		I2C_WaitforACK
 
@@ -200,10 +205,16 @@
 	addwf		ext_ee_temp1,F
 	movlw		d'0'
 	addwfc		ext_ee_temp2,F
-	
-	btfsc		ext_ee_temp2,7			; 0x8000 reached?
+
+	movlw		0xFF	
+	cpfseq		ext_ee_temp2			; =0xFFFF
+	bra			get_free_EEPROM_location2d	; No
+	cpfseq		ext_ee_temp1			; =0xFFFF
+	bra			get_free_EEPROM_location2d	; No
+
 	bra			get_free_EEPROM_location3b	; yes
-	
+
+get_free_EEPROM_location2d:
 	bsf			SSPCON2, ACKEN		; no, send Ack
 	rcall		WaitMSSP				
 	bra			get_free_EEPROM_location2	; and continue search
@@ -232,15 +243,14 @@
 	addwf		eeprom_address+0,F
 	movlw		d'0'
 	addwfc		eeprom_address+1,F
-	bcf			eeprom_overflow		
-	btfss		eeprom_address+1,7	; at 0x8000?
-	return		; no, return
-	
-	clrf		eeprom_address+0	; Yes, clear address
-	clrf		eeprom_address+1
-	bsf			eeprom_overflow		; and set overflow bit
 	return
-
+;	btfss		eeprom_address+1,7	; at 0x8000?
+;	return		; no, return
+;	
+;	clrf		eeprom_address+0	; Yes, clear address
+;	clrf		eeprom_address+1
+;	return
+;
 I2CREAD3:						; block read start with automatic address increase 
 	rcall		I2CREAD_COMMON
 	; no Stop condition here
@@ -261,8 +271,11 @@
 	rcall		WaitMSSP	
 	bsf			SSPCON2,SEN		; Start condition
 	rcall		WaitMSSP
-	movlw		b'10100110'		; Bit0=0: WRITE, Bit0=1: READ
-	movwf		SSPBUF			; control byte
+
+	movlw		b'10101110'			; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
+	btfss		eeprom_address+1,7	; Access Block2?
+	movlw		b'10100110'			; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
+	movwf		SSPBUF				; control byte
 	rcall		WaitMSSP	
 	btfsc		SSPCON2,ACKSTAT
 	bra			I2CREAD			; EEPROM NOT acknowledged, retry!	
@@ -275,8 +288,11 @@
 	
 	bsf			SSPCON2,RSEN	; Start condition
 	rcall		WaitMSSP
-	movlw		b'10100111'		; Bit0=0: WRITE, Bit0=1: READ
-	movwf		SSPBUF			; control byte
+
+	movlw		b'10101111'			; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
+	btfss		eeprom_address+1,7	; Access Block2?
+	movlw		b'10100111'			; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
+	movwf		SSPBUF				; control byte
 	rcall		WaitMSSP	
 	rcall		I2C_WaitforACK
 	
@@ -290,8 +306,10 @@
 	movwf		ext_ee_temp1				; Data byte
 	bsf			SSPCON2,SEN			; Start condition
 	rcall		WaitMSSP
-	movlw		b'10100110'			; Bit0=0: WRITE, Bit0=1: READ
-	movwf		SSPBUF			; control byte
+	movlw		b'10101110'			; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
+	btfss		eeprom_address+1,7	; Access Block2?
+	movlw		b'10100110'			; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
+	movwf		SSPBUF				; control byte
 	rcall		WaitMSSP	
 	rcall		I2C_WaitforACK
 	movff		eeprom_address+1,SSPBUF	; High Address byte
--- a/code_part1/OSTC_code_asm_part1/interface.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/interface.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -167,14 +167,16 @@
 
 	DISPLAYTEXT .18						; "Header"
 
-	clrf		uart1_temp					; low address counter
-	clrf		uart2_temp					; high address counter
+	setf		uart1_temp					; low address counter
+	setf		uart2_temp					; high address counter
 
 menu_interface3:
 	bsf		SSPCON2,SEN					; Start condition
 	call		WaitMSSP
 
-	movlw		b'10100110'					; Bit0=0: WRITE, Bit0=1: READ
+	movlw		b'10101110'			; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
+	btfss		eeprom_address+1,7	; Access Block2?
+	movlw		b'10100110'			; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
 	movwf		SSPBUF					; control byte
 	call		WaitMSSP	
 	btfsc		SSPCON2,ACKSTAT
@@ -189,7 +191,10 @@
 	bsf		SSPCON2,RSEN				; Start condition
 	call		WaitMSSP
 
-	movlw		b'10100111'					; Bit0=0: WRITE, Bit0=1: READ
+	movlw		b'10101111'			; Bit0=0: WRITE, Bit0=1: READ, BLOCK2
+	btfss		eeprom_address+1,7	; Access Block2?
+	movlw		b'10100111'			; No, -> Bit0=0: WRITE, Bit0=1: READ, BLOCK1
+
 	movwf		SSPBUF					; control byte
 	call		WaitMSSP	
 	call		I2C_WaitforACK
@@ -199,27 +204,21 @@
 menu_interface2:
 	call		rs232_wait_tx				; wait for UART
 
-	bsf			SSPCON2, RCEN				; Enable recieve mode
-	call		WaitMSSP	
-
-	movff		SSPBUF, TXREG
-
 	movlw		d'1'
 	addwf		uart1_temp,F
 	movlw		d'0'
 	addwfc		uart2_temp,F
 
-	btfsc		uart2_temp,7				; 32KB done?
-	bra			menu_interface4				; Yes
-	
-	bsf			SSPCON2, ACKEN				; Ack
-	call		WaitMSSP	
-	bra			menu_interface2				; go on
+; Slow but safe...
+	call		I2CREAD2					; same as I2CREAD but with automatic address increase 
+	movff		SSPBUF, TXREG
 
-menu_interface4:
-	bsf			SSPCON2, PEN				; Stop
-	call		WaitMSSP	
-	
+	movlw		0xFF
+	cpfseq		uart2_temp					;=0xFFFF?
+	bra			menu_interface2				; No, continue
+	cpfseq		uart1_temp					;=0xFFFF?
+	bra			menu_interface2				; No, continue
+
 	DISPLAYTEXT	.20						; Done.
 
 	WAITMS	d'250'
--- a/code_part1/OSTC_code_asm_part1/isr.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/isr.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -343,12 +343,17 @@
 ; Increase re-setable average depth divetime counter
 		incf		average_divesecs+0,F	; increase stopwatch registers	
 		btfsc		STATUS,Z
-		incf		average_divesecs+1,F	; increase stopwatch registers	
-
+		incf		average_divesecs+1,F	; increase stopwatch registers
+; Increase total divetime (Regardless of CF01)
+		incf		total_divetime_seconds+0,F	; increase stopwatch registers	
+		btfsc		STATUS,Z
+		incf		total_divetime_seconds+1,F	; increase stopwatch registers
+	
 		btfss		divemode2				; displayed divetime is running?
 		bra			RTCisr2					; No (e.g. too shallow)
 
-		incf		divesecs,F				; increase divetime registers
+; increase divetime registers (Displayed dive time)
+		incf		divesecs,F				
 		movlw		d'59'
 		cpfsgt		divesecs
 		bra			RTCisr1a
--- a/code_part1/OSTC_code_asm_part1/menu_logbook.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/menu_logbook.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -71,14 +71,27 @@
 
     ;---- fast loop: check every other byte ----------------------------------
 menu_logbook2:
-    infsnz      divemins+0,F            ; increase 16Bit value
-	incf        divemins+1,F
-    infsnz      divemins+0,F            ; increase 16Bit value, twice
-	incf        divemins+1,F
+	movlw		d'2'
+	addwf		divemins+0,F
+	movlw		d'0'
+	addwfc		divemins+1,F			; increase 16Bit value, twice
 
-	btfsc		divemins+1,7            ; At 0x8000?
+	movlw		0xFF
+	cpfseq		divemins+1				; =0xFFFF ?
+	bra			menu_logbook2a			; No
+	cpfseq		divemins+0				; =0xFFFF ?
+	bra			menu_logbook2a			; No
 	bra			menu_logbook_reset      ; yes, restart (if not empty)
 
+menu_logbook2a:
+	movlw		0x00
+	cpfseq		divemins+1				; =0x0000 ?
+	bra			menu_logbook2b			; No
+	cpfseq		divemins+0				; =0x0000 ?
+	bra			menu_logbook2b			; No
+	bra			menu_logbook_reset      ; yes, restart (if not empty)
+
+menu_logbook2b:
 	decf_eeprom_address	d'2'			; -2 to eeprom address.
 
 	call		I2CREAD					; reads one byte (Slow! Better use Blockread!)
@@ -124,6 +137,7 @@
 	bra			menu_logbook3b				; No, Nothing to do
 
 	bsf			all_dives_shown				; Yes
+	bsf			logbook_page_not_empty
 	bra			menu_logbook_display_loop2	; rcall of get_free_eeprom_location not required here (faster)
 
 
@@ -449,9 +463,6 @@
 	call		I2CREAD2				; read Air pressure
 	movff		SSPBUF,hi
 
-;	movff		lo,average_depth_hold+2
-;	movff		hi,average_depth_hold+3		; Store here for correct average
-
 	bsf			leftbind
 	output_16							; Air pressure before dive
 	STRCAT      "mbar "
@@ -507,17 +518,13 @@
 	movff		SSPBUF,divisor_nuy2			; Store divisor
 	incf_eeprom_address	d'2'				; Skip 2Bytes in EEPROM (faster)
 	; 2 bytes salinity, GF
+	btfss	logbook_format_0x21				; 10byte extra?
+	bra		display_profile2d				; No
+	incf_eeprom_address	d'10'				; Skip another 10 byte from the header for 0x21 format
+	; Average Depth, spare bytes
 
 display_profile2d:
 	; Start Profile display
-
-;	clrf		average_divesecs+0
-;	clrf		average_divesecs+1			; Counts x-pixels for average
-;	clrf		average_depth_hold_total+0
-;	clrf		average_depth_hold_total+1
-;	clrf		average_depth_hold_total+2
-;	clrf		average_depth_hold_total+3	; Track average depth here...
-;
 ; Write 0m X-Line..
 	movlw		color_grey	
 	call		PLED_set_color				; Make this configurable?
@@ -962,18 +969,6 @@
 	return
 
 profile_view_get_depth_new1:
-;	incf		average_divesecs+0,F			
-;	movlw		d'0'
-;	addwfc		average_divesecs+1,F			; counter for average depth
-;	; add depth to average registers
-;	movf		lo,W
-;	addwf		average_depth_hold_total+0,F
-;	movf		hi,W
-;	addwfc		average_depth_hold_total+1,F
-;	movlw		d'0'
-;	addwfc		average_depth_hold_total+2,F
-;	addwfc		average_depth_hold_total+3,F 	; Will work up to 9999mBar*60*60*24=863913600mBar
-;
 	btfsc		event_occured				; Was there an event attached to this sample?
 	rcall		profile_view_get_depth_new2	; Yes, get information about this event
 
@@ -1018,7 +1013,6 @@
 	call		PLED_set_color				; Set Color...
 	return		;(The two bytes indicating the manual gas change will be ignored in the standard "ignore loop" above...)
 
-
 ;Keep comments for future temperature graph
 ;	call		I2CREAD2					; ignore byte
 ;	decfsz		timeout_counter2,F			; reduce counter
@@ -1128,6 +1122,11 @@
 	cpfsgt		lo							; Skip if lo>13
 	bra			display_listdive2			; use old (Pre 0x20) format
 
+	bsf			logbook_format_0x21		; Set flag for new 0x21 Format
+	movlw		0x21
+	cpfseq		lo						; Skip if 0x21
+	bcf			logbook_format_0x21		; Clear flag for new 0x21 Format
+
 	call		I2CREAD4					; Skip Profile version (Block read)
 	movff		SSPBUF,lo					; in new format, read month
 
@@ -1161,4 +1160,7 @@
 	output_16								; Divetime minutes
 	STRCAT_PRINT "'"                    	; Display header-row in list
 	incf_eeprom_address	d'37'				; 12 Bytes read from header, skip 37 Bytes in EEPROM (Remaining Header)
-	return
+	btfss	logbook_format_0x21				; 10byte extra?
+	return									; No, Done.
+	incf_eeprom_address	d'10'				; Skip another 10 byte from the header for 0x21 format
+	return
\ No newline at end of file
--- a/code_part1/OSTC_code_asm_part1/menu_reset.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/menu_reset.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -110,7 +110,7 @@
     ;                          DEFAULT   MIN     MAX
 	CF_DEFAULT    CF_CENTI,	    d'100', d'50',  d'250'  ; dive_threshold	        100cm
 	CF_DEFAULT    CF_CENTI,	    d'30',  d'10',  d'100'  ; surf_threshold        	30cm
-	CF_DEFAULT    CF_SEC,	    d'240', d'30',  d'240'  ; diveloop_timeout      	240s
+	CF_DEFAULT    CF_INT15,	    d'240', d'0',   d'600'  ; diveloop_timeout      	240s
 	CF_DEFAULT    CF_SEC,	    d'120', d'30',  d'240'  ; surfloop_timeout	        120s
 	CF_DEFAULT    CF_SEC,	    d'5',   d'1',   d'30'   ; premenu_timeout	        5s
 
@@ -462,7 +462,7 @@
 	clrf	eeprom_address+0
 	clrf	eeprom_address+1
 
-	movlw	d'2'
+	movlw	d'4'
 	movwf	temp3
 reset_eeprom02:
 	clrf	temp4
@@ -482,7 +482,7 @@
 	decfsz	temp4,F
 	bra		reset_eeprom01				; do this 256 times
 	decfsz	temp3,F
-	bra		reset_eeprom02				; and this all 2 times -> 512 *64Bytes = 32KB
+	bra		reset_eeprom02				; and this all 4 times -> 1024 *64Bytes = 64KB
 
 	bcf		eeprom_blockwrite			; clear blockwrite flag
 
--- a/code_part1/OSTC_code_asm_part1/pled_outputs.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/pled_outputs.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -2345,6 +2345,7 @@
         DISPLAYTEXT	.251			; - 1m
         DISPLAYTEXT	.252			; +10m
         DISPLAYTEXT	.253			; -10m
+		DISPLAYTEXTH .306			; Quit Sim
         return
 
 ;-----------------------------------------------------------------------------
@@ -2674,7 +2675,7 @@
 	cpfseq	hi				; All gases shown?
 	bra		PLED_gas_list_loop	; No
 
-	DISPLAYTEXT		d'122'		; Gas 6..
+	DISPLAYTEXT		d'122'		; More
 	return					;  return (OC mode)
 
 PLED_splist_start:	
--- a/code_part1/OSTC_code_asm_part1/simulator.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/simulator.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -24,7 +24,7 @@
 ; ToDo: 
 
 menu_simulator:
-	movlw	d'1'
+	movlw	d'3'
 	movwf	logbook_temp1		; Bottom time
 	movlw	d'15'
 	movwf	logbook_temp2		; Max. Depth
--- a/code_part1/OSTC_code_asm_part1/sleepmode.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/sleepmode.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -74,6 +74,8 @@
 
 	rcall	pressuretest_sleep_fast	; Gets pressure without averaging (faster!)
 
+    SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure	; copy for compatibility
+
 	call	check_temp_extrema		; Check for temperature extremas
 
 	call	deco_calc_CNS_decrease_15min		; compute CNS decay in sleep only
@@ -131,12 +133,12 @@
 
 	rcall	pressuretest_sleep_fast	; Gets pressure without averaging (faster!)
 
-    ; compare current ambient pressure with threshold CF6==1160mbar.
+        ; compare current ambient pressure with threshold CF6==1160mbar.
 	GETCUSTOM15	d'6'				; loads pressure threshold into lo,hi
 	movff	lo,sub_a+0				; power on if ambient pressure is greater threshold
 	movff	hi,sub_a+1	
-    SAFE_2BYTE_COPY amb_pressure, sub_b
-	call	sub16					; Is (1160mbar - amb_pressure) < 0 ?
+        SAFE_2BYTE_COPY amb_pressure_avg, sub_b
+	call	sub16					; Is (1160mbar - averaged(amb_pressure)) < 0 ?
 	bsf		sleepmode
 	btfsc	neg_flag				; Wake up from Sleep?
 	bcf		sleepmode				; amb_pressure>pressure_offset_divemode: wake up!
@@ -182,6 +184,8 @@
 	nop
 	sleep								; Wait at least 35ms (every 16.5ms Timer1 wakeup)
 	call		get_pressure_value		; State2: Get pressure (51us)
+	clrf		amb_pressure_avg+0
+	clrf		amb_pressure_avg+1			; clear for sleep routine
 	call		calculate_compensation		; calculate temperature compensated pressure (233us)
 	return
 
--- a/code_part1/OSTC_code_asm_part1/spanish_text.asm	Wed Jun 08 00:01:53 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/spanish_text.asm	Wed Jun 08 01:37:14 2011 +0200
@@ -96,7 +96,7 @@
 ; 32 custom function descriptors I (FIXED LENGTH = 15 chars).
     TCODE    .40,  .35,      "Buceo Inic. [m]"           ;036 Start Dive  [m]	(depth to switch to dive mode)
     TCODE    .40,  .35,      "Buceo Fin.  [m]"           ;037 End Dive    [m]	(depth to switch back to surface mode)
-    TCODE    .40,  .35,      "Retras Fin[min]"           ;038 End Delay [min]  	(duration dive screen stays after end of dive)
+    TCODE    .40,  .35,      "Retras Fin[sec]"           ;038 End Delay [sec]  	(duration dive screen stays after end of dive)
     TCODE    .40,  .35,      "Apagado   [min]"           ;039 Power Off [min]
     TCODE    .40,  .35,      "Pre-menú  [min]"           ;040 Pre-menu  [min]	(Delais to keep surface-mode menus displayed)
     TCODE    .40,  .35,      "Vel.    [m/min]"           ;041 velocity[m/min]
@@ -391,4 +391,5 @@
 	TCODE	 .50,	.130,	 "¡Aborta!"					 ;304 Aborted
 ;@5 variant
     TCODE    .0,    .0,      "Futuro TTS"                ;305 Future TTS            (=10 chars. Title for @5 customview).
+    TCODE    .100,  .125,    "Quit Sim"                  ;306 Quit Sim (=8char max. Quit Simulator mode)
 ;=============================================================================