RTC to OLED code issue

marzan

Senior Member
Hi all. I am trying to get time from an RTC displayed on an oled using an axe133. The numbers jump from 9 to 16, so i guess its something to do with displaying hex. I am running this on a 28X2.

Code:
symbol slvAddrWR = $A0  ' I2C write address

MAIN:

	PAUSE 1000

  	i2cslave slvAddrWR, i2cslow, i2cbyte		'Initialize I2C-7SEG
  	
  	writei2c 0,(%00000100)					;timer function to 99 seconds
									;to enable %xx0xx1xx
  	writei2c 8,(%00000010)					; alarm control registers and clock mode
									;bit7 	enable alarm interrupt
									;bit6		timer alarm
									;bit5/4	clock alarm 00= no clock alarm
									;bit3		timer interrupt enable
									;bit2/1/0  	timer function  001= hundredths of a second
						
	serout b.7,n2400,(254,1)				;clear screen
	
	pause 30
	
	serout b.7,n2400,(254,148)				;move to line 3
	
	serout b.7,n2400,("TIME:   ")	
					
	writei2c 2,(%00000000)					;reset minutes
	
	writei2c 1,(%00000000)					;reset milliseconds
	
	writei2c 3,(%00000000)					;reset milliseconds												
			
	DO
		
  	readi2c 0,(b0,b1,b2,b3)
  	
	serout b.7,n2400,(254,16)				;cursor left
								
	;debug
	
	serout b.7,n2400,(254,153)
	
	serout b.7,n2400,(#b3,":",#b2,":",#b1)
	
	LOOP
Thanks for looking :)

Marz
 

srnet

Senior Member
Which RTC are you using, I dont see it mentioned in the code ?

What does the data sheet for the RTC say about the format for the mins\secs etc, are they in decimal\hex or BCD format ?
 

marzan

Senior Member
Which RTC are you using, I dont see it mentioned in the code ?

What does the data sheet for the RTC say about the format for the mins\secs etc, are they in decimal\hex or BCD format ?
I am using a PCF8583 - http://www.wvshare.com/datasheet_html/PCF8583-PDF.html.

The RTC does seem to be working. when I use the debugging screen the variables are there and do change and reset.The extreme left hand colum on the debug screen seems to show the same as the OLED, whereas its the next column that shows the decimal ( $xx )
 

marzan

Senior Member
Use the bcdtoascii command or bcdtobin operand on time data received before displaying it.
i tried this, but it dosen`t work.
Code:
symbol slvAddrWR = $A0  ' I2C write address

MAIN:

	PAUSE 1000

  	i2cslave slvAddrWR, i2cslow, i2cbyte		'Initialize I2C-7SEG
  	
  	writei2c 0,(%00000100)					;timer function to 99 seconds
									;to enable %xx0xx1xx
  	writei2c 8,(%00000010)					; alarm control registers and clock mode
									;bit7 	enable alarm interrupt
									;bit6		timer alarm
									;bit5/4	clock alarm 00= no clock alarm
									;bit3		timer interrupt enable
									;bit2/1/0  	timer function  001= hundredths of a second
						
	serout b.7,n2400,(254,1)				;clear screen
	
	pause 30
	
	serout b.7,n2400,(254,148)				;move to line 3
	
	serout b.7,n2400,("TIME:   ")	
					
	writei2c 2,(%00000000)					;reset minutes
	
	writei2c 1,(%00000000)					;reset milliseconds
	
	writei2c 3,(%00000000)					;reset milliseconds												
			
	DO
		
  	readi2c 0,(b1,b2,b3,b4)
  	
  	BCDTOASCII b1,b10,b11


  	
	serout b.7,n2400,(254,16)				;cursor left
								
	debug
	
	serout b.7,n2400,(254,153)
	
	serout b.7,n2400,(#b2,":",#b11,#b10)
	
	;serout b.7,n2400,(#b3,":",#b2,":",#b1)
	
	LOOP
does anyone know where ther is some working code for me to look at to see what I am doing wrong?

Thanks.
Marz.
 

raits999

Member
Maybe this can help

Code:
#terminal off
#no_data
#terminal 9600
#no_table

SYMBOL Sunday = $01
SYMBOL Monday = $02
SYMBOL Tuesday = $03
SYMBOL Wednesday = $04
SYMBOL Thursday = $05
SYMBOL Friday = $06
SYMBOL Saturday = $07


SYMBOL January = $01
SYMBOL February = $02
SYMBOL March = $03
SYMBOL April = $04
SYMBOL May = $05
SYMBOL June = $06
SYMBOL July = $07
SYMBOL August = $08
SYMBOL September = $09
SYMBOL October = $10
SYMBOL November = $11
SYMBOL December = $12

SYMBOL sec = b0
SYMBOL minute = b1
SYMBOL hour = b2
SYMBOL day = b3
SYMBOL month = b4
SYMBOL year = b5

SYMBOL PCF8583 = %10100000
i2cslave PCF8583, i2cfast_8, i2cbyte

'*********CLOCK********

hour=$12			'hours
minute=$54			'minutes
sec=$00			'seconds
day=$04
month=april
year=$12

writei2c $00, (%00000000)     	'control register
writei2c $02, (sec,minute,hour) 	'sec, minute, hour
'writei2c $05, (year,month,day) 	'year,month,day

'*********ALARM**********

hour=$11			'hours
minute=$39			'minutes
sec=$00			'seconds
day=$04
month=april

'writei2c $08, (%00000000)		'alarm register
'writei2c $0a, (sec,minute,hour)	'alarm time (sec,minute,hour)
'writei2c $0d, (month,day)


main:
	if pinc.2=1 then main
	readi2c $02, (b14, b15, b16)
	bcdtoascii b14,b12,b13
	bcdtoascii b15,b10,b11
	bcdtoascii b16,b8,b9
	sertxd(b8,b9,":",b10,b11,":",b12,b13,13,10)
	pause 500
	goto main
 

Bill.b

Senior Member
Hi

Here is a clock program using the serial 20x4 OLED display (AXE 134Y) and a DS1307 RTC.

The code for the RTC is similar but the data is in a different order.
refer to the datasheets for both to compare the format. also the I2C address may be different.

this code also uses an IR remote for time and alarm settings.

View attachment IRSerialCLOCKamalma3.pdf

Bill
 

marzan

Senior Member
Found the problem !! It was this line:
Code:
 readi2c 0,(b1,b2,b3,b4,b5)
it should have been this:

Code:
 readi2c $0,(b1,b2,b3,b4,b5)
I gather the $ sign means the value is in binary?


So, this code sends i2c RTC data (from a PCF8583) to 3rd line of a 20 X 4 OLED controlled by an axe133.

Code:
symbol slvAddrWR = $A0  ' I2C write address

MAIN:

	PAUSE 1000

  	i2cslave slvAddrWR, i2cslow, i2cbyte		'Initialize I2C-7SEG
  	
  	writei2c 0,(%00000100)					;timer function to 99 seconds
									;to enable %xx0xx1xx
  	writei2c 8,(%00000010)					; alarm control registers and clock mode
									;bit7 	enable alarm interrupt
									;bit6		timer alarm
									;bit5/4	clock alarm 00= no clock alarm
									;bit3		timer interrupt enable
									;bit2/1/0  	timer function  001= hundredths of a second
						
	serout b.7,n2400,(254,1)				;clear screen
	
	pause 30
	
	serout b.7,n2400,(254,148)				;move to line 3
	
	serout b.7,n2400,("TIME:   ")	
					
	writei2c 2,(%00000000)					;reset minutes
	
	writei2c 1,(%00000000)					;reset milliseconds
	
	writei2c 3,(%00000000)					;reset milliseconds												
			
	DO
		
  	readi2c $0,(b1,b2,b3,b4,b5)
  	
  	BCDTOASCII b2,b10,b11
	BCDTOASCII b3,b12,b13
	BCDTOASCII b4,b14,b15
  	
	serout b.7,n2400,(254,16)				;cursor left
								
	debug
	
	serout b.7,n2400,(254,153)
	
	serout b.7,n2400,(b14,b15,":",b12,b13,":",b10,b11)
	
	;serout b.7,n2400,(#b3,":",#b2,":",#b1)
	
	LOOP
Hopefully this will help anyone in the future trying to do the same thing. Thanks everyone for your replies.
Marz.
 

hippy

Technical Support
Staff member
Found the problem !! It was this line:
Code:
 readi2c 0,(b1,b2,b3,b4,b5)
it should have been this:

Code:
 readi2c $0,(b1,b2,b3,b4,b5)
I gather the $ sign means the value is in binary?
Nope; the two lines of code are functionally exactly the same. It's something else in the code or environment which must be different.
 

marzan

Senior Member
Hmmmm.... well thats the entire code, so I have no clue why it would work then if it is the same.
 

srnet

Senior Member
You were first trying to print the numbers like this;

serout b.7,n2400,(#b3,":",#b2,":",#b1)

Then changed to;

serout b.7,n2400,(b14,b15,":",b12,b13,":",b10,b11)
 

marzan

Senior Member
What would be the point in the bcdtoascii commandif it didn't do the ascii part? You don't need to precede the new variables with #.
You were first trying to print the numbers like this;

serout b.7,n2400,(#b3,":",#b2,":",#b1)

Then changed to;

serout b.7,n2400,(b14,b15,":",b12,b13,":",b10,b11)

I didn`t explain the change because there were quite a few steps and hours of reading that got me to that point. I kept trying different combinations after reading up on the commands.I still have lots to lean :)
 
Top