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
If you are that way about intellectual property rights, why post this? If someone uses it, they are violating your rights, correct? So then why would they want to look at it?
I'm not sure what you are referring to... I'm not against anyone useing this code... it is publicly available... I hope it helps lots of people with their projects or products. I DO object to people RIPPING my site, copying the entire thing whether they need each page or not, and thereby running up my hosting bill. I also object to people not participating with feedback, improved routines, comments, questions and criticisms and the riped copies of the site do not promote the use of the forms for feedback to this sever since they are not on this server anymore. The authors of this code are shareing it with the understanding that it will be improved, commented, etc... and that the changes will be again shared. Keeping one central site with the feedback forms helps to make that happen. Finally, I REALLY object to people takeing the code without ever thanking the authors, crediting the authors, or appreciating what they have done. If you use this code, at least use the forms to say "thanks!"
|file: /Techref/microchip/math/radix/bcdrtc.htm, 3KB, , updated: 2015/10/14 15:57, local time: 2020/9/18 19:07,
|©2020 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?|
<A HREF="http://techref.massmind.org/techref/microchip/math/radix/bcdrtc.htm"> PIC Microcontoller Radix Time Math Method </A>
|Did you find what you needed?|
Welcome to massmind.org!
Welcome to techref.massmind.org!