decimal to bcd

craig008

New Member
I have noticed that the RTC reguires a convertion from BCD to decimal. is it possible to go the other way to allow the picaxe to programme the RTC from user input to directly to the chip?

any help would be cool, this driving my nuts trying to find the way to do it. thanks in advance.
________
Magic flight launch box
 
Last edited:

eclectic

Moderator
Last edited:

craig008

New Member
the data logger is where i found data logger thing for bcd to decimal to allow the 28x1 to read from the clock. i will look deaper into the second one, bcdtoascii comand. This is a new comand to me and i wasnt aware that it exsited.

thanks for those links.
________
Website design
 
Last edited:

craig008

New Member
OK just been looking into bcd to ascii, this doesnt do what i need it to. i need to go the the other way, i.e. send $?? to the clock (when the ?? is to be the variable that is changed by user input to the picaxe).

it may be me making this more complex than it need to be, do i need the $ before the value?? or does the clock not care??
________
Ford Vedette Picture
 
Last edited:

BCJKiwi

Senior Member
Have a routine to set a DS1307 RTC from an IR Remote. This is just a subset of the full configuration routine in this project.
The key to the answer to your question is in the RTC_IR subroutine.

Code:
cfg_loop:
M_Clock:
'sec (& oscillator enable), Min, Hr, DoW, Day, Mo, Yr, Control register
'Year
YearRep:
'sertxd ("set clock YEAR Please Enter 00-99",cr,lf)
GoSub RTC_IR
b4 = b0
'Month
MonthRep:
'sertxd ("set clock MONTH Please Enter 01-12",cr,lf)
GoSub RTC_IR
If b0 < 1 OR b0 >18 then
gosub M_Error
goto MonthRep
Endif
b5 = b0
'Day
DayRep:
'sertxd ("set clock DAY Please Enter 01-29/30/31",cr,lf)
GoSub RTC_IR
If b0 < 1 OR b0 >49 then
gosub M_Error
goto DayRep
Endif
b6 = b0
'DoW # 1 - 7 sets first day of week - we don't care as we don't use this - just set to 1
'
'Hour
HourRep:
'sertxd ("set clock HOUR Please Enter 00-23",cr,lf)
GoSub RTC_IR
If b0 >35 then
gosub M_Error
Goto HourRep
Endif
b7 = b0
'Minute
MinRep:
'sertxd ("set clock MINUTE Please Enter 00-59",cr,lf)
GoSub RTC_IR
If b0 >89 then
gosub M_Error
goto MinRep
Endif
b8 = b0
'Second - highest bit must be 0 so oscillator is enabled
SecRep:
'sertxd ("set clock SECOND Please Enter 00-59",cr,lf)
GoSub RTC_IR
If b0 >89 then
gosub M_Error
goto SecRep
Endif
b9 = b0
'Control register
'%00010000 'bit 4 = 1 is square wave out at 1Hz
'
hi2csetup i2cmaster,RTC_0,i2cSlow_16,i2cbyte 'hi2c setup line only required once per POR
' S, M, H, Dow,D, M, Yr,Control 
hi2cout 0, (b9,b8,b7,$01,b6,b5,b4,%00010000)
'Configure clock control register and set time/date - only required once per power up of Clock
'Ensure DOW matches Date
'$xx is the number you want for the date/time
' e.g. $07 (or $7) is the year 07, $10 is 10 for October
'Highest bit of secs must be 0 to enable oscillator - simplest to set seconds at $00
'If the set hour is from 1 to 23 then the hours will be in 24Hr mode
' as bit6 needs to be set to 1 to enable 12 hr mode ($4C or %01001100 for 12 hr/12 o'clock)
 
RTC_IR:
GoSub GetIR
b0 = b1 +"0"
GoSub GetIR
b1 = b1 +"0"
b0 = b0-$30*16+b1-$30
Return
 
GetIR:
IRIN [10000,cfg_loop],cfg_in, w1 'wait 2.5 secs for input
pause 1000
b1 =w1-11263 ' using modern remote which returns Sony remote number + 11263 
if b1 =10 then let b1=0 :EndIf
Return
 

westaust55

Moderator
Yes.

Note the -$30 part is required to convert an ASCII value [zero (0) = $30]
when you have previously received/converted the tens and units digits to ASCII, such as with the command b0 = b1 +"0" in BCJKiwi's example.
 

craig008

New Member
OK i have been a it snowed under at work for a bit but anyway this is what i have

b6 = mins / 10 * 16
b6 = mins // 10 OR b6
let mins = b6
let b6 = 0

i have tryed changing the OR in the code for ? as per hippys' post in the above link, only to find the editor will not except it and using the or comand reurns an incorect value. i will five the nible version a go and see what i can make of that
________
PENNY STOCKS TO BUY
 
Last edited:

westaust55

Moderator
The code is correct for decomal to BCD conversion.

What if anything is wrong.
For exmple with starting mins = 49
The output mins = 73

More explanation of what you think is wrong and your code may help
 

hippy

Technical Support
Staff member
i have tryed changing the OR in the code for ¦ as per hippys' post in the above link, only to find the editor will not except it
There are actually two possible vertical bars ... for a British keyboard, shift bottom left above the backslash, and Alt-Gr top left with back tick / logical not. If you're getting "illegal character 0xFFFFFFA6" or similar your system is probably set for the wrong keyboard mapping or code page or something.

| ¦ | ¦ | ¦
 

craig008

New Member
now this would explain alot, for some reason i have a US keyboard which does not have that symbol, found an old UK one kicking around and all works great now, many thanks for that.
________
Teen videos
 
Last edited:

hippy

Technical Support
Staff member
I've got my UK keyboard setup okay for Win 98 use ( bar above backslash where I'd expect it ) but under Win XP that gets swapped with the other, but only at the MS-DOS prompt. Very annoying when editing in MS-DOS then loading or cutting and pasting in Windows.

For Win 98 I had to delete the two lines Windows adds to config.sys and autoexec.bat respectively -

Code:
Country=044,850,C:\WINDOWS\COMMAND\country.sys
keyb uk,,C:\WINDOWS\COMMAND\keyboard.sys
But as Win XP doesn't use MS-DOS as its base I'm not sure what I'm meant to alter there.

As it's getting more and more annoying I'll investigate further and if I do find a fix I'll let you know because it's probably the same type of problem you're having.
 

Technical

Technical Support
Staff member
Start>Programs>Accessories>System Tools>Character Map

is a useful Windows tool to find a character if it is not on your keyboard.
 

craig008

New Member
thanks technical, i will use that in future, but at the mo i am using the old UK keybaord. my programme is prgressing quite nicely now, but i think i may be getting some sort of clash somewhere which have gotta find.

hey hippy sorry to hear about you problems with MS-DOS, i have never used it but i am sure that the people at the link below will be happy to help

http://forums.extremeoverclocking.com/
________
VOLCANO VAPORIZER
 
Last edited:

hippy

Technical Support
Staff member
It's MS-DOS and Windows 95/98 which are fine, XP which is 'broken' :)

Thanks for the link anyway.
 
Top