Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
:
:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine.

Back 12F675 Tutorial Index Next

12F675 Tutorial 5 : A Temperature  data logger using PIC EEPROM.

EEPROM is useful for storing long term data such as data logger information and this PIC microcontroller EEPROM project saves the temperature from an LM35DZ IC to the PIC's internal long term data storage area.  The project follows on from the last project using the virtually the same hardware.

It stores temperature readings internally at regular intervals until full and after this it turns on the LED. The LED is really just for showing that something is happening and in a real data logger you would not use it.

Jump to Solderless breadboard.
Jump to Circuit Diagram.
Jump to Software.

Note: This project is not optimized for power consumption so the best way to use it is powered from a power block.  The current consumed is about 13mA (LED off) 16mA (LED on at end). If you want to use a battery use a rechargeable PP3 and do not attach the LED.

The 12F675 may not the best PIC microcontroller to use for low power data logging and a better choice would be the 16F88 as it can change its internal oscillator on the fly going into slow (current saving) mode.  But you could use the 12F675 with a slow external 32kHz crystal. 

At every ADC reading the LED is flashed briefly and when you select a 500ms reading interval you can see the readings being taken.  When 64 readings are accumulated the LED is lit permanently - showing that the data store is full. 


Note: For this chip you only get to store 64 results as you need to store an unsigned integer for every ADC result and this takes 2 bytes so 128 Bytes/2  = 64 results.

You can hit the button at any time and the contents of the EEPROM will be read from the internal EEPROM and transmitted to the PC via the serial port.

To erase the internal EEPROM hold the button and cycle the power - this flashes the led 6 times indicating erase (normal startup flashes the LED 3 times).

Solderless breadboard

The solderless breadboard and circuit diagram are nearly the same as used in the previous project so if you have already built it you don't need to do any more.  Just add the blue wire, D2 and R6.

eeprom temperature recorder plugblock

Learn about the tool used for creating this diagram.

Circuit diagram

Note that the switch shown below is just a blue wire above. Either leave the  blue wire where it is to hold the input, at pin 4, high or move the top of the blue wire to ground (0V - green wires at top left - on the left of the solderless breadboard) to set GP3 (pin 4) low.

Note: The diode stops the programming voltage conflicting with the 5V power supply - reversed biased when the high programming voltage is present.

Setting GP3 low causes a reading update rate of half a second (for debug) while setting it high causes a reading update rate of approximately 30 minutes.  So for the full 64 readings you get temperatures measured and stored every half hour over a 32 hour period.

Note: The measurement time is not calibrated so it won't be exactly 30 minutes.

Note: The circuit/software is not optimized for power usage so you should use a power block to give the circuit power otherwise a battery would be drained fairly quickly.

eeprom temperature recorder

Learn about the tool used for creating this diagram.

12F675 pinouts

 
12F675 pin out
Other views:

PIC12F675 PIC microcontroller micro controller PIC 12F675 micro controller

Software

Again the Soft USART (transmit only) described in Tutorial 3 is used and internal MikroC routines are used to get data from analogue input (AN0) and for reading from and writing to the internal EEPROM. 

Source code files :
To get the file software project files and c source code click here.

PIC Microcontroller Software operation

At start up the led is flashed three times. If you hold the button at start up the LED is flashed six times and the internal EEPROM will be erased ready to start logging the temperature again.

As mentioned before setting GP3 high causes the measurement interval to be approximately 30 minutes whereas holding it low causes a half second measurement interval (for debug).  

Note the diode D2 is to stop programming voltage conflict during development.  If you just program the 12F785 and then put it permanently in a separate circuit with no ICSP connection then D2 and R6 are not required - so you could connect pin 4 to 5V for half hour readings.

Once the internal EEPROM is full up no more readings are taken and the LED is turned on permanently.

Pressing the key at any point transmits the EEPROM data to the serial port for display/use on the PC.

Software routines

The software used to gather the temperature reading is the same as the software in tutorial 4 except averaging is done in a separate function :

get_reading()

The software continuously gathers temperature readings and as before it transmits the result to the serial port (this time as a centigrade reading) and it also stores the reading in the EEPROM. It can gather a maximum of 64 readings (half the size of the internal EEPROM). After this it stops recording and even if the power is lost the readings will remain stored in the EEPROM.

For debug the led is flashed briefly to show a data capture.

The following sub routines are defined and their function is obvious:

get_key()
printval()
erase()
eeTemp_write()
eeTemp_read()
get_reading()
flash_led_3times()
report()
finished()


Note: Vdelay_ms is used throughout and although it is less accurate it saves space (this is a 'variable' based delay routine as compared to delay_ms which generates code for each instance more accurate but more code!).

The rest of the action happens in main() in an infinite loop.  It gets a reading,
sends it to the serial port and then stores it in EEPROM.  It then flashes the LED briefly checks the key state, then checks to see if all data is gathered and then waits for a delay (the length is determined by the state of GP3 - pin 4) either 30 minutes or 0.5 seconds.


Back 12F675 Tutorial Index Next

New! Comments

Have your say about what you just read! Leave me a comment in the box below.



Claim Your: Useful

"Arduino Software Guide"

   Right Now...



Jump from 12F675 Tutorial 5 : Using PIC's EEPROM to
Best-Microcontroller-Projects Home Page


Privacy Policy | Contact | About Me

Site Map | Terms of Use




Visit our Facebook Page:

   Click Here



Sign up for MicroZine
''The'' Microcontroller Newsletter

Enter your first Name and primary email address in the form below:


And receive absolutely FREE a full project for:

"Measuring Analogue Voltages
Without An ADC"

(Using only one pin).

Instant Download:
You Can
Get It Right Now

Warning: This project could be  Removed 
at any time.  

It will  NOT be 
available indefinitely SO
To avoid 
disappointment  get it:

Now



:
:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.

To get exclusive access Enter your first name Name and primary email address Now in the form above.:



But wait !

There's more...

You'll receive more
free and exclusive reports as well as site information and site product updates


Scroll up to the form above and sign up NOW. Don't forget it's FREE and if you don't like it, you can unsubscribe at any time.

Click Here Now to use the form above to get your Valuable information absolutely free.



Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."

- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com<

"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


Learn Microcontrollers

"Interested in
Microcontrollers?"

Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon

Recent Articles

  1. How to use the DHT22 (or DHT11) with an Arduino; full code and description. Also including a comparison of the DHT11 vs DHT22.

    The Essential Guide to the DHT22/11 humidity sensor including a library code guide for the Arduino. Learn how to determine Humidity, Dew point and Heat Index.

    Read more

  2. How to Use the MAX7219 to drive an 8x8 LED display Matrix on the Arduino.

    The Essential Guide to the MAX7219; What it is and how you can easily use one in any of your projects.

    Read more

  3. How to use a DS18B20 (single or multiple on one wire) for temperature measurement using the Arduino Uno.

    How to Easily Use the DS18B20 Maxim One-Wire thermometer with Arduino example code showing external or parasitic power modes.

    Read more