Variables change depending on a SEROUT2 command placement in code


+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    797

    Default Variables change depending on a SEROUT2 command placement in code

    Hi all,

    I've been spending a few hours now (this is an euphemism, of course ) on trying to find out why the program I'm currently working on has his variables "changing" values without any obvious reason.

    Let me explain.

    In this first image, the green field shows correct values and the red one, the wrong values. Amazingly, the program works (by chance...) but the reported values by the SEROUT command are wrong (in the "red" case).

    Name:  000545.png
Views: 104
Size:  7.2 KB



    These values change depending on the placement of a few lines of code as you can see herunder.

    Correct
    Name:  OK_000543.png
Views: 89
Size:  10.8 KB

    NOT Correct
    Name:  NO_000544.png
Views: 92
Size:  10.9 KB


    So, is there any scientific reason why my values change depending on the placement of the DEBUG (yellow frame) lines?

    The variables Now and Prev are declared as BYTE and have respectively values 15 and 255 at program startup.

    Thanks for any explanation that will stop me jump out of my window!!! Okay, I leave on the groundfloor...
    Roger

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    880

    Default Re: Variables change depending on a SEROUT2 command placement in code

    Your Key_Cnt variable increments inside the IF condition and therefore, placing the SEROUT statement before the IF works correctly.

    You need to investigate that IF statement with this in mind.

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    797

    Default Re: Variables change depending on a SEROUT2 command placement in code

    Thanks a lot Jerson
    Roger

Similar Threads

  1. Change variable allocation to save code space
    By aberco in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 5th September 2011, 01:28
  2. SERIN2, SEROUT2 with long variables
    By pedja089 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 18th November 2010, 23:22
  3. Serial code placement
    By nirvdrum in forum Serial
    Replies: 3
    Last Post: - 9th January 2007, 18:58
  4. Embedding Variables into Code Memory
    By JoeSolar in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th October 2006, 17:58
  5. oscillator code and placement within program
    By bartman in forum mel PIC BASIC
    Replies: 14
    Last Post: - 14th December 2004, 02:39

Posting Permissions

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