• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Comparing output from DS1307

Status
Not open for further replies.

johnl69

Member
Can I directly compare the BCD output from a ds1307 with another register or do I need to convert it to binary first?

i have a program that takes the time from the RTC and compares it with some "alarm" registrys that I have set up;

C:
// ****  Check Blue timer ***********
    if (((hour >= ON_BLUE_hr)&&(minute >= ON_BLUE_min))&&((hour <= OFF_BLUE_hr)&&(minute <= OFF_BLUE_min)))
    {
        BLUE_L = 1;
    }
    else
    {
        BLUE_L = 0;
    }
the ON and OFF registry are set at;

C:
unsigned int ON_BLUE_hr = 0b00001000;
unsigned int ON_BLUE_min = 0b00000000;

unsigned int ON_MAIN_hr = 0b00001001;
unsigned int ON_MAIN_min = 0b00000000;

unsigned int OFF_MAIN_hr = 0b00100000;
unsigned int OFF_MAIN_min = 0b00000000;

unsigned int OFF_BLUE_hr = 0b00100000;
unsigned int OFF_BLUE_min = 0b00110000;
the alarm time display correctly on an lcd but the but the light only turn on when they should.
 

johnl69

Member
You might like to have a look here:

http://www.engscope.com/pic-example-codes/real-time-clock-and-calendar/

This uses a data structure to easily compare two date/times.
From what I gather ( i may be wrong) that routine has the alarm triggering at a set time/date which isn't what I'm after I need the alarm to be on between the 2 times incase the power is turned off then the light will go back to what ever state it should be at when the power turn on again.
 

granddad

Well-Known Member
I compare hours from DS1307 to 'action times' no problems ,, I usually use BCD / hex notation as 0x10 as 10 hours , is the DS set for 12 or 24 hr.
 

johnl69

Member
I compare hours from DS1307 to 'action times' no problems ,, I usually use BCD / hex notation as 0x10 as 10 hours , is the DS set for 12 or 24 hr.
24hr.

A strange thing happened at 20:00 the lights turned on and then 1 minute later they all turned off
 

johnl69

Member
I just changed it to

C:
hr = hour & 0b00111111;

// ****  Check Blue timer ***********
   if (((hr >= ON_BLUE_hr)&&(minute >= ON_BLUE_min))&&((hr <= OFF_BLUE_hr)&&(minute <= OFF_BLUE_min)))
   {
        BLUE_L = 1;
   }
   else
   {
        BLUE_L = 0;
   }
Just to make sure there are no extra 1's being read from the extra bits but it's the same.[/code]
 

johnl69

Member
My read / write RTC routines always have built in " convert to english" and "convert back to nonsense" routines so its never an issue...
I'll do a BCD to binary conversion on it tomorrow see if it makes a difference.

21:00 when the lights should turn off the blue light came on for 1 minute. it only seem to be working on the set times not between them??
 

johnl69

Member
Sorted now, not sure whether it was necisary to convert to binary but it does make it easier to set the times

C:
    binary_hr = BCD2Binary(hr);
    binary_min = BCD2Binary(minute);

    if ((binary_hr >= binary_blue_off_hr)&&(binary_min >= binary_blue_off_min))
    {
        BLUE_L = 0;
    }
    else if ((binary_hr >= binary_blue_on_hr)&&(binary_min >= binary_blue_on_min))
    {
        BLUE_L = 1;
    }
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top