Problems with variables


Closed Thread
Results 1 to 3 of 3
  1. #1
    egberttheone's Avatar
    egberttheone Guest

    Unhappy Problems with variables

    I'm experiencing problems if I define lots of variables; it looks like they override each other.

    example:

    A var byte
    B var byte

    A = 1

    then the value of A = 1 but B gets 1 to how is this possible? do I have to give all of my variables a memory location my self?

    here are al my variables:

    Code:
    LightButton1 VAR PORTB.7
    LightButton2 VAR PORTB.6
    LightButton3 VAR PORTB.5
    LightButton4 VAR PORTB.4
    LightButton5 VAR PORTA.5
    LightButton6 VAR PORTB.2
    LightButton7 VAR PORTB.1
    LightButton8 VAR PORTB.0
    
    MenuButton VAR PORTC.0
    BackButton VAR PORTC.1
    
    RotaryL VAR PORTC.2
    RotaryR VAR PORTC.3
    
    Relay1 VAR PORTC.4
    Relay2 VAR PORTC.5
    Relay3 VAR PORTC.6
    'Relay3 VAR PORTC.5 ' temporarly for debugging
    Relay4 VAR PORTD.6
    Relay5 VAR PORTD.0
    Relay6 VAR PORTD.1
    Relay7 VAR PORTD.2
    Relay8 VAR PORTD.3
    Relay9 VAR PORTD.4 'Heater
    Relay10 VAR PORTD.5 'Co2 pump
    Relay11 VAR PORTD.7 'Co2 refresh
    
    'SET I or O
    
    Input LightButton1
    Input LightButton2
    Input LightButton3
    Input LightButton4
    Input LightButton5
    Input LightButton6
    Input LightButton7
    Input LightButton8
    Input MenuButton
    Input BackButton
    Input RotaryR
    Input RotaryL
    
    Output Relay1
    Output Relay2
    Output Relay3
    Output Relay4
    Output Relay5
    Output Relay6
    Output Relay7
    Output Relay8
    Output Relay9
    Output Relay10
    Output Relay11
    
    'DCFSignal needs to be connected to the hardware serialport (portc.7)
    
    DQ VAR PORTE.0 ' Alias DS1820 data pin
    DQ_DIR VAR TRISE.0 ' Alias DS1820 data direction pin
    Temp2 VAR WORD
    TempSensor VAR BIT ' if 0 then no sensor where found.
    
    
    'Variables
    
    'Byte0 define's repeat or not 1 = repeat
    'Byte1 define's the maximum
    'Byte2 define's the minimum
    'Byte3 is the variable byte
    'Byte4 return 1 if it was rotated
    RotarySetting VAR BYTE[4] bank0
    
    
    'all bytes after each other, byte 0 to 2 are the start 
    'timings BYTE 3 to 5 are Stop timings and byte 6 is the mode
    ' mode 2 = start/stop @time
    ' mode 1 = aan
    ' mode 0 = uit
    LightSetting VAR BYTE[56]
    
    
    'byte 1 to 3 is the last date un witch it has refreshed
    ' if byte4 = 0 then do never refresh
    ' if byte4 = 1 then weekly refresh
    ' if byte4 = 2 then monthly refresh
    ' if byte4 = 3 then yearly refresh
    Co2RefreshSettings VAR BYTE[4]
    
    
    'byte 0 to 2 are the date and byte 13 to 15 are the time bytes on witch it has to stop. 
    ' byte3 = Duration
    ' byte4 = Repeat
    ' if byte4 = 0 then pump evry halfhour
    ' if byte4 = 1 then pump evry hour
    ' if byte4 = 2 then every 12 hours
    ' if byte4 = 3 then every day
    ' if byte5 = duration time in minutes
    'byte6 = the state, 0 = off, 1 = on, 2 = interval 
    'byte7 to 12 is the next time that it has to run
    Co2PumpSettings VAR BYTE[16]
    
    
    'Byte1 = the temprature, byte2 = halfdecimals, byte3 = heaterstate 0 = do not heat 1 = heat 
    HeaterSettings VAR BYTE[4]
    HeaterState VAR WORD[3] 'Byte1 = currend temp, byte2 = currendtemp half decimals, byte3 = state 1 = heating 2 = off
    
    TimeDate VAR BYTE[7]
    I VAR BYTE
    A VAR BYTE
    B VAR BYTE
    Temp VAR BYTE
    MenuSubMode VAR BYTE
    Dender VAR BYTE[4]
    DCFSignal VAR BIT
    
    TempTime VAR BYTE[7]
    MonthDays VAR BYTE[13]
    
    'define maximum nummer of days is the month
    
    MonthDays(1) = 31
    MonthDays(2) = 29
    MonthDays(3) = 31
    MonthDays(4) = 30
    MonthDays(5) = 31
    MonthDays(6) = 30
    MonthDays(7) = 31
    MonthDays(8) = 31
    MonthDays(9) = 30
    MonthDays(10) = 31
    MonthDays(11) = 30
    MonthDays(12) = 31
    
    ' if 0 then status screen (main) is showed
    ' if 1 then mainmenu is showed
    ' if 2 then lightmenu1 is showed
    ' if 3 then lightmenu2 is showed
    ' if 4 then lightmenu3 is showed
    ' if 5 then lightmenu4 is showed
    ' if 6 then lightmenu5 is showed
    ' if 7 then lightmenu6 is showed
    ' if 8 then lightmenu7 is showed
    ' if 9 then lightmenu8 is showed
    
    Mode VAR BYTE
    Flash VAR BYTE
    Flash2 VAR BYTE
    CFlash VAR BYTE
    ArrowPlace VAR BYTE bank0
    
    Command VAR BYTE ' Storage for command

  2. #2
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Make sure you access the arrays correctly. If you define an array of let's say 4 elements ....

    MyArray VAR BYTE[4]

    .... you should access the elements 0 through 3. MyArray[4] will access the next byte in memory wich most likley will be another variable. The compiler will NOT warn you about this, you'll have to make sure yourself.

    /Ingvar

  3. #3
    egberttheone's Avatar
    egberttheone Guest


    Did you find this post helpful? Yes | No

    Default

    ahhh nice, i will check it out. THX!

Similar Threads

  1. variable problems
    By DmitriK in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 5th June 2008, 21:19
  2. proton problems
    By shantanu in forum Off Topic
    Replies: 1
    Last Post: - 10th February 2007, 12:39
  3. Variables not appearing in Watch Window MPLabv7.3
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th June 2006, 14:36
  4. How to tell which PICs can handle 16 bit variables?
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st August 2005, 08:44
  5. implementig digital filter and my problems????????
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd June 2004, 18:06

Members who have read this thread : 1

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