How to display the first variable ?

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys,

 

How can I display the first variable from this array ?

I want to return to Sun after it's finished on Sat,

 

variable :

char *weekday[]={"Sun","Mon","Tue","Wed","Thr","Fri","Sat"};

.

.

.

if (ds1307_addr[3] >= 6)
        {
            weekday[ds1307_addr[3]] == 0;
        }

Any clues ?

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

or :

if (ds1307_addr[3] >= 6)
		{
			ds1307_addr[3] == 0;
		}

?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DS1307's register#3 holds the "day of the week" as a number between 1 and 7.

Your array has index 0 to 6.

 

The simplest way of handling this is to use:

char *weekday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"};

Then you don't need to do any mangling.

Other RTC chips use 0 to 6 for the "day of the week"

 

Note that most RTC chips store most data as BCD.    For display purposes,   you mask the valid bits and use "%02x" format.

You only need to convert from binary to BCD or vice-versa if you want to do maths on the values.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll try this solution

 

char *weekday[]={"Sun","Mon","Tue","Wed","Thr","Fri","Sat","Sun"};

thanks for the clue David...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
ds1307_addr[3] == 0; // I suppose one = sign would be enough... (affects instead of comparing)
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In any case, the ">= 6" was wrong anyways. It should have been "> 6".

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Koshi:

How long is a week (seems 7 days in your planet, anyways.. Maybe one does not need sun days)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A 7-string C array has members with indexes 0 .. 6.

The DS1307 stores the day-of-the-week with 1 .. 7 with Sunday being 7.

Other RTC chips use 0 .. 6 with Sunday being 0.  e.g. PCF8563

 

God gave us Unix,  and it was good.   The tm struct has a member:

int    tm_wday  day of week [0,6] (Sunday = 0)

So you have to do some kludging for a DS1307.   i.e. mapping 7 to 0.    Either with the modulus operator or by testing for 7.

 

bianchi's test for >=6 is clearly not a valid test for 7.    But bianchi is never too confident with >, >=, == logical operators.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:

@Koshi:

How long is a week (seems 7 days in your planet, anyways.. Maybe one does not need sun days)

In the original code, if the day was equal to or greater than 6, then make it 0. So if the value was 6 (Saturday), then change it to 0 (Sunday), so it was Saturdays being skipped, not Sundays.

Regards,
Steve A.

The Board helps those that help themselves.