Temp values to EEprom and bck!

cactusface

Senior Member
Hi All,
I have just about built my Greenhouse data-Logger, but I think I'll need a bit of a hand with the temp reading with storing and reading it back. I would like to use readtemp12 so need to put it in say (w1), then i2cwrite, mem(%10100000),(w1) then covert it with something like bintoascii w1,b5,b6,b7,b8,b9. I then want to check for min and max temps, with min in mem(%10100000) and max in mem+2 No code available but my first attemps just produced rubbish. It would I think be a lot easier using just an 8 bit byte value, it might be the way I'm reading it back from mem?

Anyone got any simple ideas!

Regards
Mel.
 

nick12ab

Senior Member
You need to post your code and also clarify on what you are trying to do:

with min in mem(%10100000) and max in mem+2
So are you using a separate EEPROM to store the maximum temperatures from the EEPROM used to store the minimum temperatures? I doubt that.

Please read the i2c tutorial which will tell you that the way to address an EEPROM is to use the %10100000 address in the hi2csetup/i2cslave command and use an integer address (0, 1, 2...) in the hi2cin/hi2cout/readi2c/writei2c commands.
 

cactusface

Senior Member
Reading WORD EEprom mem

Hi Nick,
I knew someone would say that!! So I will attach my code. Yes I am using an external EEprom for min and max temps. I have used i2c before and don't usually have a problem with it, I don't think that as such is the problem. I think it's my reading and converting it from mem that's the problem. My almost completed project is here http://www.picaxeforum.co.uk/showthread.php?21659-My-Shield


Code:
;
 *******************************
;    Filename: 	ShieldDataLogger
;    Date: 		06/07/2012	
;    File Version: v2.00 	
;    Written by: 	MS	
;    Function:	Greenhouse Data logger	
;    Last Revision:
;    Target PICAXE:My20M2Shield	
; ******************************* 

symbol intemp = b.0
symbol outtemp = b.1
symbol key= b.2
symbol light = b.3
;symbol humid = b.4

symbol All_clear=%00000000
symbol line1=128	      'Set up LCD line codes
symbol line2=192		'Start location for each line
symbol line3=148
symbol line4=212
symbol RTC=%11010000	'DS1307 Address
symbol MEM=%10100000	'EEprom Address
symbol MEM2=$8001		'2nd EEprom Address
symbol mintemp=$f770
symbol maxtemp=mintemp+2
symbol sun=b0
symbol baud=T2400		'Serial baud rate baud,N,8,1


pause 500			'Give system time to power up and stabilize?

serout c.0,baud,(255,1)	'switch backlight on
pause 200

Main:
gosub keys
gosub gettime
gosub convert
serout c.0,baud,(254,line1,b12,b13,"/",b14,b15,"/20",b16,b17," ",b10,b11,":",b8,b9,":",b19,b20," ")'display current date & time


gosub tempIn
gosub check

serout c.0,baud, (254,line2,"Inside Temp:",b9,b7,b6,".",b5,b4,"c")'display local temp.
gosub tempOut
serout c.0,baud, (254,line3,"Outside Temp:",b9,b7,b6,".",b5,b4,"c")'display remote temp.

readadc light,sun 
serout c.0,baud,(254,line4,"light value = ", #sun,"   ")


goto main

;JOBS

job1:
gosub clearlcd
serout c.0,baud,(254,line1,253,2)
i2cslave mem,i2cfast,i2cword	
readi2c mintemp,(w10)
gosub checkpoint 
serout c.0,baud,(254,line3,"   Min Temp",b8,b7,b6,".",b5,b4,"c")      																											
i2cread maxtemp,(w10)
gosub checkpoint
serout c.0,baud,(254,line4,"   Max Temp",b8,b7,b6,".",b5,b4,"c")
wait 3
return

job2:
gosub clearlcd
serout c.0,baud,(254,line1,253,3)
wait 2
return

job3:
gosub clearlcd
serout c.0,baud,(254,line1,253,4)
wait 2
return



job4:
gosub clearlcd
serout c.0,baud,(254,line1,253,5)
wait 2
return
;**************************************
;SubRounites

check:				'record MIN & MAX temps in memory.

i2cslave MEM,i2cfast,i2cword 

readi2c mintemp,(w12)
if w10<w12 then goto lowtemp
 
check2:
readi2c maxtemp,(w12)
if w10>w12 then gosub hightemp
return

lowtemp:
writei2c mintemp,(w10)
goto check2
return

hightemp:
writei2c maxtemp,(w10)
return
;--------------------------------------------
gettime:

i2cslave RTC,i2cslow,i2cbyte	'set up i2c DS1307 RTC
readi2c 0,(b0,b1,b2,b3,b4,b5,b6,b7)	'read Time and Date
return

convert:
bcdtoascii b0,b19,b20		'Secs Convert to ASCII
bcdtoascii b1,b8,b9		'Mins 
bcdtoascii b2,b10,b11		'Hours
bcdtoascii b3,b21,b22         'DayOfWeek
bcdtoascii b4,b12,b13		'Date
bcdtoascii b5,b14,b15		'Month
bcdtoascii b6,b16,b17		'Year
return
;--------------------------------------------------

tempIn:
Readtemp12 intemp,w10                                 'read in result from ds18b20 and convert to 0.06 RES 
gosub check
checkpoint:                                       
let b9 =160                                       'Display space (32)
if w10 > 64655 then                                'info     - 55 degrees          = 64656
let b9 =45                                        'Display - (45) MINUS
w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
endif                                
w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
                                          
bintoascii w10,b8,b7,b6,b5,b4 
if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
return                       
;--------------------------------------------------
tempOut:
Readtemp12 outtemp,w10                                 'read in result from ds18b20 and convert to 0.06 RES                                        
let b9 =160                                       'Display space (32)
if w10 > 64655 then                                'info     - 55 degrees          = 64656
let b9 =45                                        'Display - (45) MINUS
w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
endif                                
w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
                                          
bintoascii w10,b8,b7,b6,b5,b4 
if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
return
;---------------------------------------------------
keys:
readadc key,b11
if b11=0 then return:endif
if b11=113 then goto job1
if b11=69  then goto job2
if b11=28  then goto job3
if b11=46 then goto job4
return
;---------------------------------------------------

Any help welcome.

Regards
Mel.
 

Attachments

nick12ab

Senior Member
White spacing?
Code:
#picaxe 20m2
; *******************************
;    Filename: 	ShieldDataLogger
;    Date: 		06/07/2012	
;    File Version: v2.00 	
;    Written by: 	MS	
;    Function:	Greenhouse Data logger	
;    Last Revision:
;    Target PICAXE:My20M2Shield	
; ******************************* 

symbol intemp = b.0
symbol outtemp = b.1
symbol key= b.2
symbol light = b.3
;symbol humid = b.4

symbol All_clear=%00000000
symbol line1=128	      'Set up LCD line codes
symbol line2=192		'Start location for each line
symbol line3=148
symbol line4=212
symbol RTC=%11010000	'DS1307 Address
symbol MEM=%10100000	'EEprom Address
symbol MEM2=$8001		'2nd EEprom Address
symbol mintemp=$f770
symbol maxtemp=mintemp+2
symbol sun=b0
symbol baud=T2400		'Serial baud rate baud,N,8,1


	pause 500			'Give system time to power up and stabilize?
	
	serout c.0,baud,(255,1)	'switch backlight on
	pause 200

Main:
	gosub keys
	gosub gettime
	gosub convert
	serout c.0,baud,(254,line1,b12,b13,"/",b14,b15,"/20",b16,b17," ",b10,b11,":",b8,b9,":",b19,b20," ")'display current date & time
	
	
	gosub tempIn
	gosub check
	
	serout c.0,baud, (254,line2,"Inside Temp:",b9,b7,b6,".",b5,b4,"c")'display local temp.
	gosub tempOut
	serout c.0,baud, (254,line3,"Outside Temp:",b9,b7,b6,".",b5,b4,"c")'display remote temp.
	
	readadc light,sun 
	serout c.0,baud,(254,line4,"light value = ", #sun,"   ")
	
	
	goto main

;JOBS

job1:
	gosub clearlcd
	serout c.0,baud,(254,line1,253,2)
	i2cslave mem,i2cfast,i2cword	
	readi2c mintemp,(w10)
	gosub checkpoint 
	serout c.0,baud,(254,line3,"   Min Temp",b8,b7,b6,".",b5,b4,"c")      																											
	i2cread maxtemp,(w10)
	gosub checkpoint
	serout c.0,baud,(254,line4,"   Max Temp",b8,b7,b6,".",b5,b4,"c")
	wait 3
	return

job2:
	gosub clearlcd
	serout c.0,baud,(254,line1,253,3)
	wait 2
	return

job3:
	gosub clearlcd
	serout c.0,baud,(254,line1,253,4)
	wait 2
	return



job4:
	gosub clearlcd
	serout c.0,baud,(254,line1,253,5)
	wait 2
	return
;**************************************
;SubRounites

check:				'record MIN & MAX temps in memory.

	i2cslave MEM,i2cfast,i2cword 
	
	readi2c mintemp,(w12)
	if w10<w12 then goto lowtemp
 
check2:
	readi2c maxtemp,(w12)
	if w10>w12 then gosub hightemp
	return

lowtemp:
	writei2c mintemp,(w10)
	goto check2
	return

hightemp:
	writei2c maxtemp,(w10)
	return
;--------------------------------------------
gettime:
	
	i2cslave RTC,i2cslow,i2cbyte	'set up i2c DS1307 RTC
	readi2c 0,(b0,b1,b2,b3,b4,b5,b6,b7)	'read Time and Date
	return

convert:
	bcdtoascii b0,b19,b20		'Secs Convert to ASCII
	bcdtoascii b1,b8,b9		'Mins 
	bcdtoascii b2,b10,b11		'Hours
	bcdtoascii b3,b21,b22         'DayOfWeek
	bcdtoascii b4,b12,b13		'Date
	bcdtoascii b5,b14,b15		'Month
	bcdtoascii b6,b16,b17		'Year
	return
;--------------------------------------------------

tempIn:
	Readtemp12 intemp,w10                                 'read in result from ds18b20 and convert to 0.06 RES 
	gosub check
checkpoint:                                       
	let b9 =160                                       'Display space (32)
	if w10 > 64655 then                                'info     - 55 degrees          = 64656
	let b9 =45                                        'Display - (45) MINUS
	w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
	endif                                
	w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
	                                          
	bintoascii w10,b8,b7,b6,b5,b4 
	if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
	if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
	return                       
;--------------------------------------------------
tempOut:
	Readtemp12 outtemp,w10                                 'read in result from ds18b20 and convert to 0.06 RES                                        
	let b9 =160                                       'Display space (32)
	if w10 > 64655 then                                'info     - 55 degrees          = 64656
	let b9 =45                                        'Display - (45) MINUS
	w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
	endif                                
	w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
	                                          
	bintoascii w10,b8,b7,b6,b5,b4 
	if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
	if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
	return
;---------------------------------------------------
keys:
	readadc key,b11
	if b11=0 then return:endif
	if b11=113 then goto job1
	if b11=69  then goto job2
	if b11=28  then goto job3
	if b11=46 then goto job4
	return
;---------------------------------------------------
ClearLcd:
	serout c.0,baud,(254,line1,"                    ")
	serout c.0,baud,(254,line2,"                    ")
	serout c.0,baud,(254,line3,"                    ")
	serout c.0,baud,(254,line4,"                    ")
	return

;****************************************************
So why has one check 'subroutine' got no return whereas the other does? This will eventually result in a stack error unless the right combination of stuff happens every time - w10 being lower than w12 - and that can only happen so many times.
Code:
check:				'record MIN & MAX temps in memory.

	i2cslave MEM,i2cfast,i2cword 
	
	readi2c mintemp,(w12)
	if w10<w12 then goto lowtemp
 
check2:
	readi2c maxtemp,(w12)
	if w10>w12 then gosub hightemp
	return

lowtemp:
	writei2c mintemp,(w10)
	goto check2
	return

hightemp:
	writei2c maxtemp,(w10)
	return
This is all I can find right now, but I'll keep looking for flaws in your code.

Beware that the EEPROM will be prewritten with 255 in every location when it is new.
 

mrburnette

Senior Member
@nick12ab:
So why has one check 'subroutine' got no return whereas the other does? This will eventually result in a stack error unless the right combination of stuff happens every time - w10 being lower than w12 - and that can only happen so many times.
Actually, only "check:" is the subroutine. "check2:" is simply a label; therefore the single "return" is appropriate. I usually find that using PE's "blocks" commands helps with such identification. But, it is just the nature of BASIC and I've seen PhD's writing the same way when in a hurry and no one is looking over their shoulders. (Yep... I've done it a time or two myself... I'll have some marinara with my spaghetti code...)

- Ray

CodeBlocks.JPG
 

cactusface

Senior Member
Hi All,
This code is really getting my goat!! It seems to work but not quite in the way I expect it too... The problem seems to be when I store w10 into the extarnal EEprom or read it back or perhaps converting it for display on the serial LCD!! (in Job1)

Here's my latest version, HELP!! Can you see anything wrong?

Any hints are ideas welcome.
Regards
Mel.

Code:
; *******************************
;    Filename: 	ShieldDataLogger
;    Date: 		06/07/2012	
;    File Version: v2.00 	
;    Written by: 	MS	
;    Function:	Greenhouse Data logger	
;    Last Revision:
;    Target PICAXE:My20M2Shield	
; ******************************* 

#picaxe 20m2

symbol intemp = b.0
symbol outtemp = b.1
symbol key= b.2
symbol light = b.3
;symbol humid = b.4

symbol All_clear=%00000000
symbol line1=128	      'Set up LCD line codes
symbol line2=192		'Start location for each line
symbol line3=148
symbol line4=212
symbol RTC=%11010000	'DS1307 Address
symbol MEM=%10100000	'EEprom Address
symbol MEM2=$8001		'2nd EEprom Address
symbol mintemp=MEM
symbol maxtemp=mintemp+2
symbol sun=b0
symbol baud=T2400		'Serial baud rate baud,N,8,1


pause 300			'Give system time to power up and stabilize?

serout c.0,baud,(255,1)	'switch backlight on
pause 200

Main:
gosub keys
gosub gettime
gosub convert
serout c.0,baud,(254,line1,b12,b13,"/",b14,b15,"/20",b16,b17," ",b10,b11,":",b8,b9,":",b19,b20," ")'display current date & time

gosub tempIn
gosub checkmin
gosub tempIn
gosub checkmax

serout c.0,baud, (254,line2,"Inside Temp:",b9,b7,b6,".",b5,b4,"c")'display local temp.
gosub tempOut
serout c.0,baud, (254,line3,"Outside Temp:",b9,b7,b6,".",b5,b4,"c")'display remote temp.
readadc light,sun 
serout c.0,baud,(254,line4,"light value = ", #sun,"   ")
goto main

;JOBS

job1:
gosub clearlcd
serout c.0,baud,(254,line1,253,2)
i2cslave mem,i2cfast,i2cword	
readi2c mintemp,(w10)
gosub checkpoint
serout c.0,baud(254,line3," Temp",b8,b7,b6,".",b5,b4,"c")        																																																												
i2cread maxtemp,(w10)
gosub checkpoint
serout c.0,baud,(254,line4,"   Max Temp",b8,b7,b6,".",b5,b4,"c")
wait 3
return

job2:
gosub clearlcd
serout c.0,baud,(254,line1,253,3)
wait 2
return

job3:
gosub clearlcd
serout c.0,baud,(254,line1,253,4)
wait 2
return



job4:
gosub clearlcd
serout c.0,baud,(254,line1,253,5)
wait 2
return
;**************************************
;SubRounites

checkmin:				'record MIN & MAX temps in memory.

i2cslave MEM,i2cfast,i2cword	
readi2c mintemp,(w12)
if w11<w12 then 			'Check is w11 less then w12 in mem  
writei2c mintemp,(w11)
endif
return
 
checkmax:
i2cslave MEM,i2cfast,i2cword 
readi2c maxtemp,(w12)
if w11>w12 then 			'Check is w11 more then w12 in mem
writei2c maxtemp,(w11)
endif
return
;--------------------------------------------
gettime:

i2cslave RTC,i2cslow,i2cbyte	'set up i2c DS1307 RTC
readi2c 0,(b0,b1,b2,b3,b4,b5,b6,b7)	'read Time and Date
return

convert:
bcdtoascii b0,b19,b20		'Secs Convert to ASCII
bcdtoascii b1,b8,b9		'Mins 
bcdtoascii b2,b10,b11		'Hours
bcdtoascii b3,b21,b22         'DayOfWeek
bcdtoascii b4,b12,b13		'Date
bcdtoascii b5,b14,b15		'Month
bcdtoascii b6,b16,b17		'Year
return
;--------------------------------------------------

tempIn:
Readtemp12 intemp,w10                               'read in result from ds18b20 and convert to 0.06 RES                                      
w11=w10
let b9 =160                                       'Display space (32)
if w10 > 64655 then                                'info     - 55 degrees          = 64656
let b9 =45                                        'Display - (45) MINUS
w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
endif                                
w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
                                          
bintoascii w10,b8,b7,b6,b5,b4 
if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
return                       
;--------------------------------------------------
tempOut:
Readtemp12 outtemp,w10                                 'read in result from ds18b20 and convert to 0.06 RES                                        
let b9 =160                                       'Display space (32)
if w10 > 64655 then                                'info     - 55 degrees          = 64656
let b9 =45                                        'Display - (45) MINUS
w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
endif                                
w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
                                          
bintoascii w10,b8,b7,b6,b5,b4 
if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
return
;---------------------------------------------------
keys:
readadc key,b11
if b11=0 then return:endif
if b11=113 then goto job1
if b11=69  then goto job2
if b11=28  then goto job3
if b11=46 then goto job4
return
;---------------------------------------------------
ClearLcd:
serout c.0,baud,(254,line1,"                    ")
serout c.0,baud,(254,line2,"                    ")
serout c.0,baud,(254,line3,"                    ")
serout c.0,baud,(254,line4,"                    ")
return
;----------------------------------------------------
checkpoint:                                      
let b9 =160                                       'Display space (32)
if w10 > 64655 then                                'info     - 55 degrees          = 64656
let b9 =45                                        'Display - (45) MINUS
w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
endif                                
w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
                                          
bintoascii w10,b8,b7,b6,b5,b4 
if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
return   
;****************************************************
 

cactusface

Senior Member
Hi All,
This code is really getting my goat!! It seems to work but not quite in the way I expect it too... The problem seems to be when I store w10 into the extarnal EEprom or read it back or perhaps converting it for display on the serial LCD!! (in Job1)

Here's my latest version, HELP!! Can you see anything wrong?

Any hints or ideas welcome.

Regards
Mel.

Code:
; *******************************
;    Filename: 	ShieldDataLogger
;    Date: 		06/07/2012	
;    File Version: v2.00 	
;    Written by: 	MS	
;    Function:	Greenhouse Data logger	
;    Last Revision:
;    Target PICAXE:My20M2Shield	
; ******************************* 

#picaxe 20m2

symbol intemp = b.0
symbol outtemp = b.1
symbol key= b.2
symbol light = b.3
;symbol humid = b.4

symbol All_clear=%00000000
symbol line1=128	      'Set up LCD line codes
symbol line2=192		'Start location for each line
symbol line3=148
symbol line4=212
symbol RTC=%11010000	'DS1307 Address
symbol MEM=%10100000	'EEprom Address
symbol MEM2=$8001		'2nd EEprom Address
symbol mintemp=MEM
symbol maxtemp=mintemp+2
symbol sun=b0
symbol baud=T2400		'Serial baud rate baud,N,8,1


pause 300			'Give system time to power up and stabilize?

serout c.0,baud,(255,1)	'switch backlight on
pause 200

Main:
gosub keys
gosub gettime
gosub convert
serout c.0,baud,(254,line1,b12,b13,"/",b14,b15,"/20",b16,b17," ",b10,b11,":",b8,b9,":",b19,b20," ")'display current date & time

gosub tempIn
gosub checkmin
gosub tempIn
gosub checkmax

serout c.0,baud, (254,line2,"Inside Temp:",b9,b7,b6,".",b5,b4,"c")'display local temp.
gosub tempOut
serout c.0,baud, (254,line3,"Outside Temp:",b9,b7,b6,".",b5,b4,"c")'display remote temp.
readadc light,sun 
serout c.0,baud,(254,line4,"light value = ", #sun,"   ")
goto main

;JOBS

job1:
gosub clearlcd
serout c.0,baud,(254,line1,253,2)
i2cslave mem,i2cfast,i2cword	
readi2c mintemp,(w10)
gosub checkpoint
serout c.0,baud(254,line3," Temp",b8,b7,b6,".",b5,b4,"c")        																																																												
i2cread maxtemp,(w10)
gosub checkpoint
serout c.0,baud,(254,line4,"   Max Temp",b8,b7,b6,".",b5,b4,"c")
wait 3
return

job2:
gosub clearlcd
serout c.0,baud,(254,line1,253,3)
wait 2
return

job3:
gosub clearlcd
serout c.0,baud,(254,line1,253,4)
wait 2
return



job4:
gosub clearlcd
serout c.0,baud,(254,line1,253,5)
wait 2
return
;**************************************
;SubRounites

checkmin:				'record MIN & MAX temps in memory.

i2cslave MEM,i2cfast,i2cword	
readi2c mintemp,(w12)
if w11<w12 then 			'Check is w11 less then w12 in mem  
writei2c mintemp,(w11)
endif
return
 
checkmax:
i2cslave MEM,i2cfast,i2cword 
readi2c maxtemp,(w12)
if w11>w12 then 			'Check is w11 more then w12 in mem
writei2c maxtemp,(w11)
endif
return
;--------------------------------------------
gettime:

i2cslave RTC,i2cslow,i2cbyte	'set up i2c DS1307 RTC
readi2c 0,(b0,b1,b2,b3,b4,b5,b6,b7)	'read Time and Date
return

convert:
bcdtoascii b0,b19,b20		'Secs Convert to ASCII
bcdtoascii b1,b8,b9		'Mins 
bcdtoascii b2,b10,b11		'Hours
bcdtoascii b3,b21,b22         'DayOfWeek
bcdtoascii b4,b12,b13		'Date
bcdtoascii b5,b14,b15		'Month
bcdtoascii b6,b16,b17		'Year
return
;--------------------------------------------------

tempIn:
Readtemp12 intemp,w10                               'read in result from ds18b20 and convert to 0.06 RES                                      
w11=w10
let b9 =160                                       'Display space (32)
if w10 > 64655 then                                'info     - 55 degrees          = 64656
let b9 =45                                        'Display - (45) MINUS
w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
endif                                
w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
                                          
bintoascii w10,b8,b7,b6,b5,b4 
if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
return                       
;--------------------------------------------------
tempOut:
Readtemp12 outtemp,w10                                 'read in result from ds18b20 and convert to 0.06 RES                                        
let b9 =160                                       'Display space (32)
if w10 > 64655 then                                'info     - 55 degrees          = 64656
let b9 =45                                        'Display - (45) MINUS
w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
endif                                
w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
                                          
bintoascii w10,b8,b7,b6,b5,b4 
if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
return
;---------------------------------------------------
keys:
readadc key,b11
if b11=0 then return:endif
if b11=113 then goto job1
if b11=69  then goto job2
if b11=28  then goto job3
if b11=46 then goto job4
return
;---------------------------------------------------
ClearLcd:
serout c.0,baud,(254,line1,"                    ")
serout c.0,baud,(254,line2,"                    ")
serout c.0,baud,(254,line3,"                    ")
serout c.0,baud,(254,line4,"                    ")
return
;----------------------------------------------------
checkpoint:                                      
let b9 =160                                       'Display space (32)
if w10 > 64655 then                                'info     - 55 degrees          = 64656
let b9 =45                                        'Display - (45) MINUS
w10 = - w10                                         'info   if - ie w1=1000   display   - 10.00 C
endif                                
w10 = w10 * 50 / 8                                  'info      + ie w1=8500   display     85.00 C
                                          
bintoascii w10,b8,b7,b6,b5,b4 
if b8 = "0" then : b8 = " "  :endif                       ' zero blanking b8
if b8 =  " "  and  b7 =  "0"  then : b7 = " "  :endif     ' zero blanking b7
return   
;****************************************************
 

hippy

Technical Support
Staff member
Here's my latest version, HELP!! Can you see anything wrong?
writei2c mintemp,(w11)

You can only read and write byte values, so a word has to be stored as its component bytes. My preference would be something like ...

Symbol mintempvalue = w11 ' b23:b22
Symbol mintempvalue.lsb = b22
Symbol mintempvalue.msb = b23

writei2c mintemp,( mintemvalue.msb, mintempvalue.lsb )
 

cactusface

Senior Member
Hi Hippy,
I know someone would come up with the answer!! Yes it makes sense you can only read/write in BYTES, perhaps I got mislead by writei2c mem, (b1,b2,b3, etc). What really suprises me is that neither the syntax checker nor compiler farted at me, and shouted NO you can't do that! and went ahead and downloaded the program, so I thought I was on the right track? Think I see a way of getting around it now just remember b23,b22 = W11 and b25,b24=W12 and test b23 against the msb byte of the W? I use to read from EEprom.

It's been a long day, so I'm not going to try and work it out tonight, but I will get back to you.
Thanks again
Regards
Mel.
 

hippy

Technical Support
Staff member
What really suprises me is that neither the syntax checker nor compiler farted at me, and shouted NO you can't do that!
What you have is entirely valid code, it simply doesn't do what you were hoping it to, so the compiler can't really help you out there :)

If it output word variables as two bytes when a word variable was used it would cause similar difficulties if someone wanted to output byte values (0-255) held in a word variable, and you'd never have any idea how many bytes were output just by looking at this code ...

writei2c mem, ( timeCount, adcValue, temp )

It could be anywhere between 3 and 6 bytes depending on how each variable was defined. And what about ...

writei2c mem, ( bit0 )

Send as a byte, send as a word, or not allow it ?
 

westaust55

Moderator
The data width when sending/receiving data vai the i2c bus is always 8 bits - 1 byte.
This is not just a PICAXE reuqirement but is part of the orginal i2c bus Specification.
See section 7 of the Philips/NXP specification (http://www.classic.nxp.com/acrobat_download2/literature/9398/39340011.pdf):
Every byte put on the SDA line must be 8-bits long. The number of bytes that can be transmitted per transfer is unrestricted. Each byte has to be followed by an acknowledge bit.
 

cactusface

Senior Member
Hi,
Thanks for your help, especially Hippy, yes I see your point, and as you say it just did'ent work the way I was thinking, but I will now use some thng along the lines you suggested :

You can only read and write byte values, so a word has to be stored as its component bytes. My preference would be something like ...

Symbol mintempvalue = w11 ' b23:b22
Symbol mintempvalue.lsb = b22
Symbol mintempvalue.msb = b23

writei2c mintemp,( mintemvalue.msb, mintempvalue.lsb )
For testing the min and max temp should this work?

readi2c,mintemp,(mintempvaluemsb)
if resultvalmsb<mintempvalue) then writei2c mintemp,(resultvalmsb,resultvallsb) Resultval being the value read by readtemp12,w10

Westy! Way back in my Z80 days? I remember when Philips came up with the i2c idea and produced some code to get it going, but I can't remember what for, but it must have been to use a Phillips chip I bet. In the days when you could get a free sample??

Regards
Mel.
 
Last edited:
Top