Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Data logger using pic16f877a

Status
Not open for further replies.

Logu KS

Member level 2
Joined
Jul 19, 2014
Messages
43
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
Chennai
Activity points
372
I am trying to make a temperature data logger using rtc, lm35 and eeprom 24lc512. I did upto writing and reading the temperature value in eeprom. Now i want to write and read the time and date also. At some periodic intervals that is set using rtc the date, time and the tempertaure value to be written into the eeprom. Then using a button the written values should be read and display it hyperterminal and lcd.

Code:
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++;
	}
I just added the writing and reading part of the code. rtc_bu[0] is for seconds buffer. If seconds becomes multilples of 5 (ie) 5,10,15,20,25..... the date, time and temperature value should be written into the eeprom and pressing a button the written values should be read and displayed in lcd and hyperterminal.
 

Now I am posting my whole code below upto which I did.
Code:
/* 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;
}
My problem in the above code is in this part
Code:
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++;
	}
when the rtc seconds becomes multiples of 5 in that time the corresponding hour,min,sec and temperature value should written into the eeprom and then it is read back using a button.
i want output like this if time in rtc is 12:05:05 then it should be written into the eeprom as 12 05 05 and the corresponding temperature at that time.
 
Last edited:

hello,

is rtc_buff[0] the value of second in decimal ? or in BCD
in BCD when you have 10 -> it is 16 binary value.
maybe you need to mask MSB to only keep the LSB part 0 or 5

Code:
if ((rtc_buff[0] & 0x0F)%5==0) && ((prev_value!=rtc_buff[0]))
{
...
 
rtc_buf[0] is BCD only

Code:
if(((rtc_buf[0] & 0x0F)%5==0) && ((prev_value!=rtc_buf[0] & 0x0f))
{
prev_value=rtc_buf[0]&0x0f;

is this correct..

how to store the time in the eeprom when rtc seconds column becomes multiples of 5.

if the time is 15/45/05 while pressing the button the time 15/45/05 should be saved in eeprom memory location.
like this

0x0000 15
0x0001 45
0x0002 05
0x0003 m where m is upper 2 bits of adc result
0x0004 n where n is lower 2 bits of adc result

every 5 seconds or based on the condition given in the rtc i want data to be stored like this......
 
Last edited:

hello,


if the time is 15/45/05 while pressing the button the time 15/45/05 should be saved in eeprom memory location.

it is not so clear :
what must be the event to store the value ?
multiple of 5 second
or pressing a button

you can store each value of time direct from rtc_buff
as you did in your previous code ..
and same for ADC value store ADRH and ADRL

Code:
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



it seems OK !

you can compare all 8 bits of prev_value with or without masking MSB

Code:
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;
}

After all, the manier to store the data in eeprom depends only
of How do you will treat the data when reading back...
if you store time in BCD, you read back time direct in BCD.

if you wand to store Physical value as temperature instead of raw value of ADC ,
it is another way.


Dont forget to handle the absolute Adress of Eeprom , after writing each bloc of data .

You can also think about to manage PAGE WRITING to 24LC512..
but the amount of data to write per page must be modulo 64 bytes.

I did an application with uses Page management for a 24LC256 .. 512 pages of 64 bytes.
it is usefull when Speed reactivity is needed.. because no delay between each byte writing
inside the same page..
but maybe not necessary for your case.
 

I want to know whether the below condition is suitable for writing the data every 5 minutes. when minutes column becomes 5,10..... and seconds should be in 0.(for example 15:10:00 the data should be written and then at 15:15:00 the next data should be written)

Code:
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++;
	}

In the above code convhex_lcd is function for converting bcd to format which is suitable for displaying the data in lcd.

Code:
/* 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;
}

i am trying the above code for sending the data to hyperterminal.
'
 
Last edited:

It seems Ok, but
Because of the test
Code:
prev_value = rtc_buf[1];
concerne only the minute
You can write more than once , if the main loop duration is less than 1 second..
 

I want to write just once for every five minutes.
 

sorry, i didn't take care about this delay
Code:
__delay_ms(2000);
in the main loop .
so no problemo !
you never will have the same second 0 in a same minute 0 or minute 5...
 
where i have to insert that delay in this function...
when i was trying this function in my code the data is written but not exactly at condition which i gave......
Code:
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++;
	}

i got ouput like this
154510 125
155020 130
but not exactly at the 00 seconds.
 

maybe it is because you have a
Code:
__delay_ms(2000);
in your main loop while(1)


what you can do, is to synchronise your main loop
by testing second 0 instead of using this delay...
 

Problem in reading is solved and displays the correct values when pressing the button. I removed that delay values. For every 1 minute data is stored and while pressing button the data is read.

Now what i need is if i press button RB7 then stored values should be displayed one by one...

Code:
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);
		}

after pressing button stored values should be displayed one by one
 

To read one by one...
you want to read from adress Zero of eeprom ?
until the last adress used ?

we can suppose you know the last adress used for stroring data : is it read_adress ?.
you must refresh read_adress value, each time you write a datas in the eeprom
and maybe ,it could be better to store this lastvalue of adress in the last 2 bytes of the Eeprom.
If you do a reset , reload back this last adress used , before using again the eeprom.

To read one by one, test also the release of the button before going back in the loop of program

i did this kind of management for a datalogger with a 24LC256...
and for reading back the results stored in eeprom, but via te RS232 terminal Event, not with a button.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top