Documentos de Académico
Documentos de Profesional
Documentos de Cultura
• Home
• Forum
• Shop
• About
• Contact
• Price List for Electronic Components – Karachi
Creative Electron
read . discuss . shop
• Home
• Articles
• AVR
• Basic Electronics
• Photography
• PIC
• Projects
• Technology
• Tools
• XBee
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Electron Page 2 of 16
Temperature measurement
and sensor cables- thermocouple,rtd extension
compensation types
www.yapitaskablo.com
• Simulate PIC in Proteus along with Digital Output to toggle LED using PIC16F84
• Interface 16×2 Character LCD with PIC16F876
• Interface 128×64 Pixels Graphical LCD (KS0108) using PIC16F876 after brief introduction
to Graphical LCD.
Today in this post we learn the following new stuff while developing the project mentioned in
title;
Objective
Our objective in this post to create such a system which measures ambient temperature and sends
it to PC using Serial Port. To fulfill this we need the following major components ;
Generally PIC Microcontrollers offer 10 Bit of Analog to Digital Conversion. This means that
when they measure an incoming voltage, they compare that voltage to a reference voltage, and
give you the comparison represented as a 10-bit number (0-1023).
You can wire as many analog inputs to the PIC as there are analog ports to accept them. However,
you will notice some strange effects when you do so. The ADC circuits will affect each others’
readings, because all the circuits are pulling off the same +5V source. One thing you can do to
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Electron Page 3 of 16
minimize this is by using decoupling capacitors by each analog input, to smooth out dips and
surges in the current caused by the other ADC’s. Typically 0.1µF to 1µF will do the job. Place the
capacitors between power and ground, as physically close to the ADC input as you can get.
It also helps if you increase the sampling time and the delay between conversion and reading
commands. Too much delay and you sacrifice interactivity; too little delay and you get random
numbers. Start with the numbers in the sample code above, and vary them until you get readings
you’re happy with.
Finally, it helps to sample at a lower resolution. Sampling at 8 bits instead of 10 will improve the
speed and stability of a multiple ADC program.
Since the ADC registers provide you with 10 bit number converted from the analog input, you can
use the following formula to have input voltage;
LM35 is an integrated circuit sensor that can be used to measure temperature with an electrical
output proportional to the temperature in cenitgrade. The main reason behind using LM35 is that it
doesn’t need amplification like thermocouples. The conversion ratio of LM35 is 10mV/’C . For
e.g at temperature of 35 degrees LM35 will output 350 mV.
MAX232 is used for level translation between TTL and RS232. It is very common and integral
component while communication between Microcontrollers and PC using RS232. The USART of
PIC works on0-5V levels while RS232 works over -15 to +15 level. The MAX232 acts as a bridge
between these two standards.
Project
By combining the above three major components along with the power of CCS C Compiler we
achieve our objectives.
Hardware
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Electron Page 4 of 16
Software
Following are the steps from the software we will design for the project;
Steps 4 to 6 will be performed under an infinite loop. But a delay will be added explained later.
#DEVICE ADC=10
The above statement is used to define the resolution of ADC in bits. The maximum resolution for
PIC16F876 is 10-Bit. But you can define it to any number less than the maximum resolution.
The following line is used to initialize and configure USART to start communication.
This line is used just after the oscillator clock declaration.Usually you have to give it Baudrate and
the pins used for communication. If you want to use the builtin hardware USART then you use the
above declared pins. But if you like more than one serial communication ports, you can declare
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Electron Page 5 of 16
communication on any pins. But note that using pins other than C6 and C7 will involve software
serial data handling. And it can compromise speed as compared to hardware USART.
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
These three lines setup the ADC and initializes it. setup_adc_ports is used to define which pins
are to be used as analog inputs. Most suitable is ALL_ANALOG as it makes all AN pins as analog.
The next statement defines the clock source for ADC. As PIC also has external clock feature for
ADC conversion. The best is internal clock.
To select the pin from which to read the analog voltages we use set_adc_channel . In our case
LM35 is connected to Pin AN0, so we select Channel 0.
value = read_adc();
The function read_adc() is used to read the value from ADC Register. It contains the digital
equivalent value of analog input.
For e.g. if we input 2.5 volts and the resolution defined for ADC is 10-Bit, we will get a value of
512 from read_adc().
As we know that we get a digital value equivalent to in out analog voltage. So first we convert it
into voltage value;
Please note that by default the reference voltage for ADC in PIC is 5V.
For e.g if we get a value of 512 from ADC of 10-Bit resolution, the formula will have following
values ;
Invalid Application ID
We have got the voltage value which is coming from ADC, now we convert it into Temperature
with help of formula provided by LM35;
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Electron Page 6 of 16
If voltage of 0.375 are read from ADC, the above formula will return Temperature of 37.5°C.
Read and conversion of voltages into digital and then temperature is done. In next we will send the
data to PC using very simple command.
The very reason of popularity of CCS C Compiler is its ease of use and powerful commands.
Specially dealing with serial communication is very easy in this compiler. To send data to PC all
you need to do is to use the following one line function;
printf(“Temperature: %.1f\n\r”,temp);
If you have used TurboC you maybe very well familiarized with printf. This function is the same
olf function but the only difference is that when used in TurboC it displays on Monitor and when
used in PIC it sends data over to serial port.
Temperature: 37.5
#include <16F876.h>
#DEVICE ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232 (baud=57600,rcv=PIN_C7, xmit=PIN_C6)
float value;
float temp;
float volt;
void main()
{
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
while(1)
{
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Electron Page 7 of 16
//Send data to PC
printf(“Temperature: %.1f\n\r”,temp);
You can use Hyper Terminal which comes with Windows XP. Or you can use many other serial
port monitors easily available for download.
Following is the screenshot of Hyper Terminal being sent the temperature data;
In our next post we will learn how to make temperature readings more accurate by using filters
and different techniques. Also we will learn how to recieve the serial data in Visual Basic 6 for
further programming and GUI.
Happy InterfacING =)
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Electron Page 8 of 16
Related Posts
PROTEUS: How to interface XBEE/GSM Modem or any Serial port device with Proteus.
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Electron Page 9 of 16
28 Comments
Add Comment
Post as …
Showing 28 comments
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Elect... Page 10 of 16
That's a good idea, why don't you try it. Use http://creativeelectron.net/?p... for reference.
Like Reply
Like Reply
Like Reply
Like Reply
Like Reply
MAX232 enhances voltage by charging and connecting capacitors in series.All is done internally by its logic controller and
voltage comparator. There polarity for series connection determines the polarity of output voltage that is TX.
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Elect... Page 11 of 16
Like Reply
hmmmm....
does that mean that Vs+ is to be connected to Vcc ??? and Vs- is to be connected to the common gnd ??? or are these
two to be connected to a separate connector for communication purpose????
Like Reply
Like Reply
no after connecting them with capacitor then what....What abt that power and gnd which r connected with
these two pins...
Like Reply
What do you mean by "then what" and "what about" ? Sorry can't understand you.
Like Reply
Like Reply
Got it..Thanxx..
Like Reply
VS are not the supply voltages, they are actually the capacitor voltages used for converting 0 volts to 9 volts and 5 volts to -9
volts.
Vs + is for positive voltages for communication while Vs - is for negative. As you can see in VS- the capacitor is connected
in inverse polarity, to have negative voltages from it.
Like Reply
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Elect... Page 12 of 16
Really interesting.....
Like Reply
As far as my knowledge is concerned it is neither polling nor interrupt. Because printf() sends the data, it doesn't receive.
Polling and interrupts come into action when you are expecting input from any port.
Polling means reading data continuously until and unless you get one. In interrupts, you get an ISR called whenever the data
is received.
Well there are also interrupts for receiving serial data. Will cover them in next post.
Like Reply
Hamza Nice post... Just one thing is unclear that is how to send the same data to LCD. You have posted LCD related thing earlier
but it's still confusing about the LCD connections to the controller pins. Which pins of controller are for LCD?
Like Reply
Thanks .
in few days I will add the LCD in this post too. As far as pins are concerned you cal only use the pins which are declared in
the header file. You can also change the pins but it is not advisable.
All you need to do is to add 330Ohms Pull-Down resistors on Data and CS Pins.
Like Reply
Like Reply
By CS Pins I mean Control Signal Pins which are RS, RW and E Pins.
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Elect... Page 13 of 16
Like Reply
ok..
And whats with ADCON0, ADCON1 registers and ADRESH, ADRESL...
Do we need to incorporate these in some way...
Like Reply
No you really don't need to worry about registers. Thats the beauty of CCS C Compiler that it has
very easily understandable functions which take care of registers.
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
Like Reply
Pretty interesting....
i'll fidgit with my written code and try to display it on an lcd..
if i cant in a day or two then i'll post it here...
Regards..
Like Reply
Like Reply
Use only "\r" (return character). "\n" will take you to the next line which you
don't need in LCD until and unless you want to display on new line.
Like Reply
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Elect... Page 14 of 16
Like Reply
This works great on LCD as well, but only for positive values. I tried
simulating this on Proteus and it showed 0 on the LCD when I tried
negative temperatures. Am I doing something wrong?
Like Reply
Like Reply
Categories
• Articles (11 posts)
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Elect... Page 15 of 16
Comments
• creativeelectron on GLCD: Interfacing 128x64 Pixel GLCD (KS0108) with
PIC16F876 :
Tell me the exact model number of the GLCD...
• Allanrocks05 on GLCD: Interfacing 128x64 Pixel GLCD (KS0108) with PIC16F876 :
if i use a 240x128 glcd. can i still interface it?...
• Ironhide87 on GLCD: Interfacing 128x64 Pixel GLCD (KS0108) with PIC16F876 :
Our resolution is 480x234...
• creativeelectron on GLCD: Interfacing 128x64 Pixel GLCD (KS0108) with
PIC16F876 :
While interfacing the GLCD we do not consider the physical s...
• Ironhide87 on GLCD: Interfacing 128x64 Pixel GLCD (KS0108) with PIC16F876 :
We plan to interface the PIC18F4520 with a larger size Graph...
• creativeelectron on GLCD: Interfacing 128x64 Pixel GLCD (KS0108) with
PIC16F876 :
Yes you can interface it with any PIC Microcontroller....
• Ironhide87 on GLCD: Interfacing 128x64 Pixel GLCD (KS0108) with PIC16F876 :
Can we interface it with PIC18F4520 instead?pls reply be...
• Saad Dawra on ARDU: Physical Computing with Arduino - An Introduction :
The comments system seems buggy, I got an email yesterday sa...
• Saad Dawra on ARDU: Physical Computing with Arduino - An Introduction :
Hey thanks for the reply Asad I did get the atmega168 them t...
• umair on About :
Gr8 yar...Really our nation has a great pool of talent.....
Recent Posts
• ARDU: Physical Computing with Arduino – An Introduction
• AVR: How to use serial port in ATMEGA88
• CEShop: MiniGPS and 12V Battery added.
• CEShop: List of items which will be in-stock in Phase-I
• Electronics: How to interpret semiconductor devices model numbers.
• PROTEUS: How to interface XBEE/GSM Modem or any Serial port device with Proteus.
• Photog
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011
PIC: PC Interfaced Digital Thermometer using PIC Microcontroller | Creative Elect... Page 16 of 16
http://creativeelectron.net/blog/2009/10/pic-pc-interfaced-digital-thermometer-using-p... 18/01/2011