Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to set time and date from keypad

Status
Not open for further replies.
hi dear

i am doing Rtc using ds1307 with pic16f877a

i need a help how to set time and date from keypad by using this function

ds1307_set_date_time(31,12,9,2,23,59,55);//day, month,year,dow,hr,min.sec

from this

void ds1307_set_date_time(BYTE day, BYTE mth, BYTE year, BYTE dow, BYTE hr, BYTE min, BYTE sec)
{
sec &= 0x7F;
hr &= 0x3F;

i2c_start();
i2c_write(0xD0); // I2C write address
i2c_write(0x00); // Start at REG 0 - Seconds
i2c_write(bin2bcd(sec)); // REG 0
i2c_write(bin2bcd(min)); // REG 1
i2c_write(bin2bcd(hr)); // REG 2
i2c_write(bin2bcd(dow)); // REG 3
i2c_write(bin2bcd(day)); // REG 4
i2c_write(bin2bcd(mth)); // REG 5
i2c_write(bin2bcd(year)); // REG 6
i2c_write(0x80); // REG 7 - Disable squarewave output pin
i2c_stop();
}



i have 4 four keys connected porta with pullup

i have to do menu function to set time and date

any one help me i am using ccs c complier pic 16f877a
 
only 4 keys?
how about making them:
Increment, Decrement , Next , Set

first two would edit parameter value,
next would be used to select parameter to be edited,
set would call function that finally writes the parameters to DS1307
 
thanks panic ,give me a sample code to slelect menu mode to set time (call function)

keys are menu ,up ,next,set.....
 
Last edited:
I use 4 keys on ALL my units....
Up, Down, Enter and next... If two keys are pressed at the same time ( up and down ) it clears.

I also have done a shift on the first key, so I can have six functions...

Here is my security entry function:- Maybe it will help.

Code:
char security()
	{
	int code = 0;
	char key=0;
	I2cReadStr(lcdbuf,0x390,16);  // ignore this its an external string in I2C eeprom
	LCDline(1);
	LCDprint(lcdbuf);
	while(1)
		{
		sprintf(lcdbuf,"      %04d      ",code);
		LCDline(2);
		LCDprint(lcdbuf);
		key = keyhit();
		if(key == 4)
			{
			if(code == CODE ) return 1;
			else return 0;
			}
		if(key == 1 && code < 10000 )
			code*=10;
		if(key == 2 )
			code++;
		if(key == 3 && code)
			code--;
		if(key == 5)
			code = 0;
		}
	}
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top