Exemple #1
0
bool ClockInit()
{
	//Initialize DS1307 Interface
	DS1307Init();

	//Clear CH bit of RTC
#define CH 7

	uint8_t temp;
	if(!DS1307Read(0x00,&temp)) return 0;

	//Clear CH Bit
	temp&=(~(1<<CH));//ch becomes 0

	if(!DS1307Write(0x00,temp)) return 0;

	//Set 12 Hour Mode
	if(!DS1307Read(0x02,&temp)) return 0;

	//Set 12Hour BIT
	temp|=(0b01000000);

	//Write Back to DS1307
	if(!DS1307Write(0x02,temp)) return 0;

	return 1;
}
Exemple #2
0
bool SetMinute(uint8_t min)
{
	uint8_t temp,result;
	temp=((min/10)<<4)|(min%10);
	result=DS1307Write(0x01,temp);
	return result;
}
Exemple #3
0
bool SetYear(uint8_t year)
{
	uint8_t temp,result;
	temp=((year/10)<<4)|(year%10);
	result=DS1307Write(0x06,temp);
	return result;
}
Exemple #4
0
bool SetDate(uint8_t date)
{
	uint8_t temp,result;
	temp=((date/10)<<4)|(date%10);
	result=DS1307Write(0x04,temp);
	return result;
}
Exemple #5
0
bool SetMonth(uint8_t month)
{
	uint8_t temp,result;
	temp=((month/10)<<4)|(month%10);
	result=DS1307Write(0x05,temp);
	return result;
}
Exemple #6
0
bool SetDay(uint8_t day)
{
	uint8_t temp,result;
	temp=(day%10);
	result=DS1307Write(0x03,temp);
	return result;
}
Exemple #7
0
bool SetSecond(uint8_t sec)
{
	uint8_t temp,result;

	temp=((sec/10)<<4)|(sec%10);
	result=DS1307Write(0x00,temp);

	return result;
}
void setTime(uint8_t hour,uint8_t minute,uint8_t second,uint8_t dow,uint8_t day,uint8_t month,uint8_t year){
	DS1307Write(0x00,dec2bcd(second));	//set seconds
	DS1307Write(0x01,dec2bcd(minute));	//set minutes
	DS1307Write(0x02,dec2bcd(hour) & 0x3F);	//set hours
	DS1307Write(0x03,dec2bcd(dow));	//set dow
	DS1307Write(0x04,dec2bcd(day));	//set date
	DS1307Write(0x05,dec2bcd(month));	//set month
	DS1307Write(0x06,dec2bcd(year));	//set year
}
Exemple #9
0
//0 is AM 1 is PM
bool SetAmPm(bool pm)
{
	uint8_t temp,result;

	DS1307Read(0x02,&temp);

	if(pm)
		temp|=0b00100000;//SET
	else
		temp&=0b11011111;//CLEAR

	result=DS1307Write(0x02,temp);

	return result;

}
Exemple #10
0
bool SetHour(uint8_t hr)
{
	uint8_t temp,result,am_pm;
	am_pm=GetAmPm();
	temp=((hr/10)<<4)|(hr%10);
	temp|=0b01000000; //12 Hr Mode

	if(am_pm)
	{
		temp|=0b00100000;
	}
	result=DS1307Write(0x02,temp);

	return result;

}
Exemple #11
0
void setTimeDOW(uint8_t dow){
	DS1307Write(0x03,dec2bcd(dow));	//set dow	
}
Exemple #12
0
void setTimeDay(uint8_t day){
	DS1307Write(0x04,dec2bcd(day));	//set date	
}
Exemple #13
0
void setTimeMonth(uint8_t month){
	DS1307Write(0x05,dec2bcd(month));	//set month	
}
Exemple #14
0
void setTimeYear(uint8_t year){
	DS1307Write(0x06,dec2bcd(year));	//set year
}
Exemple #15
0
void setTimeSecond(uint8_t second){
	DS1307Write(0x00,dec2bcd(second));	//set seconds	
}
Exemple #16
0
void setTimeHour(uint8_t hour){
	DS1307Write(0x02,dec2bcd(hour) & 0x3F);	//set hours	
}
Exemple #17
0
void setTimeMinute(uint8_t minute){
	DS1307Write(0x01,dec2bcd(minute));	//set minutes	
}
Exemple #18
0
void main()
{
	//Wait Util Other device startup
	_delay_loop_2(0);
	_delay_loop_2(0);

	//Initialize the LCD Module
	LCDInit(LS_BLINK);

	//Initialize I2C Bus
	I2CInit();

	//Enable Pull ups on keys
	PORTB|=((1<<PB2)|(1<<PB1)|(1<<PB0));

	//Clear CH bit of RTC
	#define CH 7

	uint8_t temp;
	DS1307Read(0x00,&temp);

	//Clear CH Bit
	temp&=(~(1<<CH));

	DS1307Write(0x00,temp);

	//Set 12 Hour Mode
	DS1307Read(0x02,&temp);

	//Set 12Hour BIT
	temp|=(0b01000000);

	//Write Back to DS1307
	DS1307Write(0x02,temp);

	
	LCDClear();
	
	LCDWriteString("DS1307 RTC Exmple");
	
	char Time[12];	//hh:mm:ss AM/PM
	
	//Now Read and format time
	uint8_t data;
	
	while(1)
	{
		
		DS1307Read(0x00,&data);
		Time[8]='\0';
		Time[7]=48+(data & 0b00001111);
		Time[6]=48+((data & 0b01110000)>>4);
		Time[5]=':';
	
		DS1307Read(0x01,&data);
	
		Time[4]=48+(data & 0b00001111);
		Time[3]=48+((data & 0b01110000)>>4);
		Time[2]=':';
	
		DS1307Read(0x02,&data);
	
		Time[1]=48+(data & 0b00001111);
		Time[0]=48+((data & 0b00010000)>>4);

		LCDClear();
	
		LCDWriteString("DS1307 RTC Exmple");
	
		LCDWriteStringXY(2,1,Time);

		//AM/PM
		if(data & 0b00100000)
		{
			LCDWriteStringXY(11,1,"PM");
		}
		else
		{
			LCDWriteStringXY(11,1,"AM");
		}

		//Wait Some time and keep testing key input
		uint8_t i;
		for(i=0;i<20;i++)
		{
		
			if(GetKeyStatus(2))
			{
				//Go To Main Menu
				ShowMainMenu();

				_delay_loop_2(0);
				_delay_loop_2(0);
				_delay_loop_2(0);

			}
			_delay_loop_2(5000);
		}
	}
	

	
}
Exemple #19
0
void startClock(void){
	DS1307Write(0x00,dec2bcd(getTimeSecond()) | 0x7F);	//set seconds
}
Exemple #20
0
void SetTime()
{
	

	uint8_t hr,min,sec,am_pm,temp;

	//Read the Second Register
	DS1307Read(0x00,&temp);
	sec=(((temp & 0b01110000)>>4)*10)+(temp & 0b00001111);

	//Read the Minute Register
	DS1307Read(0x01,&temp);
	min=(((temp & 0b01110000)>>4)*10)+(temp & 0b00001111);

	//Read the Hour Register
	DS1307Read(0x02,&temp);
	hr=(((temp & 0b00010000)>>4)*10)+(temp & 0b00001111);

	am_pm=(temp & 0b00100000)>>4;

	//If Hour Register is 0 make it 12, as 00:00:00 invalid time
	if(hr==0) hr=12;

	uint8_t sel=0;

	while(1)
	{
		LCDClear();

		LCDWriteString("00:00:00    <OK>");
		
		LCDWriteIntXY(0,0,hr,2);
		LCDWriteIntXY(3,0,min,2);
		LCDWriteIntXY(6,0,sec,2);

		if(am_pm)
		{
			LCDWriteStringXY(9,0,"PM");
		}
		else
		{
			LCDWriteStringXY(9,0,"AM");
		}

		//Draw Pointer
		LCDWriteStringXY(sel*3,1,"^^");

		//Input Up key
		if(GetKeyStatus(1))
		{
			if(!GetPrevKeyStatus(1))
			{
				if(sel==0)
				{	
					//Hour
					if(hr==12)
					{
						hr=1;
					}
					else
					{
						hr++;
					}
				}

				if(sel==1)
				{	
					//Min
					if(min==59)
					{
						min=0;
					}
					else
					{
						min++;
					}
				}

				if(sel==2)
				{	
					//Sec
					if(sec==59)
					{
						sec=0;
					}
					else
					{
						sec++;
					}
				}

				if(sel==3)
				{	
					//AM-PM
					if(am_pm==0)
					{
						am_pm=1;
					}
					else
					{
						am_pm=0;
					}
				}
				if(sel == 4)
				{
					//OK
					break;
				}
			}
		}

		//Input Down
		if(GetKeyStatus(0))
		{
			if(!GetPrevKeyStatus(0))
			{
				if(sel==0)
				{	
					//Hour
					if(hr==1)
					{
						hr=12;
					}
					else
					{
						hr--;
					}
				}

				if(sel==1)
				{	
					//Min
					if(min==0)
					{
						min=59;
					}
					else
					{
						min--;
					}
				}

				if(sel==2)
				{	
					//Sec
					if(sec==0)
					{
						sec=59;
					}
					else
					{
						sec--;
					}
				}

				if(sel==3)
				{	
					//AM-PM
					if(am_pm==0)
					{
						am_pm=1;
					}
					else
					{
						am_pm=0;
					}
				}
				if(sel == 4)
				{
					//OK
					break;
				}
			}
		}

		if(GetKeyStatus(2))
		{
			if(!GetPrevKeyStatus(2))
			{
				//Change Selection
				if(sel==4)
					sel=0;
				else
					sel++;
			}
		}

		PREV_PINB=PINB;

		_delay_loop_2(30000);

	}

	//Now write time back to RTC Module
	temp=((sec/10)<<4)|(sec%10);
	DS1307Write(0x00,temp);

	temp=((min/10)<<4)|(min%10);
	DS1307Write(0x01,temp);

	temp=((hr/10)<<4)|(hr%10);
	temp|=0b01000000; //12 Hr Mode
	if(am_pm)
	{
		temp|=0b00100000;
	}
	DS1307Write(0x02,temp);

	LCDClear();
	LCDWriteString("Message !");
	LCDWriteStringXY(0,1,"Main Time Set");

	uint8_t i;
	for(i=0;i<10;i++)
		_delay_loop_2(0);




}