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.

PIC16F684 : store temperature data inside EEPROM in c

Status
Not open for further replies.

lizzy

Newbie level 5
Joined
Apr 11, 2010
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
malaysia
Activity points
1,332
hello, i'm really new in this embedded stuff. can someone help/ teach me how to code it? that is i have to save/store temperature data into EEPROM in 512 cycles and every cycle is 30 mins. please i really 0 input about this program
 

pic16f684 is having only 256 bytes of eeprom, you have to go for a higher end processor or by using an external eeprom like 24xx
 

    lizzy

    Points: 2
    Helpful Answer Positive Rating
sorry my mistake. like what u said js store 256 bytes. can u g guide me to build my program rajudp?
 

how you are reading temperature, and what is the range?
 

if it is possible the range is more than 200degree. (if i can find the suitable thermistor) but for now i js set it in normal temperature between 0 and 140 farenheit. and i hope it can save data every 30 mins
 

look the links you will get an idea

**broken link removed**
http://quozl.netrek.org/ts/
**broken link removed**


you can use LM 35 pt100 or any thermistor for this application ,

the microcontroller is having 10 bit ADC , and yoy have to use it as 8bit to store 256 values.

do you want to store only temperature or with time stamp
 

    lizzy

    Points: 2
    Helpful Answer Positive Rating
yes i want to store the data with time stamp. but i don't need to display the data in any lcd. i js pick the data inside pic connected to pickit2.
i already search around but still i really have no idea. j assume that i have nothing about this coding. please help me. how to code it.
 

then can u help me in this? oh please.
 

this is the code. how to write EEPROM inside it?

Code:
#include <pic.h>

#define	DIGIT1	RA0	
#define	DIGIT2	RA1	
#define 	DIGIT3	RA2	
#define	ON			0
#define	OFF		1

/* 
RA5 - Segment a
RC5 - Segment b
RC4 - Segment c
RC3 - Segment d
RC2 - Segment e
RC1 - Segment f
RC0 - Segment g

RA4 - Thermistor
*/

__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
  & UNPROTECT & BORDIS & IESODIS & FCMDIS);
  
  
const char LEDDigit[10] = {
    0b0000001,                  //  Digit Zero
    0b1001111,                  //  Digit One
    0b0010010,                  //  Digit Two
    0b0000110,                  //  Digit Three
    0b1001100,                  //  Digit Four
    0b0100100,                  //  Digit Five
    0b0100000,                  //  Digit Six
    0b0001111,                  //  Digit Seven
    0b0000000,                  //  Digit Eight
    0b0000100};                 //  Digit Nine
    
  
int Temperature, TempDigit, DisplayPos, D1, j;
int ADCState;

int i, j, d, t, temp;
main()
{
	///////////  INIT  ////////////
	
	PORTA = 0;
	PORTC = 0;
	TRISA = 0b010000;      		//  All Bits of PORTA are Outputs except RA4
   TRISC = 0;           		//  All Bits of PORTC are Outputs
   
   CMCON0 = 7;                //  Turn off Comparators
   ANSEL = 1 << 4;            //  RA4 is ADC input
   ADCON0 = 0b00001101;			//  Left justify, Use Vdd, Channel 4 (AN3), Do not start, Turn on
   ADCON1 = 0b00010000;			//  run oscillatr as 8 x prescalar
   
   DisplayPos = 0;
   j = 0;
   Temperature = 0;
   ADCState = 0;

  
   ////  MAIN LOOP  ////
   
   while(1)
   {
	   ///////////  DISPLAY READOUT  ///////////
	   
	   DIGIT1 = OFF;
	   DIGIT2 = OFF;
	   DIGIT3 = OFF;
	   
		if(DisplayPos == 0)									//Light 1st segment
		{
			TempDigit = Temperature % 10;					//Just get "1"s place
			RA5 = LEDDigit[TempDigit] >> 6;				//Turn on digit
			PORTC = LEDDigit[TempDigit];
			DIGIT3 = ON;
			for(D1=0;D1<414;D1++);							//Delay for 7ms
			
		}else if(DisplayPos == 1)							//Light 2nd segment
		{
			TempDigit = Temperature % 100;				//Just get "10"s place (strip off "100"s place)
			TempDigit = TempDigit / 10;					//   and convert to "1"s place
			RA5 = LEDDigit[TempDigit] >> 6;				//Turn on digit
			PORTC = LEDDigit[TempDigit];
			DIGIT2 = ON;
			for(D1=0;D1<400;D1++);							//Delay for 7ms
		}else														//Light 3rd segment
		{	
			TempDigit = Temperature / 100;				//Just get "100"s place
			RA5 = LEDDigit[TempDigit] >> 6;				//Turn on digit
			PORTC = LEDDigit[TempDigit];
			DIGIT1 = ON;
			for(D1=0;D1<400;D1++);							//Delay for 7ms
		}

		DisplayPos = (DisplayPos + 1) % 3;				//Next segment
		
		
		j++;
		if(j == 50)												//Time to update temp?
		{
			j = 0;
		
			switch(ADCState)
			{
				case 0:						//Start ADC operation
					GODONE = 1;
					ADCState = 1;
					break;
				case 1:
					ADCState = 0;
					Temperature = ADRESH - 82;
					break;
			}
		}
	}
}
 

If you look at the file 'Pic.h' you will see that Hi-Tech includes eeprom read and write macros and functions in it's libraries.

The function prototypes for reading and writing eeprom are defined like so:
Code:
/* library function versions */
extern void eeprom_write(unsigned char addr, unsigned char value);
extern unsigned char eeprom_read(unsigned char addr);

You have already included <pic.h> so these functions are visible.
So to read and write eeprom, just use the library functions.
 

you can store ADRESH value, but here you are monitoring in every 7ms
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top