Esempio n. 1
0
static 
void ReadRTC( void )	// Using Global struct RTC to store time into
{
	BYTE i;
	
	// init to 100k Baud
	i2cOpen(I2C_MASTER, I2C_SLEW_OFF, EE_BAUD(CLOCK_FREQ, RTC_BAUD));
	TRISG_RG0 =1;		// enables the RTC, CLK via 2.2K onto DS1307

	i2cWaitForIdle();
    i2cPutStartAndWait();       //Write I2C Start Condition, and wait for it to complete
    i2cPutByteAndWait(D1307_ADDR | I2C_WRITE);
   

    if(i2cWasAckReceived()) 		// check only once for ack 
	{
		i2cPutByteAndWait(0);		// Set address register  to 0
	
	     //Send repeated I2C start condition
        i2cRestartAndWait();

        //Send module address, and read/write bit (LSB bit) set - this is a read message
        i2cPutByteAndWait(D1307_ADDR |I2C_READ);
        if(i2cWasAckReceived()) 		// check only once for ack 
		{
	        for ( i = 0 ; i < RTCYear; i++)
	        {
		           rtc_regs[i]=i2cGetByte(I2C_ACK);  //ACK each byte except for last one. 
		    } 
			rtc_regs[i]=i2cGetByte(I2C_NACK); 		// NACK on last Byte, the Year	
		}
   	}
	
	i2cPutStopAndWait();
	
	LATG0 = 1;		// disables the DS1307 clock
	TRISG_RG0 =0;   // drive Ds1307 clock line high 
	
	
	//reset I2C back to 400K Baud
	i2cOpen(I2C_MASTER, I2C_SLEW_ON, EE_BAUD(CLOCK_FREQ, 400000));
	
	
	return ;
}	
Esempio n. 2
0
// communicates via I2c and sets the RTC chip to the date & time
// returns 1 if successful 
BYTE SetRTC( void ) // Using global RTC structure to set RTC from 
{
	BYTE i;
	BYTE ret = 1;
	
	rtc_regs[RTCYear]  = hextoBCD(RTC.Year - 2000); 
	rtc_regs[RTCMonth] = hextoBCD(RTC.Month)& 0x1F;
	rtc_regs[RTCDate]  = hextoBCD(RTC.Date)  & 0x3F;
	rtc_regs[RTCHour]  = hextoBCD(RTC.Hour) 	& 0x3f;
	rtc_regs[RTCMin]   = hextoBCD(RTC.Min) 	& 0x7f;
	rtc_regs[RTCSec]   = hextoBCD(RTC.Sec)	& 0x7f;  // Bit 7 contains the "Clock Halt" bit and must be 0 for the RTC to tun 
	rtc_regs[RTCDay]   = 0; 	// no support for day of the week
	rtc_regs[RTCControl] = 0x13; //32Khz square wave OC output  -- In case we need it for the Baro device
	
	// init to < 100K Baud
	i2cOpen(I2C_MASTER, I2C_SLEW_OFF, EE_BAUD(CLOCK_FREQ, RTC_BAUD));
	TRISG_RG0 =1;			// enable the SCK onto the D1307
	
	i2cWaitForIdle();
    i2cPutStartAndWait();       //Write I2C Start Condition, and wait for it to complete
    i2cPutByteAndWait(D1307_ADDR | I2C_WRITE);
   
    if(i2cWasAckReceived()) 
	{
		i2cPutByteAndWait(0);		// Set reg addr to 0
		for (i = 0; i<8;i++)
			i2cPutByteAndWait(rtc_regs[i]);	// set RTC registers ignoring ack
    }
    else
    	ret = 0;
    	
 	i2cPutStopAndWait();
	LATG0 = 1;		// disables the DS1307 clock
	TRISG_RG0 =0;   // drive Ds1307 clock line high 

	
	// reset I2C back to 400K Baud
	i2cOpen(I2C_MASTER, I2C_SLEW_ON, EE_BAUD(CLOCK_FREQ, 400000));
	
	return ret;

}	
Esempio n. 3
0
/*********************************************************************
 * Function:        BOOL MPFSInit(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          TRUE, if MPFS Storage access is initialized and
 *                          MPFS is is ready to be used.
 *                  FALSE otherwise
 *
 * Side Effects:    None
 *
 * Overview:        None
 *
 * Note:            None
 ********************************************************************/
BOOL MPFSInit(void)
{
    mpfsOpenCount = 0;
    mpfsFlags.Val = 0;

#if defined(MPFS_USE_PGRM)
    return TRUE;
#else
    /*
     * Initialize the EEPROM access routines.
     * Use ~ 400 Khz.
     */
    XEEInit(EE_BAUD(CLOCK_FREQ, 400000));

    return TRUE;
#endif
}