16F877a - Please Help


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007
    Posts
    2

    Default 16F877a - Please Help

    Hi~ this is my first time using a microcontroller, let alone programming. Somehow, I ended up being the programmer for a group project, and I desperately need some help. I am programming a pic16f877a with PicBasic Pro with an input coming from a digital temperature sensor (tmp121) and an output to a transmitter (txm-433-lr). If the temperature coming in from the sensor is greater than 85 degrees farenheit, I want an pulse signal to be sent out to make a car honk and '1' to be sent to an alarm device via the transmitter. I've spent a long time looking over other examples and tried to piece things together the best I could, but I'm afraid that I am utterly horrible at this.

    Thanks in advance to anybody that helps! Here is the code I have so far:

    ' read tmp121 1-wire temp sensor
    ' if temp > 85 degrees farenheit, send signal to transmitter

    DEFINE LOADER_USED 1
    DEFINE OSC 20

    temp VAR WORD 'storage for temp
    ftemp VAR WORD ' holds converted temp
    samples VAR WORD ' hold number of samples

    TRISD = %00000000 ' output portd
    TRISC = %00000000 ' output portc

    car_honk var PORTD.6 ' pin 29 to start car honk
    panic_alarm var PORTD.7 ' pin 30
    transmit_datain var PORTC.6 ' pin 25 to transmitter

    ADCON1 = 7 ' set PORTA to digital
    PAUSE 500 ' wait .5 seconds

    loop:
    FOR sample = 1 TO 20 ' take 20 samples
    SERIN PORTA.0 temp ' here I don't know how to read in the digital temperature from the sensor
    samples = samples + temp
    PAUSE 500 ' wait about .5 sec per loop
    NEXT sample
    temp = samples/20 ' take average
    ftemp = (180/100 * temp) + 32 ' convert to farenheit

    IF ftemp > 85 THEN set_alarm

    samples = 0 ' clear sample accumulator

    GOTO loop ' do it forever

    set_alarm:
    PULSOUT car_honk, 500000 ' send pulse 1 sec long
    HIGH panic_alarm
    HIGH transmit_datain
    PAUSE 10000 ' can I use PAUSE to make the set_alarm last for 10 seconds?
    RETURN

    END

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Need to have - include "modedefs.bas" - near the start of the program for serial to work.

    Get rid of Sample after NEXT.

    IF ftemp > 85 THEN set_alarm change to
    IF ftemp > 85 THEN GOSUB set_alarm (look in the manual)

    Look in the manual for how SERIN works.

    Take things piece by piece. Try reading the temperature to hyper-terminal first to make sure that is working, the add more functions after that.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. 16F877 vs. 16F877A
    By DavyJones in forum General
    Replies: 12
    Last Post: - 11th April 2009, 18:22
  2. help my bluetooth and PIC 16F877A?
    By slimpeng in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th March 2008, 06:52
  3. Read the newbee threads, 16F877A no go.
    By BobbyA in forum mel PIC BASIC Pro
    Replies: 39
    Last Post: - 31st December 2006, 03:09
  4. Clock connection to DS1802 from 16F877A
    By coyotegd in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd January 2006, 18:52
  5. 1st 16F877A program in PICBasic
    By Borisw37 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th January 2005, 04:46

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts