UberNewbie can't set his clock...


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Thanks folks,

    Yes, BCD is what it is I guess. And that explains why it works to use HEX2 to send to the LCD and why DEC2 doesn't work right.

    It also explains why when manually loading the time..

    Code:
    rtcmin = $11    'Set Minutes
    ..it works to say the numbers are HEX when you're really entering DEC info. For numbers from 0 to 9 it works, AND it puts the digits in the right place for BCD.

    If I want to set the minutes to 11, it works to say "rtcmin = $11"
    But if I try to enter it as "11" with out the $..
    Code:
    rtcmin = 11    'Set Minutes
    ..when it loads into the clock as BCD, it ends up as "1A" on the display.

    I can picture what's going on (although I don't think I've put it in words well)
    but I don't know how to solve the problem...

    After I increment my variable "rtcmin" by 1, is there a way to "fool" things into thinking it's hex again? (without actually to converting hex. I want "12 = $12", not "12 = 0C")

    Am I totally lost?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Can you figure the code behind this?...

    Code:
    	BCDByte=DecimalByte DIG 1
    	BCDByte=BCDByte<<4
    	BCDByte=BCDByte+DecimalByte DIG 0
    When DecimalByte=12, then BCDByte=$12

    or put another way...

    Code:
    	BCDByte=((DecimalByte DIG 1)<<4)+DecimalByte DIG 0

  3. #3
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Ahhh, thank you Melanie!
    A first glance tells me that is exactly what I'm looking for !

    I think the Shift Left Operator (<<) may be just what I'm after!

    I got sidetracked today...
    Code:
    GOSUB DoWifeChores
     DoWifeChores:
                        finish building new kitchen cabinet
    
      RETURN
    Tomorrow morning I'll see what I can do with that left shift operator and I'll report back.
    Thanks very much!

    Steve

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Ha Ha Ha ! Sorry, but it just struck me as funny . . .
    Code:
    If DoWifeChores = 1 THEN
    goto WifeHappy
    ELSE
    IF DoWifeChores = 0 THEN
    GOTO OnMyOWN
    endif
    
    OnMyOwn:
    Cook 
    Laundry
    Sleep Cold ' In all it's many possible meanings
    Look for apartment
    
    WifeHappy:
    Wife cooks
    Does Laundry
    Keeps you warm
    Let's you stay
    You have time to PIC :D
    finish building new kitchen cabinet
    Revenge for all those New Yankee Workshop videos she had to endure
    Last edited by Archangel; - 4th January 2009 at 07:37.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Thanks to everyone that responded!

    Melanie, I still couldn't that snippet of code you supplied to work right. Using Dig 0 and Dig 1 to pick the 1's and 10's digits out of the BCD didn't give the desired results...

    What finally DID work for me was to split the minutes data apart using bitwise AND (&) like so:

    Code:
       BCDByteH = rtcmin & %11110000 'get the high nibble
       BCDByteL = rtcmin & %00001111 'get the low nibble
    That got my upper and lower 4 bits separated out OK so I can increment/decrement them with the pushbuttons.
    When I'm done I put them back together into rtcmin with bitwise OR (|)


    Code:
      rtcmin = BCDByteH | BCDByteL 
          
        gosub settime
    That seems to be working so far. More testing still to make sure...

    Anyway, thanks to all!

    (Oh, and Joe S., you MUST be a married man. You seem to know the code for it pretty well.

    Steve

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Byte_Butcher View Post
    (Oh, and Joe S., you MUST be a married man. You seem to know the code for it pretty well.

    Steve
    HE HE HE, YOU GOT IT ! I got a list of honey do's longer than a road across Texas, AND I got another list of Sonny Do's from my mother. Keeps me outta trouble.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Just for the record, the examples I posted are valid, tried and tested...

    Not knowing how you are manipulating your code and Buttons behind the scenes doesn't help... but, if your Seconds Button for example incremented the Seconds every time you pressed or held it...

    Code:
    	While SecondsButton=0
    		Seconds=Seconds+1
    		If Seconds>59 then Seconds=0
    		Pause 250
    		Wend
    That will give you a variable 'Seconds' which will contain a (Decimal) value in the range 0-59.

    Running it through either if the routines I posted previously you get...

    DecimalByte Decimal (HEX) = BCDByte Decimal (HEX)

    0-9 ($00-$09) = 0-9 ($00-$09)
    10-19 ($0A-$13) = 16-25 ($10-$19)
    20-29 ($14-$1D) = 32-41 ($20-$29)
    30-39 ($1E-$27) = 48-57 ($30-$39)
    40-49 ($28-$31) = 64-73 ($40-$49)
    50-59 ($32-$3B) = 80-89 ($50-$59)

    ...which then can be used for the Seconds Register for the timer chip.

    Now those routines are only valid for the range 0-99 giving a BCD of $00-$99, which is fine if you are setting clocks as you're only interested in 0-59 worst-case anyway.

    The way you've implimented things seems kinda hard work, if individually you are incrementing units seperately from the tens.

    Melanie, I still couldn't that snippet of code you supplied to work right. Using Dig 0 and Dig 1 to pick the 1's and 10's digits out of the BCD didn't give the desired results...
    Of course it didn't... that routine pulls the units and tens digits out a DECIMAL number to construct (encode) the BCD - not to decode the BCD... you weren't asking for that in your original post! To construct DECIMAL from BCD, you can do something simple like...
    Code:
    	DecimalByte=(BCDByte>>4)*10+(BCDByte & $0F)

  8. #8
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default little of topic but...

    Melanie and her "one line wonders" of code made me curious. In what order does PBP actually calculate and do things?
    Let's use her latest code as an example:

    Code:
    DecimalByte=(BCDByte>>4)*10+(BCDByte & $0F)
    Obviously the BCDByte is shifted right by 4 and the top 4 bits are made to 0. After the >>4 the data in BCDByte is "broken" and only the 4 low bits are valid.

    Will
    Code:
    DecimalByte=(BCDByte & $0F)+((BCDByte>>4)*10)
    give the same results?

    When does the shift command actually change the data in BCDByte?

Similar Threads

  1. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 20:36
  2. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  4. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31
  5. How to set external clock source in PBP
    By TurboLS in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 19th February 2005, 15:56

Members who have read this thread : 0

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