Picaxe clock thermometer

raits999

Member
This is project that I made for my brother, it will go to his garage after he finishes casing.
It shows time, inside and outside temperature. Brain for the clock is axe200 module that controls ds1307 rtc and 3 saa1064 chips. I`m not going in details because ho is skilled enough to solder smd will figure it out.

Here is some pictures:
Picture 1 Picture 2 Picture 3 Picture 4


And code:
Code:
#picaxe 28x2
#no_data
#no_table
#terminal off

symbol clock=$70
symbol in=$74
symbol out=$76
symbol ds1307=$D0

symbol outsensor=c.6
symbol insensor=c.5
symbol hourplus=pinb.7
symbol minuteplus=pinb.6

symbol minute=b1
symbol minute2=b2
symbol hour=b3
symbol nr1=b4
symbol nr2=b5
symbol nr3=b6
symbol nr4=b7
symbol temp=w4
symbol temp2=w6

init:
i2cslave clock,i2cslow,i2cbyte
hi2cout $00,($1F)
i2cslave in,i2cslow,i2cbyte
hi2cout $00,($1F)
i2cslave out,i2cslow,i2cbyte
hi2cout $00,($1F)
wait 2
readtemp12 outsensor,temp
gosub tempconvert
i2cslave out,i2cslow,i2cbyte
hi2cout $00,($17,nr1,nr2,nr3,$80)
readtemp12 insensor,temp
gosub tempconvert
i2cslave in,i2cslow,i2cbyte
hi2cout $00,($17,nr1,nr2,nr3,$80)
i2cslave ds1307,i2cfast, i2cbyte
hi2cout $07, (%00010000)
hi2cin $01,(minute,hour)
nr1=hour/16:nr2=hour AND $0F
nr3=minute/16:nr4=minute AND $0F
gosub clocknr
i2cslave clock, i2cslow, i2cbyte
hi2cout $00, ($17,nr1,nr2,nr3,nr4)
	
Main:
	i2cslave ds1307,i2cfast, i2cbyte
	hi2cin $01,(minute,hour)
	nr1=hour/16:nr2=hour AND $0F
	nr3=minute/16:nr4=minute AND $0F
	if hourplus=1 then gosub hourset
	if minuteplus=1 then gosub minuteset
	pause 500
	minute=nr3*10+nr4
	if minute2=minute then main
	minute2=minute
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,nr1,nr2,nr3,nr4)
	readtemp12 outsensor,temp
	gosub tempconvert
	i2cslave out,i2cslow,i2cbyte
	hi2cout $00,($17,nr1,nr2,nr3,$80)
	readtemp12 insensor,temp
	gosub tempconvert
	i2cslave in,i2cslow,i2cbyte
	hi2cout $00,($17,nr1,nr2,nr3,$80)
	goto main
	
minuteset:
	minute=minute+1
	if minute =10 then : minute = Minute+6
	elseif minute =26 then : minute = Minute+6
	elseif minute =42 then : minute = Minute+6
	elseif minute =58 then : minute = Minute+6
	elseif minute =74 then : minute = Minute+6
	elseif minute = 90 then : minute = 0
	endif
	i2cslave ds1307,i2cfast, i2cbyte
	hi2cout $01, (minute)
	hi2cin $01,(minute,hour)
	nr1=hour/16:nr2=hour AND $0F
	nr3=minute/16:nr4=minute AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,nr1,nr2,nr3,nr4)
	pause 500
	if minuteplus=1 then minuteset
	return
	

hourset:
	hour=hour+1
	if hour=10 then : hour = hour + 6
	elseif hour=26 then : hour = hour + 6
	elseif hour=36 then : hour = 0
	endif
	i2cslave ds1307,i2cfast, i2cbyte
	hi2cout $02, (hour)
	hi2cin $01,(minute,hour)
	nr1=hour/16:nr2=hour AND $0F
	nr3=minute/16:nr4=minute AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,nr1,nr2,nr3,nr4)
	pause 500
	if hourplus=1 then hourset
	return			

tempconvert:
	temp2=temp
	if temp> 2048 then gosub negative
	if temp<=2048 then gosub positive
	return
	
positive:
	let temp2=temp2*10/16
	let nr1=temp2/ 100 		
	let nr2=temp2//100 / 10       
   	let nr3=temp2// 10
   	lookup nr1,($0,$3,$5D,$57,$33,$76,$7E,$43,$7F,$77),nr1
	lookup nr2,($6F,$3,$5D,$57,$33,$76,$7E,$43,$7F,$77),nr2
	lookup nr3,($EF,$A8,$F6,$FC,$B9,$DD,$DF,$E8,$FF,$FD),nr3
	return
	
negative:
	temp2= INV temp2 
	temp2= temp2 AND 4095 + 1 
	let temp2=temp2*10/16
	if temp2=255 then : temp2=0
	endif
	let nr1 =temp2 / 100 		
	let nr2 =temp2//100 / 10       
   	let nr3 =temp2 // 10
   	lookup nr1,($80,$83,$DD,$D7,$B3,$F6,$FE,$C3,$FF,$F7),nr1
	lookup nr2,($6F,$3,$5D,$57,$33,$76,$7E,$43,$7F,$77),nr2
	lookup nr3,($EF,$A8,$F6,$FC,$B9,$DD,$DF,$E8,$FF,$FD),nr3
	if temp2<100 then : nr1=$10
	endif	
	return
		

clocknr:
	lookup nr1,($0,$14,$6E),nr1
	lookup nr2,($77,$14,$6E,$3E,$1D,$3B,$7B,$16,$7F,$3F),nr2
	lookup nr3,($77,$41,$3B,$6B,$4D,$6E),nr3
	lookup nr4,($77,$41,$3B,$6B,$4D,$6E,$7E,$43,$7F,$6F),nr4
	return
 

PaulRB

Senior Member
Hi raits999,

I am very interested because I am also trying to use the saa1064 and I am having some problems.
I would like to know what transistors you have used, connected to the mx1 and mx2 pins?

Thanks,

Paul
 

raits999

Member
Hi raits999,

I am very interested because I am also trying to use the saa1064 and I am having some problems.
I would like to know what transistors you have used, connected to the mx1 and mx2 pins?

Thanks,

Paul
I am using ordinary npn transistor as its shown in saa1064 datasheet.
 

PaulRB

Senior Member
Thanks raits999, my displays are now working. I don't know what I was doing wrong before. I am using bc635 npn transistors, simply because they were available from a local store and had a suitable power rating.
 

westaust55

Moderator
@raits999,
One area where you can optimise a little is the temperature conversion routine.
Rather than two completely separate sections for positive and negative temperature you could try this (untested):

Code:
tempconvert:
	nr4 = 0
	temp2=temp
	IF temp > 2048 THEN
	  temp2= - temp2
	  nr4 = $80
	ENDIF	
	let temp2=temp2*10/16
	let nr1=temp2/ 100 		
	let nr2=temp2//100 / 10       
  	let nr3=temp2// 10
 	lookup nr1,($0,$3,$5D,$57,$33,$76,$7E,$43,$7F,$77),nr1
	lookup nr2,($6F,$3,$5D,$57,$33,$76,$7E,$43,$7F,$77),nr2
	lookup nr3,($EF,$A8,$F6,$FC,$B9,$DD,$DF,$E8,$FF,$FD),nr3
	nr1 = nr1 AND nr4
	return
 

raits999

Member
@raits999

The area is to show projects which may help others.

Please can you provide a schematic?

e
I don't have full schematic but I did draw basic schematic.
tt.jpg

@raits999,
One area where you can optimise a little is the temperature conversion routine.
Rather than two completely separate sections for positive and negative temperature you could try this (untested):
Thanks for suggestion but this code wouldn't work because lookup table in positive and negative number are different.
 

westaust55

Moderator
Thanks for suggestion but this code wouldn't work because lookup table in positive and negative number are different.
Are you sure? did you actually try the code?
If I am right, only the data in the first row of the three lookup commands differs by setting the msb.
note that I was using variable nr4 as a flag which overcomes the need for separate lookup tables.
 

raits999

Member
I have now updated the control board with new clock ds3231 and smaller controller 14m2, plus added daylight saving correction to program.

New code:
Code:
#picaxe 14m2
#no_data

symbol clock=$70
symbol in=$74
symbol out=$76
symbol ds3231=$D0

symbol outsensor=c.0
symbol insensor=c.1
symbol colon=b.1
symbol up=pinc.2
symbol selectt=pinc.3

symbol minute=b0
symbol hour=b1
symbol day=b2
symbol date=b3
symbol month=b4
symbol year=b5
symbol nr1=b6
symbol nr2=b7
symbol nr3=b8
symbol nr4=b9
symbol flag=b10
symbol temp=w6
symbol temp2=w7

init:
read 0,flag
i2cslave clock,i2cslow,i2cbyte
hi2cout $00,($1F)
i2cslave in,i2cslow,i2cbyte
hi2cout $00,($1F)
i2cslave out,i2cslow,i2cbyte
hi2cout $00,($1F)
wait 2
readtemp12 outsensor,temp
gosub tempconvert
i2cslave out,i2cslow,i2cbyte
hi2cout $00,($17,nr1,nr2,nr3,$80)
readtemp12 insensor,temp
gosub tempconvert
i2cslave in,i2cslow,i2cbyte
hi2cout $00,($17,nr1,nr2,nr3,$80)
i2cslave ds3231,i2cfast, i2cbyte
hi2cout $0E, (%00000000)
hi2cin $01,(minute,hour)
nr1=hour/16:nr2=hour AND $0F
nr3=minute/16:nr4=minute AND $0F
gosub clocknr
i2cslave clock, i2cslow, i2cbyte
hi2cout $00, ($17,nr1,nr2,nr3,nr4)
	
Main:
	low colon
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cin $01,(minute,hour,day,date,month,year)
	if month=$3 and date>$24 and day=$7 and hour=$2 and flag=0 then hourplus	'daylight saving set
	if month=$10 and date>$24 and day=$7 and hour=$3 and flag=1 then hourminus
	nr1=hour/16:nr2=hour AND $0F
	nr3=minute/16:nr4=minute AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,nr1,nr2,nr3,nr4)
	readtemp12 outsensor,temp
	gosub tempconvert
	i2cslave out,i2cslow,i2cbyte
	hi2cout $00,($17,nr1,nr2,nr3,$80)
	readtemp12 insensor,temp
	gosub tempconvert
	i2cslave in,i2cslow,i2cbyte
	hi2cout $00,($17,nr1,nr2,nr3,$80)
	if selectt=1 then hourset
	if up=1 then showdate
	goto main
	
showdate:
	high colon						'just for checking
	nr3=year/16:nr4=year AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,$6E,$77,nr3,nr4)
	wait 2
	nr1=month/16:nr2=month AND $0F
	nr3=date/16:nr4=date AND $0F
	gosub clocknr
	hi2cout $00, ($17,nr1,nr2,nr3,nr4)
	wait 2
	nr1=day/16:nr2=day AND $0F
	gosub clocknr
	hi2cout $00, ($17,nr1,nr2,$0,$0)
	wait 2
	goto main	
	
hourset:
	high colon
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cin $01,(minute,hour)
	nr1=hour/16:nr2=hour AND $0F
	nr3=minute/16:nr4=minute AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,nr1,nr2,$0,$0)
	pause 250
	if selectt=1 then minuteset
	if up=0 then hourset
	hour=hour+1
	if hour=10 then : hour = hour + 6
	elseif hour=26 then : hour = hour + 6
	elseif hour=36 then : hour = 0
	endif
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cout $02, (hour)
	goto hourset
	
			
minuteset:
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cin $01,(minute,hour)
	nr1=hour/16:nr2=hour AND $0F
	nr3=minute/16:nr4=minute AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,$0,$0,nr3,nr4)
	pause 250
	if selectt=1 then yearset
	if up=0 then minuteset
	minute=minute+1
	if minute =10 then : minute = Minute+6
	elseif minute =26 then : minute = Minute+6
	elseif minute =42 then : minute = Minute+6
	elseif minute =58 then : minute = Minute+6
	elseif minute =74 then : minute = Minute+6
	elseif minute = 90 then : minute = 0
	endif
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cout $01, (minute)
	goto minuteset
	
yearset:
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cin $06,(year)
	nr3=year/16:nr4=year AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,$6E,$77,nr3,nr4)
	pause 250
	if selectt=1 then monthset
	if up=0 then yearset
	year=year+1
	if year =10 then : year = year+6
	elseif year =26 then : year = year+6
	elseif year =42 then : year = year+6
	elseif year =58 then : year = year+6
	elseif year =74 then : year = year+6
	elseif year = 90 then : year = 0
	endif
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cout $06, (year)
	goto yearset
	
monthset:
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cin $05,(month)
	nr1=month/16:nr2=month AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,nr1,nr2,$0,$0)
	pause 250
	if selectt=1 then dateset
	if up=0 then monthset
	month=month+1
	if month =10 then : month = month+6
	elseif month =19 then : month = 1
	endif
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cout $05, (month)
	goto monthset
	
dateset:
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cin $04,(date)
	nr3=date/16:nr4=date AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,$0,$0,nr3,nr4)
	pause 250
	if selectt=1 then dayset
	if up=0 then dateset
	date=date+1
	if date =10 then : date = date+6
	elseif date =26 then : date = date+6
	elseif date =42 then : date = date+6
	elseif date =50 then : date = 1
	endif
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cout $04, (date)
	goto dateset
	
dayset:
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cin $03,(day)
	nr1=day/16:nr2=day AND $0F
	gosub clocknr
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,nr1,nr2,$0,$0)
	pause 250
	if selectt=1 then daylightsavingset
	if up=0 then dayset
	day=day+1
	if day =8 then : day = 1
	endif
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cout $03, (day)
	goto dayset
			
daylightsavingset:
	nr4=flag						'0=winter time
	gosub clocknr					'1=summer time
	i2cslave clock, i2cslow, i2cbyte
	hi2cout $00, ($17,$0,$0,$0,nr4)
	pause 250
	if selectt=1 then main
	if up=0 then daylightsavingset
	flag=flag+1
	if flag=>2 then : flag=0	
	endif
	write 0,flag
	goto daylightsavingset				
	
hourplus:
	flag=1
	hour=$3
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cout $02, (hour)
	write 0,flag
	goto main	
	
hourminus:
	flag=0
	hour=$2
	i2cslave ds3231,i2cfast, i2cbyte
	hi2cout $02, (hour)
	write 0,flag
	goto main
		

tempconvert:
	temp2=temp
	if temp> 2048 then gosub negative
	if temp<=2048 then gosub positive
	return
	
positive:
	let temp2=temp2*10/16
	let nr1=temp2/ 100 		
	let nr2=temp2//100 / 10       
   	let nr3=temp2// 10
   	lookup nr1,($0,$3,$5D,$57,$33,$76,$7E,$43,$7F,$77),nr1
	lookup nr2,($6F,$3,$5D,$57,$33,$76,$7E,$43,$7F,$77),nr2
	lookup nr3,($EF,$A8,$F6,$FC,$B9,$DD,$DF,$E8,$FF,$FD),nr3
	return
	
negative:
	temp2=-temp2
	let temp2=temp2*10/16
	let nr1 =temp2 / 100 		
	let nr2 =temp2//100 / 10       
   	let nr3 =temp2 // 10
   	lookup nr1,($80,$83,$DD,$D7,$B3,$F6,$FE,$C3,$FF,$F7),nr1
	lookup nr2,($6F,$3,$5D,$57,$33,$76,$7E,$43,$7F,$77),nr2
	lookup nr3,($EF,$A8,$F6,$FC,$B9,$DD,$DF,$E8,$FF,$FD),nr3
	if temp2<100 then : nr1=$10
	endif	
	return
		

clocknr:
	lookup nr1,($0,$14,$6E,$3E),nr1
	lookup nr2,($77,$14,$6E,$3E,$1D,$3B,$7B,$16,$7F,$3F),nr2
	lookup nr3,($77,$41,$3B,$6B,$4D,$6E),nr3
	lookup nr4,($77,$41,$3B,$6B,$4D,$6E,$7E,$43,$7F,$6F),nr4
	return
 
Top