if(rtc_buf[0]%5==0 && prev_value != rtc_buf[0])
{
prev_value = rtc_buf[0];
write_EEPROM(address,hour);
address++;
write_EEPROM(address,minute);
address++;
write_EEPROM(address,second);
address++;
write_EEPROM(address,m);
address++;
write_EEPROM(address,n);
address++;
if(address>60000)address=0;
}
RB7=0;
//read_address=0;
if(RB7==1)
{
//read_address =0;
p=read_EEPROM(read_address);
read_address++;
q=read_EEPROM(read_address);
read_address++;
r=read_EEPROM(read_address);
read_address++;
RxByte=read_EEPROM(read_address);
read_address++;
RxByte1=read_EEPROM(read_address);
txt1(p+0x30);
txt1(10);
txt1(13);
txt1(q+0x30);
txt1(10);
txt1(13);
txt1(r+0x30);
txt1(10);
txt1(13);
z=((RxByte<<8)|RxByte1);
// Converting sample value to temperature
T=(z*0.48876);
Temp1 = (unsigned int)((T/100)%10); // 1st digit
Temp2 = (unsigned int)((T/10)%10); // 2nd digit
Temp3 = (unsigned int)((T/1)%10); // 3rd digit
// Displaying temperature in lcd
lcdcommand(0xcd);
if(T<=99)
{
lcddata(' '); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
}
lcdcommand(0xcd);
if(T>=100)
{
lcddata(Temp1+0x30); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
// lcddata('C');
}
txt1(Temp1+0x30);
txt1(Temp2+0x30);
txt1(Temp3+0x30);
txt1(10);
txt1(13);
read_address++;
}
/* Main function */
void main(void)
{
char i;
TRISC=0X00;
PORTC=0X00;
// lcd initialization
initlcd();
keypadinit();
// adc initialization
adc_init();
TXSTA=0X24;
RCSTA=0X90;
SPBRG=25;
I2Cinit();
/* While loop starts */
while(1)
{
for(i=0;i<15;i++) // for loop for rtc values and time&date setting and on time setting
rtc_buf[i]=rtc1307_read(i); // moving the read value to rtc buffer
lcdcommand(0X80); // general rtc running condition after setting
lcddisplay("DATE:");
lcdcommand(0X85);
convhex_lcd(rtc_buf[4]); // Date
lcddata('/');
convhex_lcd(rtc_buf[5]); // Month BCD to binary conversion
lcddata('/');
convhex_lcd(rtc_buf[6]); // Year
lcddata(' ');
convhex_lcd(rtc_buf[3]); // Year
lcddata(' ');
lcdcommand(0XC0);
lcddisplay("TIME:");
lcdcommand(0XC5);
convhex_lcd(rtc_buf[2]); // Hour BCD to binary conversion
lcddata(':');
convhex_lcd(rtc_buf[1]); // Min
lcddata(':');
convhex_lcd(rtc_buf[0]); // Sec
lcddata(' ');
/* RB6 center button pressing */
RB6=0;
if(RB6==1) // when center button pressed for setting date and time
{
lcdcommand(0X01);
__delay_ms(10);
lcdcommand(0X80);
lcddisplay("DATE: / / ");
do
{
lcdcommand(0X0E); //cursor display
lcdcommand(i);
pushbuttondate(); // gotO pushbuttondate function
if(count==8)
{
count=0;flag=1;
}
lcdcommand(0X0C); // cursor blinking off
}while(flag!=1);
__delay_ms(10);
lcdcommand(0XC0);
lcddisplay("TIME: : : ");
do
{
lcdcommand(0X0E);
lcdcommand(j);
pushbuttontime(); // goto pushbuttontime function
if(count==8)
{
count=0;flag1=1;
}
lcdcommand(0X0C);
}while(flag1!=1);
RB6=0;
while(RB6==0); // loading the set date and time to rtc
{
I2Cstart();
I2Csend(0xD0);
I2Csend(0x00);
I2Csend(second);
I2Csend(minute);
I2Csend(hour);
I2Csend(0X19);
I2Csend(date);
I2Csend(month);
I2Csend(year);
I2Cstop();
}
}
/* SET ON time */
RB0=0;
/* RB0 Pressing the upper left button */
if(RB0==1)
{
lcdcommand(0X01);
lcdcommand(0x80);
__delay_ms(10);
lcddisplay("SET ON TIME!");
lcdcommand(0XC0);
lcddisplay("TIME: : : ");
lcdcommand(0XC5);
convhex_lcd(rtc_buf[9]); // hour1
lcddata(':');
convhex_lcd(rtc_buf[10]); // minute1
lcddata(':');
convhex_lcd(rtc_buf[11]); //second1
lcddata(' ');
flag1=0;j=0XC5;
do
{
lcdcommand(0X0E);lcdcommand(j);
/* RB4 Pressing the right side button */
if(RB4==1)
{
x=0;while(RB4); // the value of x is initially zero
lcdcommand(j);
j++; // position increments
lcdcommand(0X14); // cursor right shift
count++;
if(j==0XC7 || j==0XCA) // auto increment the position when cursor reaches : or /
{
j=j+1;lcdcommand(j);count=count+1;
}
}
/* RB5 Pressing the left side button */
if(RB5==1)
{
x=0;while(RB5);
lcdcommand(j); // position decrements
j--;
lcdcommand(0X10); // cursor left shift
count--;
if(j==0XC7 || j==0XCA) // auto decrement the position when cursor reaches : or /
{
j=j-1;lcdcommand(j);count=count-1;
}
if(count<1)
{
x=0;count=1;j=0XC5;lcdcommand(0XC0);lcddisplay("TIME: : : ");
}
}
/* RB2 Pressing the up side button */
if(RB2==1)
{
x++;while(RB2); // x value increments from 0 to 9
lcdcommand(j);
if(x>9)
{
x=0;
}
lcddata(x+48);
}
/* RB3 Pressing the down side button */
if(RB3==1)
{
x--;while(RB3);
lcdcommand(j); // x value decrements from 9 to 0
if(x<0)
{
x=9;
}
lcddata(x+48);
}
/* RB1 */
if(RB1==1) // go back to time 0xc0
{
x=0;count=0;
j=0XC5;
lcdcommand(0XC0);
lcddisplay("TIME: : : ");
}
RB0=0;
if(RB0==1)
{
count=8;
}
if(j==0XC5){h11=x;}
if(j==0XC6){h21=x;}
if(j==0XC8){m11=x;}
if(j==0XC9){m21=x;}
if(j==0XCB){s11=x;}
if(j==0XCC){s21=x;}
second1=((s11&0X0F)<<4)|s21; // for second xx
minute1=((m11&0X0F)<<4)|m21; // for month xx // binary to BCD conversion
hour1=((h11&0X0F)<<4)|h21; // for hour xx
rtc1307_write(9,hour1);
rtc1307_write(10,minute1);
rtc1307_write(11,second1);
if(count==8)
{
count=0;flag1=1;
}
lcdcommand(0X0C);
}while(flag1!=1);
/* SET OFF time */
lcdcommand(0X01);
lcdcommand(0x80);
__delay_ms(10);
lcddisplay("SET OFF TIME!");
lcdcommand(0XC0);
lcddisplay("TIME: : : ");
lcdcommand(0XC5);
convhex_lcd(rtc_buf[12]); // hour0
lcddata(':');
convhex_lcd(rtc_buf[13]); // minute0
lcddata(':');
convhex_lcd(rtc_buf[14]); // second0
lcddata(' ');
flag1=0;j=0XC5;
do
{
lcdcommand(0X0E);lcdcommand(j);
/* RB4 Pressing the right side button */
if(RB4==1)
{
x=0;while(RB4); // the value of x is initially zero
lcdcommand(j);
j++; // position increments
lcdcommand(0X14); // cursor right shift
count++;
if(j==0XC7 || j==0XCA)
{
j=j+1;lcdcommand(j);count=count+1;
}
}
/* RB5 Pressing the left side button */
if(RB5==1)
{
x=0;while(RB5);
lcdcommand(j);
j--; // position decrements
lcdcommand(0X10); // cursor left shift
count--;
if(count<1)
{
x=0;count=1;j=0XC5;lcdcommand(0XC0);lcddisplay("TIME: : : ");
}
}
/* RB2 Pressing the up side button */
if(RB2==1)
{
x++;while(RB2); // x increments from 0 to 9
lcdcommand(j);
if(x>9)
{
x=0;
}
lcddata(x+48);
}
/* RB3 Pressing the down side button */
if(RB3==1)
{
x--;while(RB3); // x decrements from 9 to 0
lcdcommand(j);
if(x<0)
{
x=9;
}
lcddata(x+48);
}
/* RB1 */
if(RB1==1)
{
x=0;count=0;j=0XC5;lcdcommand(0XC0);lcddisplay("TIME: : : ");
}
RB0=0;
if(RB0==1)
{
count=8;
}
if(j==0XC5){h10=x;}
if(j==0XC6){h20=x;}
if(j==0XC8){m10=x;}
if(j==0XC9){m20=x;}
if(j==0XCB){s10=x;}
if(j==0XCC){s20=x;}
second0=((s10&0X0F)<<4)|s20;
minute0=((m10&0X0F)<<4)|m20; // binary to BCD conversion
hour0=((h10&0X0F)<<4)|h20;
rtc1307_write(12,hour0);
rtc1307_write(13,minute0);
rtc1307_write(14,second0);
if(count==8)
{
RB0=0;count=0;flag1=1;
}
lcdcommand(0X0C);
}while(flag1!=1);
do
{
enter();
}while(e!=2);
while(RB0!=0);
}
__delay_ms(2000);
lcdcommand(0x01);
adc_channel_select(1);
val=adc_result();
// Displaying temperature
lcdcommand(0x80);
lcddisplay("Temperature");
// Combining 10 bits and storing it in int from adc
t=(val*0.48876);
temp1 = (unsigned int)((t/100)%10); // 1st digit
temp2 = (unsigned int)((t/10)%10); // 2nd digit
temp3 = (unsigned int)((t/1)%10); // 3rd digit
// Displaying temperature in lcd
lcdcommand(0xc0);
if(t<=99)
{
lcddata(' '); // displaying the 1st digit
lcddata(temp2+0x30); // displaying the 2nd digit
lcddata(temp3+0x30); // displaying the 3rd digit
lcddata(0xdf); // for displaying degree symbol
lcddata('C');
}
lcdcommand(0xc0);
if(t>=100)
{
lcddata(temp1+0x30); // displaying the 1st digit
lcddata(temp2+0x30); // displaying the 2nd digit
lcddata(temp3+0x30); // displaying the 3rd digit
// lcddata(0xdf); // for displaying degree symbol
// lcddata('C');
}
//
// // Converting degree to farenheit
// f=((t*9)/5)+32;
//
// far1=(unsigned int) ((f/100)%10); // 1st digit
// far2=(unsigned int) ((f/10)%10); // 2nd digit
// far3=(unsigned int) ((f/1)%10); // 3rd digit
//
// // Displaying farenheit in lcd
// lcdcommand(0xc6);
// if(f<=99)
// {
// lcddata(' '); // displaying the 1st digit
// lcddata(far2+0x30); // displaying the 2nd digit
// lcddata(far3+0x30); // displaying the 3rd digit
// lcddata('F');
// }
//
// if(f>=99)
// {
// lcddata(far1+0x30); // displaying the 1st digit
// lcddata(far2+0x30); // displaying the 2nd digit
// lcddata(far3+0x30); // displaying the 3rd digit
// lcddata('F');
// }
if(rtc_buf[0]%5==0 && prev_value != rtc_buf[0])
{
prev_value = rtc_buf[0];
write_EEPROM(address,rtc_buf[2]);
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[1]);
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[0]);
address++;
__delay_ms(10);
write_EEPROM(address,m);
address++;
__delay_ms(10);
write_EEPROM(address,n);
address++;
__delay_ms(10);
if(address>60000)address=0;
}
RB7=0;
//read_address=0;
if(RB7==1)
{
//read_address =0;
u=read_EEPROM(read_address);
convhex_lcd(u);
read_address++;
v=read_EEPROM(read_address);
convhex_lcd(v);
read_address++;
w=read_EEPROM(read_address);
convhex_lcd(w);
read_address++;
RxByte=read_EEPROM(read_address);
read_address++;
RxByte1=read_EEPROM(read_address);
// p=(u & 0x0F) <<4;// (s1&0X0F)<<4)
// txt1(p);
// txt1(10);
// txt1(13);
// txt1(v);
// txt1(10);
// txt1(13);
// txt1(w);
// txt1(10);
// txt1(13);
z=((RxByte<<8)|RxByte1);
// Converting sample value to temperature
T=(z*0.48876);
Temp1 = (unsigned int)((T/100)%10); // 1st digit
Temp2 = (unsigned int)((T/10)%10); // 2nd digit
Temp3 = (unsigned int)((T/1)%10); // 3rd digit
// Displaying temperature in lcd
lcdcommand(0xcd);
if(T<=99)
{
lcddata(' '); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
}
lcdcommand(0xcd);
if(T>=100)
{
lcddata(Temp1+0x30); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
// lcddata('C');
}
txt1(Temp1+0x30);
txt1(Temp2+0x30);
txt1(Temp3+0x30);
txt1(10);
txt1(13);
read_address++;
}
__delay_ms(2000);
}
}
void txt1(int u)
{
TXREG=u; //
while(TXIF!=1); // txt until txflag is one
TXIF=0;
}
if(rtc_buf[0]%5==0 && prev_value != rtc_buf[0])
{
prev_value = rtc_buf[0];
write_EEPROM(address,rtc_buf[2]);
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[1]);
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[0]);
address++;
__delay_ms(10);
write_EEPROM(address,m);
address++;
__delay_ms(10);
write_EEPROM(address,n);
address++;
__delay_ms(10);
if(address>60000)address=0;
}
RB7=0;
//read_address=0;
if(RB7==1)
{
//read_address =0;
u=read_EEPROM(read_address);
convhex_lcd(u);
read_address++;
v=read_EEPROM(read_address);
convhex_lcd(v);
read_address++;
w=read_EEPROM(read_address);
convhex_lcd(w);
read_address++;
RxByte=read_EEPROM(read_address);
read_address++;
RxByte1=read_EEPROM(read_address);
// p=(u & 0x0F) <<4;// (s1&0X0F)<<4)
// txt1(p);
// txt1(10);
// txt1(13);
// txt1(v);
// txt1(10);
// txt1(13);
// txt1(w);
// txt1(10);
// txt1(13);
z=((RxByte<<8)|RxByte1);
// Converting sample value to temperature
T=(z*0.48876);
Temp1 = (unsigned int)((T/100)%10); // 1st digit
Temp2 = (unsigned int)((T/10)%10); // 2nd digit
Temp3 = (unsigned int)((T/1)%10); // 3rd digit
// Displaying temperature in lcd
lcdcommand(0xcd);
if(T<=99)
{
lcddata(' '); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
}
lcdcommand(0xcd);
if(T>=100)
{
lcddata(Temp1+0x30); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
// lcddata('C');
}
txt1(Temp1+0x30);
txt1(Temp2+0x30);
txt1(Temp3+0x30);
txt1(10);
txt1(13);
read_address++;
}
if ((rtc_buff[0] & 0x0F)%5==0) && ((prev_value!=rtc_buff[0]))
{
...
if(((rtc_buf[0] & 0x0F)%5==0) && ((prev_value!=rtc_buf[0] & 0x0f))
{
prev_value=rtc_buf[0]&0x0f;
if the time is 15/45/05 while pressing the button the time 15/45/05 should be saved in eeprom memory location.
0x0000 15
0x0001 45
0x0002 05
0x0003 m where m is upper 2 bits of adc result
0x0004 n where n is [B][COLOR="#FF0000"]lower 8 bits [/COLOR][/B]of adc result
if(((rtc_buf[0] & 0x0F)%5==0) && (prev_value!=rtc_buf[0] )
{
prev_value=rtc_buf[0];
write_EEPROM(address,rtc_buf[2]); // hour in BCD format
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[1]); /minut
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[0]); // second
address++;
__delay_ms(10);
write_EEPROM(address,m); // ADC MSB
address++;
__delay_ms(10);
write_EEPROM(address,n); // ADC LSB
address++;
__delay_ms(10);
if(address>60000)address=0;
}
if((rtc_buf[1] & 0x0f)%5==0 && rtc_buf[0]==0 && prev_value != rtc_buf[1])
{
prev_value = rtc_buf[1];
write_EEPROM(address,rtc_buf[2]);
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[1]);
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[0]);
address++;
__delay_ms(10);
write_EEPROM(address,m);
address++;
__delay_ms(10);
write_EEPROM(address,n);
address++;
__delay_ms(10);
if(address>60000)address=0;
}
RB7=0;
//read_address=0;
if(RB7==1)
{
//read_address =0;
u=read_EEPROM(read_address);
convhex_lcd(u);
read_address++;
v=read_EEPROM(read_address);
convhex_lcd(v);
read_address++;
w=read_EEPROM(read_address);
convhex_lcd(w);
read_address++;
RxByte=read_EEPROM(read_address);
read_address++;
RxByte1=read_EEPROM(read_address);
z=((RxByte<<8)|RxByte1);
// Converting sample value to temperature
T=(z*0.48876);
Temp1 = (unsigned int)((T/100)%10); // 1st digit
Temp2 = (unsigned int)((T/10)%10); // 2nd digit
Temp3 = (unsigned int)((T/1)%10); // 3rd digit
// Displaying temperature in lcd
lcdcommand(0xcd);
if(T<=99)
{
lcddata(' '); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
}
lcdcommand(0xcd);
if(T>=100)
{
lcddata(Temp1+0x30); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
// lcddata('C');
}
txt1(Temp1+0x30);
txt1(Temp2+0x30);
txt1(Temp3+0x30);
txt1(10);
txt1(13);
read_address++;
}
/* BCD conversion */
void conv_txt1(unsigned char bcd)
{
unsigned char temp3,temp4;
temp3=bcd>>4;
txt1(temp3|0x30); ///////hsb
msb=temp3|0x30;
temp4=bcd&0x0F;
txt1(temp4|0x30); ///////lsb
lsb=temp4|0x30;
}
prev_value = rtc_buf[1];
__delay_ms(2000);
if((rtc_buf[1] & 0x0f)%5==0 && rtc_buf[0]==0 && prev_value != rtc_buf[1])
{
prev_value = rtc_buf[1];
write_EEPROM(address,rtc_buf[2]);
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[1]);
address++;
__delay_ms(10);
write_EEPROM(address,rtc_buf[0]);
address++;
__delay_ms(10);
write_EEPROM(address,m);
address++;
__delay_ms(10);
write_EEPROM(address,n);
address++;
__delay_ms(10);
if(address>60000)address=0;
}
RB7=0;
//read_address=0;
if(RB7==1)
{
//read_address =0;
u=read_EEPROM(read_address);
convhex_lcd(u);
read_address++;
v=read_EEPROM(read_address);
convhex_lcd(v);
read_address++;
w=read_EEPROM(read_address);
convhex_lcd(w);
read_address++;
RxByte=read_EEPROM(read_address);
read_address++;
RxByte1=read_EEPROM(read_address);
z=((RxByte<<8)|RxByte1);
// Converting sample value to temperature
T=(z*0.48876);
Temp1 = (unsigned int)((T/100)%10); // 1st digit
Temp2 = (unsigned int)((T/10)%10); // 2nd digit
Temp3 = (unsigned int)((T/1)%10); // 3rd digit
// Displaying temperature in lcd
lcdcommand(0xcd);
if(T<=99)
{
lcddata(' '); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
}
lcdcommand(0xcd);
if(T>=100)
{
lcddata(Temp1+0x30); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
// lcddata('C');
}
txt1(Temp1+0x30);
txt1(Temp2+0x30);
txt1(Temp3+0x30);
txt1(10);
txt1(13);
read_address++;
}
__delay_ms(2000);
RB7=0;
if(RB7==1)
{
lcdcommand(0x01);
lcdcommand(0x80);
lcddisplay("Temperature");
lcdcommand(0xc0);
u=read_EEPROM(read_address);
convhex_lcd(u);
read_address++;
v=read_EEPROM(read_address);
convhex_lcd(v);
read_address++;
w=read_EEPROM(read_address);
convhex_lcd(w);
read_address++;
RxByte=read_EEPROM(read_address);
read_address++;
RxByte1=read_EEPROM(read_address);
read_address++;
conv_txt1(u);
conv_txt1(v);
conv_txt1(w);
txt1(10);
txt1(13);
z=((RxByte<<8)|RxByte1);
// Converting sample value to temperature
T=(z*0.48876);
Temp1 = (unsigned int)((T/100)%10); // 1st digit
Temp2 = (unsigned int)((T/10)%10); // 2nd digit
Temp3 = (unsigned int)((T/1)%10); // 3rd digit
// Displaying temperature in lcd
lcdcommand(0xcb);
if(T<=99)
{
lcddata(' '); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
lcddata(0xdf); // for displaying degree symbol
lcddata('C');
}
lcdcommand(0xcb);
if(T>=100)
{
lcddata(Temp1+0x30); // displaying the 1st digit
lcddata(Temp2+0x30); // displaying the 2nd digit
lcddata(Temp3+0x30); // displaying the 3rd digit
lcddata(0xdf); // for displaying degree symbol
lcddata('C');
}
txt1(Temp1+0x30);
txt1(Temp2+0x30);
txt1(Temp3+0x30);
txt1(10);
txt1(13);
__delay_ms(1000);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?