Menu

Why does this simple code give me errors

Help
Paul Haug
2017-03-04
2017-03-04
  • Paul Haug

    Paul Haug - 2017-03-04

    This code gives me errors, I have been trying to isolate but no avail.
    .

    #chip 16F88, 8
    #config Osc = Int
    #option explicit
    
    #define LED PORTB.0
    #define LoopCounter
    Dir LED Out
    
    For LoopCounter = 1 to 6
      PulseOut Led, 1 s
      Wait 1 s
    Next
    

    Here are the errors, what the heck, how can start values be to big with loopcounter starting at 0 ?????
    Line 11 is * For LoopCounter = 1 to 6* which is what the errors are refering to.

    1.2 Sec. <<< WARNINGs / ERRORs while compiling!
    Doubleclick on errormessage below to go to sourcecode-line:
    NextStepTest.gcb (11): Error: For start value is too big for the counter
    NextStepTest.gcb (11): Error: For end value is too big for the counter
    NextStepTest.gcb (11): Error: Missing operand, before +

     

    Last edit: Paul Haug 2017-03-04
  • William Roth

    William Roth - 2017-03-04

    Hi Paul,

    LoopCounter is a variable. So use DIM instead of define. Define makes it a constant that cannot change.

    #chip 16F88, 8
    #config Osc = Int
    #option explicit
    
    #define LED PORTB.0
    '// #define LoopCounter
    DIM LoopCounter as Byte 
    
    Dir LED Out
    
    For LoopCounter = 1 to 6
      PulseOut Led, 1 s
      Wait 1 s
    Next
    
     
  • Paul Haug

    Paul Haug - 2017-03-04

    Many thanks again William, old habits carry over from other basics need to be re-trained. I wil add this to my notes.
    The three errors msgs were a little strange, but now I understand why they said that.
    Paul

     

    Last edit: Paul Haug 2017-03-04
  • Paul Haug

    Paul Haug - 2017-03-04

    William, would it be a problem if I used Dim instead of Define for all variables, even unchanging variables, except of course Define for all iI/O should be Define ?
    Thanks my friend
    Paul

     

    Last edit: Paul Haug 2017-03-04
  • William Roth

    William Roth - 2017-03-04

    DIM will assign a memory location (Static RAM) . How much is assigned depends upon the varible type.

    Never use #define with a variable that needs to change.

    Define tells the compiler to replace one thing with another thing and uses no memory.

    For Example. #define ABC 16 will make ABC a constant with a value of 16. So is good when the value will never change.

    Another Example. #Define Led_On Set PortC.1 On

    If you then place Led_On in the basic source code, the compiler will replace Led_on with
    "Set PortC.1 On" at compile time and the equivalent of "Set PortC.1 on" will be put into the ASM code .This is a sneaky way to make a simple macro.

    Another example #define pulsout pulseout

    Now you do not have to worry about misspelling "pulseout" with the Picaxe version of pulsout (no "e")

     

    Last edit: William Roth 2017-03-04
    • Paul Haug

      Paul Haug - 2017-03-04

      Thanks, this is very helpful. I am also reading a lot of sample programs and help files (many of which you have posted) and beginning to undersdtand the "gotchas' in gcb. I am waiting to get my pickit3 so I can start debuging some programs as I expand and add to my main program.
      Paul

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.