void RTCGetTime(struct atimestamp* timestamp)
{
    int8 time_hun;
	int8 time_sec;
	int8 time_sec2;
	int8 time_min;
    int8 time_hour;
	int8 time_yearday;
	int8 time_weekdaymonth;
    int1 nack;
    int8 address;
    address  = PCF8583_CURRENTTIME;

	i2c_start();
    nack = i2c_write(PCF8583_WRITE);
    if (nack) {
     i2c_stop();
    } else {
     i2c_write(address);
     i2c_start();
     nack = i2c_write(PCF8583_READ);
     if (nack) {
      i2c_stop();
     } else {
      time_hun  = i2c_read();
      time_sec  = i2c_read();
      time_min  = i2c_read();
      time_hour = i2c_read();
      time_yearday  = i2c_read();
      time_weekdaymonth= i2c_read(0);
      i2c_stop();

	  time_sec2 = BCDdecode(time_sec);
	  if (timestamp->second != time_sec2) {
       timestamp->hundredth= BCDdecode(time_hun);
	   timestamp->second   = time_sec2;
	   timestamp->minute   = BCDdecode(time_min);
	   timestamp->hour     = BCDdecode(time_hour); 

       timestamp->weekday = ((time_weekdaymonth & PCF8583_MASK_WEEKDAY) >> 5);  
 	   timestamp->day  = ((time_yearday & 0x30) >> 4)*10 + (time_yearday & 0x0F);
	   timestamp->month = ((time_weekdaymonth & 0x10) >> 4)*10 + (time_weekdaymonth & 0x0F);
	   timestamp->year = (time_yearday & 0xC0) >> 6;

      timestamp->updated = 1;
      }
	 }
    }
Esempio n. 2
0
File: clib.c Progetto: forwhat/OS
char* get_time()
{
	getTime();
	hour=BCDdecode(hour);
	min=BCDdecode(min);
	sec=BCDdecode(sec);
	time[0]=hour/10+'0';
	time[1]=hour%10+'0';
	time[2]=':';
	time[3]=min/10+'0';
	time[4]=min%10+'0';
	time[5]=':';
	time[6]=sec/10+'0';
	time[7]=sec%10+'0';
	return time;
}
Esempio n. 3
0
File: clib.c Progetto: forwhat/OS
char* get_date()
{
	getDate();
	century=BCDdecode(century);
	year=BCDdecode(year);
	month=BCDdecode(month);
	day=BCDdecode(day);
	date[0]=century/10+'0';
	date[1]=century%10+'0';
	date[2]=year/10+'0';
	date[3]=year%10+'0';
	date[4]='/';
	date[5]=month/10+'0';
	date[6]=month%10+'0';
	date[7]='/';
	date[8]=day/10+'0';
	date[9]=day%10+'0';
	return date;
}
void RTCGetTime(int1 alarm, struct atimestamp* timestamp)
{
    int8 time_hun;
	int8 time_sec;
	int8 time_sec2;
	int8 time_min;
    int8 time_hour;
	int8 time_yearday;
	int8 time_weekdaymonth;
    int1 nack;

    int8 address;

    if (alarm) address = PCF8583_ALARMTIME;
    else address = PCF8583_CURRENTTIME;

	i2c_start();
    nack = i2c_write(PCF8583_WRITE);
    if (nack) {
     i2c_stop();
    } else {
     i2c_write(address);
     i2c_start();
     nack = i2c_write(PCF8583_READ);
     if (nack) {
      i2c_stop();
     } else {
      time_hun  = i2c_read();
      time_sec  = i2c_read();
      time_min  = i2c_read();
      time_hour = i2c_read();
      time_yearday  = i2c_read();
      time_weekdaymonth= i2c_read();
      i2c_stop();

	  time_sec2 = BCDdecode(time_sec);
	  if (timestamp->second != time_sec2) {
       timestamp->hundredth= BCDdecode(time_hun);
	   timestamp->second   = time_sec2;
	   timestamp->minute   = BCDdecode(time_min);
	   timestamp->hour     = BCDdecode(time_hour); 
	   timestamp->day      = BCDdecode(time_yearday & PCF8583_MASK_DAY); 
	   timestamp->month    = BCDdecode(time_weekdaymonth & PCF8583_MASK_MONTH);
       timestamp->weekday  = time_weekdaymonth & PCF8583_MASK_WEEKDAY; 
	   timestamp->leapyear = time_yearday ^ PCF8583_MASK_YEAR;
       timestamp->updated = 1;
      }
      delay_ms(10);
	 }
    }
}