Program works fine alone but not as part of a larger program.

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009

    Default Program works fine alone but not as part of a larger program.


    I'm making a display unit for my car using a serial LCD screen, some sensors and a 16F877a. So far I've figured out most of my problems using the search function but this has me baffled.

    I've built a circuit which creates a 5-1v output for 0-100% of fuel level sensor travel. I wrote code for it and it displays 1-99%. Good enough.

    So I copy the code and variables into the main program which has the rest of the code for the other parameters I'm showing like coolant temp, oil pressure and such. That program runs fine except for the fuel level part. It displays either 36 or 45 for a split second before display the correct number then writing 36 or 45 as the program cycles again. It does this each time the program cycles. I've removed the lookdown2 tables and set fuel2 and fuel4 to be 25 each so it should display just plain 50 but even then 36 or 45 still flash up.

    My question is what is causing this and how can I fix it?
    I've made sure #fuel isn't being sent out anywhere else in the program. I'll explain the code but you guys shouldn't need it. The code is below.

    It uses 2 lookdown2 function depending on where the fuel sender is. If one table's maxed out it, that's automatically set to the highest value in the lookdown2 table. It then adds the output of the two tables to and displays it.


    ADCIN 3, rawfuel
    if rawfuel > 511 then
    fuel1 = rawfuel/4
    fuel3 = 253
    fuel3 = rawfuel/2
    fuel1 = 129
    lookdown2 fuel1, >[254,252,249,246,243,241,238,235,_
    146,143,141,138,136,133,131,129], fuel2
    lookdown2 fuel3,>[253,248,243,239,234,230,225,221,_
    104,103,102,101,100,99], fuel4
    fuel= fuel2 + fuel4
    if fuel <100 then
        serout Portd.2, N9600, [017, 015, 003]
        serout Portd.2, N9600, [" "]
        serout Portd.2, N9600, [017, 015, 003]
    if fuel <10 then
        'serout Portd.2, N9600, [017, 015, 003]
        serout Portd.2, N9600, [" "]
    serout portd.2, N9600, [#fuel]
    goto fuellevel

  2. #2
    Join Date
    May 2009


    I got it figured out. Another part of the program was writing a value to the spot the fuel level was being sent to. Ugh, I feel stupid.

Similar Threads

  1. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  2. 7805 works fine, LM2940CT5 not!
    By DanPBP in forum Off Topic
    Replies: 4
    Last Post: - 29th August 2007, 23:01
  3. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 15:30
  4. ERROR Compling 16F819...l but the 16F818 works fine
    By 4Lewis in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st April 2006, 07:47

Posting Permissions

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