Ejemplo n.º 1
0
/*************************************************************************
 * Function Name: RTC_Init
 * Parameters: void
 *
 * Return:  0: sucess
 *		    1: fail
 *
 * Description: Initialize RTC, configure prescaler, CIIR and AMR register
 *
 *************************************************************************/
int rtc_init(unsigned char BackComp)
{
    LPC_Rtc_DateTime_t datetime;
    LPC_Rtc_Date_t date;

    /* check if RTC is enabled already -> battery buffered */
    if (RTC_CCR & CCR_CLKEN)
    {
        /* make sure it is set to external watch quartz, no matter if enabled or not */
        RTC_CCR |= CCR_CLKSRC;

        /* get current date from RTC */
        RTC_GetDate(&date);
    }
    else
    {
        /* disable and reset RTC */
        RTC_CCR = CCR_CTCRST;
        RTC_CCR = 0x00;
        RTC_CCR |= CCR_CLKSRC;  /* 32kHz watch quarz */

        /* init all necessary RTC registers */
        RTC_ILR    = ILR_COUNT_INC_FLAG | ILR_ALARM_FLAG | ILR_SUB_SEC_FLAG;    /* clear all interrupt flags of RTC */
        RTC_CIIR   = CIIR_SEC;                                                  /* enable second interrupt */
        RTC_AMR    = AMR_SEC;                                                   /* mask second interrupts */
        RTC_CISS   = CISS_DISABLE;                                             /* no sub second interrupts */

        /* set default time */
        memcpy((unsigned char *)&datetime, (unsigned char *)&RTC_InitDateTime, sizeof(LPC_Rtc_DateTime_t));

        /* initialize Date and Time */
        RTC_SetDateTime(&datetime);

    }

    /* check if the date is valid, set default if not */
    if(!IsValidDay(date.year, date.month, date.day))
    {
        memcpy((char *)&datetime, (char *)&RTC_InitDateTime, sizeof(LPC_Rtc_DateTime_t));

        /* initialize Date and Time */
        if (RTC_SetDateTime(&datetime))
            return 1;
    }

    /* convert current time to unix time */
    RTC_datetime_to_unix(&unix_time, &datetime);

    /* set interrupt vector entry for RTC 1s interrupt */
    set_isr_handler( RTC_IRQ,(void *)RTC_ISR,RTC_IRQ_PRIO);
#ifndef LPC1768
    /* Enable the interrupts */
    VICIntEnable |= (1<<13);
#endif
    RTC_Enable();

    return 0;
}
Ejemplo n.º 2
0
int main() 
{
    rtc_t rtc;
    SystemInit();
    UART0_Init(9600);  

    RTC_Init();
    rtc.hour = 10; //  10:40:20 am
    rtc.min =  40;
    rtc.sec =  0;

    rtc.date = 1; //1st Jan 2016
    rtc.month = 1;
    rtc.year = 2016;
    rtc.weekDay = 5; // Friday: 5th day of week considering monday as first day.   


    /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetDateTime(&rtc);  //  10:40:20 am, 1st Jan 2016


    /* Display the Time and Date continuously */
    while(1)
    {
        RTC_GetDateTime(&rtc);
        UART0_Printf("\n\rtime:%2d:%2d:%2d  Date:%2d/%2d/%4d",(uint16_t)rtc.hour,(uint16_t)rtc.min,(uint16_t)rtc.sec,(uint16_t)rtc.date,(uint16_t)rtc.month,(uint16_t)rtc.year);
    }	      
}
void rtc_test()
{
    rtc_t rtc;
    UART_Printf("\n\rConnections SCL->PC.3 SDA->PC.4");
    UART_Printf("\n\r Make connections and hit 'k' to test! ");
    while(UART_RxChar()!='k');   

    RTC_Init();
    rtc.hour = 0x10; //  10:40:20 am
    rtc.min =  0x40;
    rtc.sec =  0x00;

    rtc.date = 0x01; //1st Jan 2016
    rtc.month = 0x01;
    rtc.year = 0x16;
    rtc.weekDay = 5; // Friday: 5th day of week considering monday as first day.




    /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetDateTime(&rtc);  //  10:40:20 am, 1st Jan 2016


    /* Display the Time and Date continuously */
    while(1)
    {
        RTC_GetDateTime(&rtc);
        UART_Printf("\n\rtime:%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)rtc.hour,(uint16_t)rtc.min,(uint16_t)rtc.sec,(uint16_t)rtc.date,(uint16_t)rtc.month,(uint16_t)rtc.year);
    }
}
int main() 
{
    rtc_t rtc;

    /*Connect RS->PB0, RW->PB1, EN->PB2 and data bus to PORTB.4 to PORTB.7*/
    LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7);
    LCD_Init(2,16);

    RTC_Init();
    rtc.hour = 0x10; //  10:40:20 am
    rtc.min =  0x40;
    rtc.sec =  0x00;

    rtc.date = 0x01; //1st Jan 2016
    rtc.month = 0x01;
    rtc.year = 0x16;
    rtc.weekDay = 5; // Friday: 5th day of week considering monday as first day.




    /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetDateTime(&rtc);  //  10:40:20 am, 1st Jan 2016


    /* Display the Time and Date continuously */
    while(1)
    {
        RTC_GetDateTime(&rtc);
        LCD_GoToLine(0);
        LCD_Printf("time:%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)rtc.hour,(uint16_t)rtc.min,(uint16_t)rtc.sec,(uint16_t)rtc.date,(uint16_t)rtc.month,(uint16_t)rtc.year);
    }

    return (0);
}
Ejemplo n.º 5
0
static void settime()
{
	RTC_SetDateTime(&Date,&Time);
	timeflag = 0;
	PageJump(&pSys);
}
Ejemplo n.º 6
0
//uint8_t readCfgFile(DATE *adate,TIME *atime, uint8_t *filename_dat, uint8_t atomic)
uint8_t readCfgFile(uint8_t *filename_dat, uint8_t atomic)
{
	DIR *dir;
	uint32_t cluster, fileSize, firstSector;
	uint16_t k;
	uint8_t i,j,ld,lt;
	uint8_t filename[]="CONFIG  CFG";
	uint8_t filename2[]="_CONFIG CFG";
	
	TIME_t time;
	DATE_t date;
	
	
	dir = findFiles (GET_FILE, filename, filename, atomic); 	//get the file location
	if(dir == 0) 
		return(0);

	cluster = (((uint32_t) dir->firstClusterHI) << 16) | dir->firstClusterLO;
	fileSize = dir->fileSize;
	
	ld = 0;
	lt = 0;
	
	while(1)
	{
		firstSector = getFirstSector (cluster);
		for(j=0; j<SectorPerCluster; j++)
		{
			SD_readSingleBlock(firstSector + j, atomic);
			for(k=0; k<512; k++)
			{
				switch(buffer[k])
				{
					case	'S':
								k++;
								switch(buffer[k])
								{
								case 'T':
                             k++;
                             time.h = getDec((uint8_t*)buffer+k);
                             time.m = getDec((uint8_t*)buffer+k+2);
                             time.s = getDec((uint8_t*)buffer+k+4);
                             break;
								case 'D':
                             k++;
                             date.d = getDec(&buffer[k]);
									           date.m = getDec(&buffer[k+2]);
                             date.y = 20 + getDec(&buffer[k+4]);
                             break;
								case 'F':
                             k = k+2;
                             for(i=0;i<13;i++)
                             {
                                if(buffer[k+i] < 0x20)		//if any control code
                                   break;
                                filename_dat[i] = buffer[k+i];
                             }
                             k = k+i;
                             break;
								case 'M':    //mask definitions: M - mic only, S - SHT sensor only, T - DS1820 1-wire sensor, X - Mic+SHT, '-' - nothing
                             k++;
                             for(i=0;i<12;i++)
                             {
                               Mask.SHT = Mask.SHT<<1;
                               Mask.MIC = Mask.MIC<<1;
                               switch(buffer[k+i])
                               {
 //                                case 'X':					//SHT mask generated from mic mask!
 //                                        Mask.SHT |= 0x0001;
                                 case 'M':
                                         Mask.MIC |= 0x0001;
                                         break;
 //                                case 'S':
 //                                        Mask.SHT |= 0x0001;
 //                                        break;
                                 case 'T':
                                         Mask.DS |= 0x01;		// any T will cause DS mask to be one...
                                         break;
                                 default:
                                         break;
                               }
                             }      
                             k = k+i;
								}
								break;
					case 'A':
								k++;
								if(buffer[k]=='D')
								{	
									k++;
									ADate[ld].d = getDec((uint8_t*)buffer+k);
									//k +=2;
									ADate[ld].m = getDec((uint8_t*)buffer+k+2);
									//k +=2;
									ADate[ld].y = 20 + getDec((uint8_t*)buffer+k+4);
									ld++;
								}
								else if(buffer[k]=='T')
								{	
									k++;
									ATime[lt].h = getDec((uint8_t*)buffer+k);
									//k +=2;
									ATime[lt].m = getDec((uint8_t*)buffer+k+2);
									//k +=2;
									ATime[lt].s = getDec((uint8_t*)buffer+k+4);
									lt++;
								}
								break;
					
				}
				
				if (k >= fileSize )
				{
					findFiles(RENAME,filename, filename2, atomic);
					RTC_SetDateTime(&date, &time);
//??				if(Mask.SHT)
//					{
						generate_mask_bm();
//					}
					return(lt);
				}
			}
		}
		cluster = getSetNextCluster (cluster, GET, 0, atomic);
		if(cluster == 0) 
		{
#if RSCOM == 1
			printf_P(PSTR("ERR GETTING CLUSTERb\n")); 
#endif		//BIGAVR
			return(0);
		}
	}
	return(0);
}