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


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009
    Posts
    4

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

    Hi,

    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.

    Thanks.

    Code:
    FUELlevel: 
    ADCIN 3, rawfuel
    if rawfuel > 511 then
    fuel1 = rawfuel/4
    fuel3 = 253
    else
    fuel3 = rawfuel/2
    fuel1 = 129
    endif
    lookdown2 fuel1, >[254,252,249,246,243,241,238,235,_
    232,230,227,224,221,219,216,213,_
    210,207,205,202,199,196,194,191,_
    188,186,183,180,177,175,172,169,_
    167,164,161,159,156,154,151,148,_
    146,143,141,138,136,133,131,129], fuel2
    
    lookdown2 fuel3,>[253,248,243,239,234,230,225,221,_
    216,212,208,204,199,195,191,187,_
    184,180,176,172,169,165,162,158,_
    155,152,149,146,143,143,140,137,_
    134,132,129,127,124,122,120,118,_
    116,114,112,111,109,108,106,105,_
    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, [" "]
    else
        serout Portd.2, N9600, [017, 015, 003]
    endif
    if fuel <10 then
        'serout Portd.2, N9600, [017, 015, 003]
        serout Portd.2, N9600, [" "]
    endif
    
    serout portd.2, N9600, [#fuel]
    goto fuellevel

  2. #2
    Join Date
    May 2009
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    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, 08:26
  2. 7805 works fine, LM2940CT5 not!
    By DanPBP in forum Off Topic
    Replies: 4
    Last Post: - 29th August 2007, 22:01
  3. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14: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, 06:47

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