Bcd Fomat Help


Results 1 to 17 of 17

Thread: Bcd Fomat Help

Threaded View

  1. #8


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    Convert BCD to decimal... assume variable RTCSeconds holds the seconds in BCD format...

    First let's deal with the TENS value (Bits 4,5 and 6)...

    DecimalSeconds=RTCSeconds & $70
    DecimalSeconds=DecimalSeconds>>4
    DecimalSeconds=DecimalSeconds*10

    And finally add-in the UNITS value...

    DecimalSeconds=DecimalSeconds+(RTCSeconds & $0F)

    ----

    To convert Decimal back to BCD, reverse the Process...

    RTCSeconds=DecimalSeconds DIG 1
    RTCSeconds=RTCSeconds<<4
    RTCSeconds=RTCSeconds+(DecimalSeconds DIG 0)

    ----


    Incorporate the above into a General Purpose Subroutine and use the same single routine to convert Seconds, Minutes, Hours etc etc.


    Melanie
    Thanks a lot. I was breaking my head from last few days to learn this. You have really explained it very nicely.

    BUT

    I am facing slight problem in my simulation (I am using proteus).
    My code looks like this when program starts for the first time:
    Code:
    Rtcget		var byte[8]
    Rtcsec		var Rtcget[0]
    Rtcmin		var Rtcget[1]
    Rtchr		var Rtcget[2]
    Rtcday		var Rtcget[3]
    
    read 30,check
    if check=0 then
    	pause 50
    	I2CWRITE SDA,SCL,$D0,$00,[$00,$00,$12,$01,$00,$00,$00,$90]
    	pause 50
    	write 30,1
    endif
    
    	I2CREAD SDA,SCL,$D1,$00,[STR Rtcget\8]
    		pause 50
    		sec=Rtcsec & $70
    		sec = sec>>4
    		sec=sec*10
    		sec=sec +(Rtcsec & $0F)
    
    		minu=Rtcmin & $70
    		minu = minu>>4
    		minu=minu*10
    		minu=minu +(Rtcmin & $0F)
    
    		hrs=Rtchr & $30
    		hrs=hrs>>4
    		hrs=hrs*10
    		hrs=hrs+(Rtchr & $0F)
    
    		if Rtcday=$01 then days=1
    		if Rtcday=$02 then days=2
    		if Rtcday=$03 then days=3
    		if Rtcday=$04 then days=4
    		if Rtcday=$05 then days=5
    		if Rtcday=$06 then days=6
    		if Rtcday=$07 then days=7
    & when user changes the time it looks like this
    Code:
    Rtcmin=minu DIG 1
    					Rtcmin=Rtcmin<<4
    					Rtcmin=Rtcmin+(minu DIG 0)
    
    					Rtchr=hrs DIG 1
    					Rtchr=Rtchr<<4
    					Rtchr=Rtchr+(hrs DIG 0)
    
    					if days=1 then Rtcday=$01
    					if days=2 then Rtcday=$02
    					if days=3 then Rtcday=$03
    					if days=4 then Rtcday=$04
    					if days=5 then Rtcday=$05
    					if days=6 then Rtcday=$06
    					if days=7 then Rtcday=$07
    				I2CWRITE SDA,SCL,$D0,$00,[$00,Rtcmin,Rtchr,Rtcday,$00,$00,$00,$90]
    				PAUSE 20
    The problem is that during simulation, the frequency of the pulse changes once I set the time (coming from DS1307 - I want 1Hz)
    Please point out the problem in my code if any, or is it the simulation software which is not correct (Proteus 6.9)
    Last edited by financecatalyst; - 3rd January 2011 at 17:04. Reason: missing info
    ___________________
    WHY things get boring when they work just fine?

Similar Threads

  1. DS1302 16F628 Woes
    By idtat in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th January 2009, 14:15
  2. BCD problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th September 2008, 16:36
  3. Rotary BCD
    By Tobias in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2007, 03:04
  4. Real time clock... what a headache!
    By Eng4444 in forum mel PIC BASIC
    Replies: 2
    Last Post: - 8th June 2006, 21:56
  5. Leading 0's or BCD
    By RYTECH in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th December 2005, 01:06

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts