please dont rip this site

PIC Microcontoller Radix Time Math Method


Unpacked BCD to 16 bit binary conversion

Drew Vassallo says:
There's been some discussion about using RTCs lately. Typically, they send/receive in packed BCD. Except for the year, which is 0-99, all of the other variables are within 0-64 BCD.

After briefly searching the PICLIST archives, I couldn't really find any snippets that weren't overkill for this purpose, so I made my own. These are more specific to RTC time conversion and have reduced instruction counts over the "standard" code fragments. If you convert your hours to 12-hour format instead of the 24-hour output format of the RTC, you can use the obvious:

; BCD conversion is limited to "Hours" values less than 16
                movf    Hours, 0
                addlw   0x06
                skpdc
                addlw   -0x06
                movwf   Hours

This can also be used for month and day of the week.

For minutes, seconds, and date, you can use:

; Hex to BCD conversion - limited to 0-99 decimal (0x00-0x63 hex)
; Call with: number to be converted in W
; Returns with: converted BCD number in W
; Registers: Temp, Temp+1 used during conversion
Hex2BCD
		movwf	Temp
		clrw
		btfsc	Temp, 4
		addlw	0x16
		btfsc	Temp, 5
		addlw	0x32
		addlw	0x06
		skpdc
		addlw	-0x06
		btfsc	Temp, 6
		addlw	0x64
		addlw	0x06
		skpdc
		addlw	-0x06
		movwf	Temp+1
		movf	Temp, 0
		andlw	0x0F
		addwf	Temp+1, 0
		skpndc
		addlw	0x06
		addlw	0x06
		skpdc
		addlw	-0x06
		return

See:

Comments:

See also:


file: /Techref/microchip/math/radix/bcdrtc.htm, 3KB, , updated: 2009/5/14 14:41, local time: 2014/4/24 03:08, owner: ADV--A41,
TOP NEW HELP FIND: 
107.21.163.227:LOG IN

 ©2014 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://www.piclist.com/techref/microchip/math/radix/bcdrtc.htm"> PIC Microcontoller Radix Time Math Method </A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2014 contributors:
o List host: MIT, Site host massmind.org, Top posters @20140424 RussellMc, Josh Koffman, alan.b.pearce, IVP, Isaac Marino Bavaresco, Larry Bradley, cdb, Bob Axtell, Byron Jeff, Dwayne Reid,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
 

Welcome to www.piclist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .