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: 2015/10/14 14:57, local time: 2024/11/21 17:58, owner: ADV--A41,
TOP NEW HELP FIND: 
3.147.78.242:LOG IN

 ©2024 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://ecomorder.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 a nice message (short messages are blocked as spam) 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?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .