Matching time conditions


Closed Thread
Results 1 to 40 of 49

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest

    Default Matching time conditions

    I want to be able to set a time period using a DS1307 where a condition is matched and an action (value ) is changed. EG between time A and time B value x=25, bur between time B and time A value X =32.

    Here's the section of code I have that displays the time on the LCD
    Code:
    		'
    		'	Display Time on Line 1
    		'	----------------------
    	LCDOut $FE,$80
    	If RTCHour.6=1 then
    			' Work-Out 12 or 24 hour Display for Hours
    		CounterA=(RTCHour>>4)&$01
    		else
    		CounterA=(RTCHour>>4)&$03
    		endif
    	CounterA=CounterA*10+(RTCHour&$0F)
    	If RTCHour.6=1 then
    			' Display Hours appropriately for 12 or 24 hour Mode 
    		LCDOut #CounterA
    		else
    		LCDOut #CounterA Dig 1,#CounterA Dig 0
    		endif
    	LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":"
    	LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," "
    	
        
        IF RTCHour.6=1 then
    		If RTCHour.5=1 then
    			LCDOut "PM"
    			else
    			LCDOut "AM"
    			endif
    		endif
    		'
    From this it seems that CounterA dig0 and dig1 represent the hour and RTCMin the minutes. Is it a simple case of using a variable to match these and then toggle another variable that holds value X, something like

    if CounterA dig0 + CounterA dig1 => 1 then tempset=26
    if CounterA dig0 + CounterA dig1 => 6 then tempset=32

    Or is there a better way (simpler?) to do this ?

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Using the LCD I obtained the values for DEC RTCHours, my logic being that this then gives me a variable which I can then use, eg 21hrs gives a value of 33.

    I then tried to use this value thus

    Code:
    	LCDOut $FE, $D4,"rtc value = ", dec rtchour
    	AlarmH1 = Dec(RTCHour)
        If alarmH1=33 then
         alarmled=1
        endif
    But I get a bad expression error with the AlarmH1 = Dec(RTCHour)

    If I can get the value into a varaible somehow I have something to work with

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Something like
    Code:
    HEXRTCHour = RTCHour $ $70
    Should convert the BCD into HEX
    I think....
    Dave
    Always wear safety glasses while programming.

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Dave, thanks for the reply, but I get a syntax error with that no matter how format it, (even added a HexRTCHour var byte in the code) -

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hmm..

    This is from one of mine to change the I2C output to HEX then display the DEC via serial.
    Code:
    I2CRead DS_SDA, DS_SCL, RTC, SecReg, [sec,MINs,hr,day,date,mon,yr] 
    
    SEC_T = sec & $70
    SEC_T = SEC_T>>4 'Tens place
    Serout2 PORTC.6, 16572,["SEC_T  ",DEC SEC_T, $d, $a]
    SEC_O = sec & $0F  'Ones place
    Serout2 PORTC.6, 16572,["SEC_O  ",DEC SEC_O, $d, $a]
    Dave
    Always wear safety glasses while programming.

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Hmm..

    This is from one of mine to change the I2C output to HEX then display the DEC via serial.
    Dave - I note your deliberate mistake to keep me on my toes

    Code:
    HEXRTCHour = RTCHour $ $70
    Code:
    SEC_T = sec & $70
    Thanks - that's compiled - will now go away and play

  7. #7
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Smile Matching time conditions

    Why not simply usesomething like a DS1337
    where you can have an alarm time and compare it with the current time and if there is a match the DS1337 has a pin that either goes high or low ( cant remember check the data sheet)
    This can then be connected to your interupt pin
    here is an example
    http://www.picbasic.co.uk/forum/show...highlight=toni

    Isaac

  8. #8
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Isaac,

    many thanks for the link - I'll study that and will look at breadboarding the 1337 chip.

    Melanie,

    I've looked at the datasheet on many occasions, but to those of us who can only grasp the basics, these datasheets tend to be somewhat daunting, and whilst I don't possess the Rosetta Stone, sometimes Egyptian would probably seem easier than many a datasheet by half

    Also, for me I learn far more about PBP from example code written by those more advanced at programming than trying to fathom out the ins and outs of complicated chip structure. After all, this is a forum on PicBASIC Pro. I guess I should of registered at Maxim's forum (assuming one exists) to ask for technical assistance with the data format from the DS1307.

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


    Did you find this post helpful? Yes | No

    Default

    After all, this is a forum on PicBASIC Pro. I guess I should of registered at Maxim's forum (assuming one exists) to ask for technical assistance with the data format from the DS1307.
    Just do as you're told and download that Datasheet!

    Then, and ONLY THEN you will be able to compare that I2C Statement with the DS1307's Registers. IT IS the Rosetta stone... until you've looked you won't see it.

    I'm NOT being iffy or off-hand with my answer to your query... I'm actually telling you EXPLICITLY that IT WILL HELP YOU UNDERSTAND.

    Skip all the crap and jump straight into the section on the Registers... look, it's all laid out crystal clear - it shows you what sequence they're in, how they're addressed, what's inside them... how on earth can you possibly understand what's going on in a piece of code if you don't understand what a particular BYTE of DATA has got inside it at any point in time.

    If I told you that Bit 7 of the SECONDS Register was kinda IMPORTANT - How would you know? I could be talking Greek (sorry Ioannis)!

    One look, and you know what the $D0 is all about in the I2C Statement. And what about $00 - what's it there for? The answer is screaming at you from the pages of the PBP Manual description of the I2C Command, and the DS1307's Datasheet. The two of them go together hand-in-hand. There's NO other secret document, no Training Course in Electronics or programming... just those two items together allow you fully understand, manipulate and control that chip. Don't handicap yourself unnescessarilly by dismissing it's 'beyond' your understanding. The DS1307 is a simple chip. But more importantly it's a stepping stone on the path to progressing to more complex hardware devices.

    Armed with that information, THEN come on the forum and ask your questions. Then folks can point you as to WHY something is the way it is. YOU ASKED about accessing Data out of sequence... that $00 holds the key, and that Datasheet tells you what you should change it to if you wanted just to extract say HOURS. But if I simply said you change it to $02, my answer would be totally meaningless unless you knew WHY!

    That is WHY I really PUSH folks to TRY and get to grips with Datasheets. The Ds1307 only has a dozen pages or so, and a chunk of those are irrelevant, so it's not like I'm asking you to digest Tolstoy's War & Peace.

  10. #10
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    ... And what about $00 - what's it there for? The answer is screaming at you from the pages of the PBP Manual description of the I2C Command, and the DS1307's Datasheet. The two of them go together hand-in-hand.
    Mel,

    Bear with me on this as I'm sure quite a few of us still have difficulties in getting our heads round bits and bytes and registers etc. But to try and answer your question and see if I've got some grips with the data sheet, here's my take on the above.

    $00 is the start of the register address (00H). This byte stores the seconds, bits 0-4 for the digits and bits 5-7 the 10's. The next byte (01H) is the same but for mins. 02H stores the hours, with bit 6 setting the device up for 12/24 hrs depending if set high or low. Bits 0-2 of 03H stores the days, 04H date, 05H month, 06H year (1st 4 bits for digits, last 4 bits decades).

    The only part I don't grasp is the $D0 part - The manual stated
    I2CREAD DataPin,ClockPin,Control,{Address,}[Var{,Var...}]{,Label}
    so in the code I have
    Code:
    I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]
    which transpires as datapin, clockpin, then control. but the only control reference I can find in the data sheet is for SQW (square wave out), and I'm still at a loss as to where you arrive at the $D0

  11. #11
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post

    The only part I don't grasp is the $D0 part -
    OK now got it...

    from the datasheet The address byte contains
    the 7 bit DS1307 address, which is 1101000, followed by the *direction bit (R/W ) which, for a write,
    is a 0.
    I used a binary to decimal / hex convertor.... 11010000 is D0, therefore the $D0 is the address which the PIC looks for to locate the DS1307 on the I2C buss and sets the DS1307 to either receive data or to send it ?

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