help me: temperature sensor lm35 with pic16f877 and code

Discussion in 'Embedded Systems and Microcontrollers' started by mohamedspider, May 31, 2012.

  1. mohamedspider

    Thread Starter New Member

    May 31, 2012
    2
    0
    hi everyone,,

    i want to ask for my project

    my project is fire alarm by using lm35 sensor and pic16f877

    that will send output from sensor to pic then to serial port

    and i will recieve it in visual basic 6 program

    i draw this circuit in " ISIS 7 Professional "

    i want anyone help me and tell me if this circuit correct or not

    and send the code that will put in pic by using "microc" and hex file

    http://www.mediafire.com/?is14xyu4sttuvy1
     
    • temp.jpg
      temp.jpg
      File size:
      167.9 KB
      Views:
      223
  2. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    I see that there are 2 things left out in your circuit. You didn't pull up /MCLR with a 10K resistor and 2x 22pF caps are needed on the both sides of the crystal or else it wouldn't start the osc reliably.

    If you want the software in the language you wanted, you can always do a google search and see if there is one that would fit your need. But hoping someone to write a customized program for you ? :eek:......... I am doubtful someone would do that kind of favour for you.:D

    Is a program written in Hi Tech C with sample schematics and hex code OK with you? You may refer to this link if you want....

    http://www.cytron.com.my/viewProduct.php?pid=CQETLQMVCCEeEiwgJAkGB7jFpdiP0exH82At4sXol8s=&store=

    All the files are downloadable from the useful doc section. You may use it as a reference for your design....

    Allen
     
    Last edited: May 31, 2012
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Additionally while a PIC can output RS-232 data it does not do so at RS-232 levels. There are chips available to do such.

    A further error is expecting others to write your code for you.
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    That will work in the Proteus simulator. You can connect like this. In this way you can have a virtual microcontroller. That interface with a onboard serial port on your host computer. The latter data can be read by any other serial port. But of course as you say. This will not work in any real world setting.
    Why not also write the report while we are at it:p
     
  5. mohamedspider

    Thread Starter New Member

    May 31, 2012
    2
    0
    thank you so much for your help

    i know it wrong to ask write code to my project but this is first time to make project like this and i don't know any program language to write code for pic

    anyway

    this is my new schematic


    [​IMG]

    but i try run it on visual basic

    it gave me this result

    [​IMG]

    i don't know what's wrong in this code

    this code is writen in PICbasic pro compiler

    Code ( (Unknown Language)):
    1.  
    2. DEVICE 16F877
    3. DECLARE  XTAL 4
    4. DECLARE ADIN_RES 10
    5. DECLARE ADIN_TAD 8_FOSC
    6. DECLARE ADIN_STIME 50
    7. Dim TEMP As WORD
    8. TRISA = %00000001
    9. TRISC 0.6 = 0
    10. ADCON1 = %10000000
    11.        TEMP = 0
    12.                 TEMP = ADIN 0
    13.                 TEMP = (TEMP / 2)
    14.                 SEROUT PORTC.6,16780, [ DEC TEMP,13]
    15.  
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Your new schematic did not attach, nor did anything appear under where you say "it gave me this result" but I assume it did not work.

    I don't use PICbasic anymore so I don't have a reference to completely check your code to check how you set up the voltage conversion, but generally what you are doing seems reasonable. (That means the error may be subtle and hard to spot.)

    You are doing two tasks here:

    1) read temperature voltage

    2) transmit temperature voltage via RS-232

    I would separate these two tasks to simplify things by for the moment by ignoring reading the voltage and just send a known number, say instead of

    Code ( (Unknown Language)):
    1. TEMP = ADIN 0
    Use this instead:

    Code ( (Unknown Language)):
    1. TEMP = 100
    Once you get "50" inside VB you can move on to reading the voltage.

    Next (and more importantly) you probably intend to read the temperature voltage continuously. To do that you should place the last 3 lines in a loop:

    Code ( (Unknown Language)):
    1.  
    2.     DO
    3.         TEMP = 100    ' was ADIN 0
    4.         TEMP = (TEMP / 2)
    5.         SEROUT PORTC.6,16780, [ DEC TEMP,13]
    6.     LOOP
    7.  
    (The code may be looping anyway after the processor runs out of memory to execute but this way is cleaner and proper.)
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    The terminal program used by the OP is clearly ASCII based. So would it not be better to write something like this


    Code ( (Unknown Language)):
    1. TEMP = 16706
    and then
    Code ( (Unknown Language)):
    1.  
    2.     DO
    3.         TEMP = 16706    ' was ADIN 0
    4.           SEROUT PORTC.6,16780, [ DEC TEMP,13]
    5.     LOOP
    6.  
    As a first test program. If everything OK then terminal program should show the letters "A" and "B" Until it do that something is wrong in the communication setup
     
Loading...