Stumped with word variable


Closed Thread
Results 1 to 31 of 31
  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Stumped with word variable

    Hi guys,

    I have four variables in my code that are words as I need to store numbers between 0 and 1439. That part is fairly straight forward and I can manually enter "White_on_Time =840" and "White_off_Time = 1230" etc However I want to use some pre-sets in my code via the data statement. This works fine with byte variables but I can't for the life of me get correct value into the variable via the data / read statements.

    I've tried "data word" and then the values but that fails, so consulting the manual I tried the READ (variable).byte
    Code:
    read 10,Blue_on_Time.0
    read 11,Blue_on_Time.1
    But that didn't work either.

    The strange thing is I have a menu option to set these values thus
    Code:
    Lcdout $FE,2
    LCDOUT $FE,$80,"Set On Time For "
        IF H_butt = 0 THEN GOSUB delHours
        IF M_butt = 0 THEN GOSUB delMinutes
        lightsetHR[fn]=Hours
        lightsetMN[fn]=Minutes
        if viv >=2 then viv =2
        if viv= 1 then LCDOUT $FE,$C0,"Blue Leds "
        if viv= 2 then LCDOUT $FE,$C0,"white Leds "   
        lcdout $FE,$94,#lightsetHR[fn] DIG 1,#lightsetHR[fn] DIG 0,":",#lightsetMN[fn] DIG 1,#lightsetMN[fn] DIG 0
        Blue_on_Time = (lightsetHR[0]*60)+lightsetMN[0]
        White_on_Time = (lightsetHR[1]*60)+lightsetMN[1]
    /snip
    If I left the read / write as normal (ie without the 1st byte / 2nd byte modifier) and set the time to 14:00 hrs (ie (14*60)+0 = 840)via the menu option it works. I have a test line on the LCD which shows the dec value for blue_on_time is 840.

    Any pointers as to what I'm doing wrong ?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    read 10,Blue_on_Time.0 is bit 0 not the low byte
    read 11,Blue_on_Time.1 is bit 1 not the high byte
    you want
    read 10,Blue_on_Time.lowbyte
    read 11,Blue_on_Time.highbyte

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Cheers Richard, will give that a go.

    Guess I need to use the same method to write the value to memory ie write 10,blue_on_time.lowbyte and write 11,blue_on_time.highbyte

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    yes its hard to remember wether the data statement saves words as highbyte first or not
    and then does the write word do the same ?, to read them back properly you must get it right.
    but write 1 ,word wordvar and read 1, wordvar is the way to go if you can't be bothered understanding what happens

    data @1 ,1,2 ; (wordvar.highbyte),( wordvar.lowbyte) $0102 =258 the question is ,is data @1,word 258 is it the same thing try it and see

    the easy way out if your not sure about data is to :-
    write 1, wordvar.highbyte, wordvar.lowbyte
    read 1 , wordvar.highbyte,wordvar.lowbyte
    its less efficient but it leaves no doubt.
    you could always read the manual or just experiment to find out , the trick is though to be able to remember it
    for next time

  5. #5
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Quote Originally Posted by richard View Post
    you could always read the manual
    I had referred to the manual, but just didn't comprehend how this worked...

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Uhmmm.

    Just tried
    write 10,Blue_on_Time.highbyte

    and on compiling it complains of illegal character, with a code [108].

    I've gone through the code and it compiles fine if I remove the .highbyte .... confused !!

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Hi,
    I copy/pasted the above line into a blank program, added Blue_On_Time VAR WORD to the top and it compiled just fine for a 16F628.
    Code:
    Blue_On_Time VAR WORD
    
    write 10,Blue_on_Time.highbyte
    
    END
    Try removing the complete line, then re-enter it or copy/paste it from your own post. Perhaps there's some strange hidden character or something lurking. Like I said, compiles just fine here.

    /Henrik.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    I just tried it for a 12f683 and it won't compile for me,i sure I have been successful for other chips or else I could just be going mad
    jumping between pic's and arduino's
    are you using pbp3 ?
    maybe just use write 10 ,word Blue_on_Time and read 10 ,word Blue_on_Time

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    That's strange. Tried it again, compiled for a 12F683 and it worked, exactly as the same code as before. I'm on PBP3, don't know about Scampy.

    /Henrik,

  10. #10
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Thanks guys for the additional input. I'm running 2.60 and MPLAB 8.87 which has never been a problem.

    I've come across a previous bit of code that used the highbyte / lowbyte and that compiled fine so it must be to do with something in that statement. I'll try changing the variables (removing the underscore) and see if that has any affect, but as the example code I found also used underscores than I can't see that being the issue.

    Malcolm

  11. #11
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Confused !

    I loaded a version of the code that contained hard coded values for the light on times. EG 14:00 is 840 minutes after midnight. I commented out the hard coded values and enterd the data statements etc so this is what I had

    Code:
    Blue_on_Time var word            'stores the blue on time as a digit in minutes, eg 14:00hrs = 840
    I then added the data statement
    Code:
    data @0
        data    00      'Blue fade IN duration hours
        data    30       'Blue fade IN duration minutes
        data    00      'Blues fade OUT duration hours
        data    30       'Blue fade OUT duration minutes
        data    00       'Whites fade IN duration hours
        data    30      'Whites Fade IN duration MINS
        data    00       'Whites Fade OUT duration HOURS
        data    30       'Whites Fade OUT duration MINS
        data    255       'Blue MAX Intensity %
        data    255      'Whites MAX Intensity %
        data    840
    I then added the read statement

    Code:
    read 10,Blue_on_time
    I then added the line so I could see what values for Blue on time I was getting
    Code:
    lcdout $FE,$D4+11,dec Blue_on_Time
    When that was complied and loaded, the program gave a value of 74 when first run, and obviously the condition was not matched and the blue LEDs remained off. If I then go into the menu option to set the on time to 14:00 the LCD correctly displays 840 as the LCD (simplified part of the code here)
    Code:
    Lighton:
    
    Lcdout $FE,2
    LCDOUT $FE,$80,"Set On Time For "
        IF H_butt = 0 THEN GOSUB delHours
        IF M_butt = 0 THEN GOSUB delMinutes
        lightsetHR[fn]=Hours
        lightsetMN[fn]=Minutes
        if viv >=2 then viv =2
        if viv= 1 then LCDOUT $FE,$C0,"Blue Leds "
        if viv= 2 then LCDOUT $FE,$C0,"white Leds "   
        lcdout $FE,$94,#lightsetHR[fn] DIG 1,#lightsetHR[fn] DIG 0,":",#lightsetMN[fn] DIG 1,#lightsetMN[fn] DIG 0
        Blue_on_Time = (lightsetHR[0]*60)+lightsetMN[0]
        White_on_Time = (lightsetHR[1]*60)+lightsetMN[1]
        
        write 10,Blue_on_Time
    If then add the high / low byte to the option in the read and write statements I get the Illegal character error again.

    The other thing that is now not happening is that if I remove the highbyte / lowbyte from the read / write commands program the chip and then manually set the on time the LCD displays 840 as the value, but when the counter value is reached (ie the clock turns to 14:00) there is no change in state of the LEDs. So its not matching the correct value for the word variable. Could this be due I'm comparing the decimal value for the variable, when in real terms it's still in hex decimal or something ?

    My other option would be to use the lightsetHR[0] and lightsetMN[0] as the data values saved and then try and let the program do the conversion Blue_on_Time = (lightsetHR[0]*60)+lightsetMN[0].


    Update: I've tried the above and I still can't get the case to change from off to on

    Code:
    data @0
        data    00      'Blue fade IN duration hours
        data    30       'Blue fade IN duration minutes
        data    00      'Blues fade OUT duration hours
        data    30       'Blue fade OUT duration minutes
        data    00       'Whites fade IN duration hours
        data    30      'Whites Fade IN duration MINS
        data    00       'Whites Fade OUT duration HOURS
        data    30       'Whites Fade OUT duration MINS
        data    255       'Blue MAX Intensity %
        data    255      'Whites MAX Intensity %
        data    14
        data    00
    And then have this in the read routine

    Code:
    Read 10,lightsetHR[0]
    Read 11,lightsetMN[0]
    This compiled Ok and when loaded the LCD correctly displayed 840 as the value of Blue_on_time, but when the clock turned over from 13:59 to 14:00 the case still remains the same and the LED failed to light.

    If I comment out the read write and data lines, and code the value blue_on_time=840 it works !!!! - obviously I would like to be able to change the on and off times of the two channels (white and blue) rather than had coded.
    Last edited by Scampy; - 9th November 2013 at 17:46. Reason: update on further test

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Hi,
    You can't just say DATA 840 since that is larger than what fits in a byte.
    Are you sure the LCD said 74 and not 72? 840 in binary is 1101001000, look at the 8 least significant bits (marked in red), that's what will actually fit within the byte in EEPROM. It says 72.

    As been written previously you need to use the WORD modifier to store a WORD in EEPROM, and then use it again to read it. Or read the high and low byte "manually" after figuring out in which order the DATA statement stores them.

    /Henrik.

  13. #13
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Henrik,

    I still can't get this to compile. I've tried something different, here is my logic (illogical thinking !!)

    Created eight new variables, as bytes as the values will be 0-12 for hours and 0-59 for minutes
    Code:
    Blue_On_Time_H var byte
    Blue_on_Time_M var byte
    Blue_Off_Time_H var byte
    Blue_off_Time_M var byte
    
    White_On_Time_H var byte
    White_on_Time_M var byte
    White_Off_Time_H var byte
    White_off_Time_M var byte
    Then add eight lines of data to match

    Code:
        data    14      'Blue ON time hours
        Data    00      'Blue ON time minutes
        data    15      'Blue OFF time hours
        Data    00      'Blue OFF time minutes
        Data    14      'Whites ON time hours
        data    01      'Whites ON time minutes
        data    14      'Whites OFF time hours
        Data    20      'Whites OFF time minutes
    Then added the read and write sections

    Code:
    write 10,white_on_time_h              'Whites ON time hours
    write 11,white_on_time_m              'Whites ON time minutes
    write 12,white_off_time_h             'Whites OFF time hours
    write 13,white_off_time_m             'Whites OFF time minutes
    write 14,blue_on_time_h             'Whites ON time hours
    write 15,blue_on_time_m             'Whites ON time minutes
    write 16,blue_off_time_h            'Whites OFF time hours
    write 17,blue_off_time_m            'Whites OFF time minutes
    Code:
    Read 10,white_on_time_h              'Whites ON time hours
    Read 11,white_on_time_m              'Whites ON time minutes
    read 12,white_off_time_h             'Whites OFF time hours
    read 13,white_off_time_m             'Whites OFF time minutes
    read 14,blue_on_time_h             'blue ON time hours
    read 15,blue_on_time_m             'blue ON time minutes
    read 16,blue_off_time_h            'blue OFF time hours
    read 17,blue_off_time_m            'blue OFF time minutes
    I get the illegal character error when compiling. If I comment out the read / write lines for these variables it complies. I've even tried commenting all but just one line and it still fails !

    OK I see I've transposed the data values - but the fact that it's not putting anything into the memory shouldn't matter

    Now corrected:
    Code:
    data @0
        data    00      'Blue fade IN duration hours
        data    30      'Blue fade IN duration minutes
        data    00      'Blues fade OUT duration hours
        data    30      'Blue fade OUT duration minutes
        data    00      'Whites fade IN duration hours
        data    30      'Whites Fade IN duration MINS
        data    00      'Whites Fade OUT duration HOURS
        data    30      'Whites Fade OUT duration MINS
        data    255     'Blue MAX Intensity %
        data    255     'Whites MAX Intensity %
        data    14      'Whites ON time hours
        Data    00      'Whites ON time minutes
        data    15      'Whites OFF time hours
        Data    00      'blue OFF time minutes
        Data    14      'blue ON time hours
        data    01      'blue ON time minutes
        data    14      'blue OFF time hours
        Data    20      'blue OFF time minutes
    Last edited by Scampy; - 9th November 2013 at 21:49. Reason: corrected data

  14. #14
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    the highbyte,lowbyte works for ok me now (as it should) I must have too tired last nite , interesting when I used write 10, tst.highbyte before declaring tst as a word mcs5 crashed with no error message just died.
    scampy
    it looks like your reading from location 10 but your data @0 writes from location 0

  15. #15
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    One more for tonight before I throw this poxy project out the window.

    why does WRITE 10,lightsetHR[1] work when WRITE 10,white_on_time_h cause the illegal error ?

    I've changed the code to the following:
    Data statement:
    Code:
    data @0
        data    00      'Blue fade IN duration hours
        data    30      'Blue fade IN duration minutes
        data    00      'Blues fade OUT duration hours
        data    30      'Blue fade OUT duration minutes
        data    00      'Whites fade IN duration hours
        data    30      'Whites Fade IN duration MINS
        data    00      'Whites Fade OUT duration HOURS
        data    30      'Whites Fade OUT duration MINS
        data    255     'Blue MAX Intensity %
        data    255     'Whites MAX Intensity %
        data    14      'Whites ON time hours
        Data    00      'Whites ON time minutes
        data    15      'Whites OFF time hours
        Data    00      'blue OFF time minutes
        Data    14      'blue ON time hours
        data    01      'blue ON time minutes
        data    14      'blue OFF time hours
        Data    20      'blue OFF time minutes
    Read statement:
    Code:
    Read 0,fadesetHR[0]    'Blue fade IN duration hours
    Read 1,fadesetMN[0]    'Blue fade IN duration minutes
    Read 2,fadeoutHR[0]    'Blue fade OUT duration hours
    read 3,fadeoutMN[0]    'Blue fade OUT duration minutes
    
    read 4,fadesetHR[1]    'Whites fade IN duration hours
    read 5,fadesetMN[1]    'Whites fade IN duration minutes
    read 6,fadeoutHR[1]    'Whites fade OUT duration hours
    read 7,fadeoutMN[1]    'Whites fade OUT duration minutes
    
    Read 8,B_max
    Read 9,W_max
    
    Read 10,white_on_time_h              'Whites ON time hours
    Read 11,white_on_time_m              'Whites ON time minutes
    read 12,white_off_time_h             'Whites OFF time hours
    read 13,white_off_time_m             'Whites OFF time minutes
    read 14,blue_on_time_h             'blue ON time hours
    read 15,blue_on_time_m             'blue ON time minutes
    read 16,blue_off_time_h            'blue OFF time hours
    read 17,blue_off_time_m            'blue OFF time minutes
    Write statements

    Code:
    write 0,fadesetHR[0]    'Blue fade IN duration hours
    write 1,fadesetMN[0]    'Blue fade IN duration minutes
    write 2,fadeoutHR[0]    'Blue fade IN duration hours
    write 3,fadeoutMN[0]    'Blue fade IN duration minutes
    
    write 4,fadesetHR[1]    'Whites fade IN duration hours
    write 5,fadesetMN[1]    'Whites fade IN duration minutes
    write 6,fadeoutHR[1]    'Whites fade IN duration hours
    write 7,fadeoutMN[1]    'Whites fade IN duration minutes
    
    write 8,B_max
    write 9,W_max
    
    write 10,lightsetHR[1]
    write 11,lightsetMN[1]
    write 12,lightoffHR[1]
    Write 13,lightoffMN[1]
    
    write 14,lightsetHR[0]
    write 15,lightsetMN[0]
    write 16,lightoffHR[0]
    Write 17,lightoffMN[0]
    I then have the following section as part of the initialization before the main program loop
    Code:
    lightsetHR[0] = Blue_On_Time_H
    lightsetMN[0] = Blue_On_Time_M
    lightsetHR[1] = White_On_Time_H
    lightsetMN[1] = White_On_Time_M
    
    lightoffHR[0] = Blue_Off_Time_H
    lightoffMN[0] = Blue_Off_Time_M
    lightoffHR[1] = White_Off_Time_H
    lightoffMN[1] = White_Off_Time_M
    And in the main program loop

    Code:
    Blue_on_Time =(lightsetHR[0]*60)+lightsetMN[0]
    Blue_off_time = (lightoffHR[0]*60)+lightoffMN[0]
     
    White_on_Time =(lightsetHR[1]*60)+lightsetMN[1]
    White_off_time = (lightoffHR[1]*60)+lightoffMN[1]

    This compiles fine, and when first run the case changes at the value set in the data statement, and the LCD displays the correct value for Blue on time (eg 842 for 14:02). But when I set the on time up via the menu, even though the LCD displays the new value for blue_on_time correctly (eg 845 for 14:05 as set via the menu) it still fails to trip the case statement at the new time.

    Any ideas ?

  16. #16
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    it might be easier to use a PCF8563 rtc chip with built in alarm and interrupt output
    I use one of these on my wireless remote rain guage its a good thing. works at 3v too

    i'd need to see the full code to see whats wrong with your project

  17. #17
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Hi,
    I have NO idea what's going on with this Illegal Character error. The only thing I can think of is, as I've said before, some kind of hidden character that makes the compiler hick up. I copy/pasted all of the sections in the previous post into MCS, resulting in the following:
    Code:
    Blue_On_Time_H var byte
    Blue_on_Time_M var byte
    Blue_Off_Time_H var byte
    Blue_off_Time_M var byte
    
    White_On_Time_H var byte
    White_on_Time_M var byte
    White_Off_Time_H var byte
    White_off_Time_M var byte
    
    data    14      'Blue ON time hours
    Data    00      'Blue ON time minutes
    data    15      'Blue OFF time hours
    Data    00      'Blue OFF time minutes
    Data    14      'Whites ON time hours
    data    01      'Whites ON time minutes
    data    14      'Whites OFF time hours
    Data    20      'Whites OFF time minutes
        
    write 10,white_on_time_h              'Whites ON time hours
    write 11,white_on_time_m              'Whites ON time minutes
    write 12,white_off_time_h             'Whites OFF time hours
    write 13,white_off_time_m             'Whites OFF time minutes
    write 14,blue_on_time_h             'Whites ON time hours
    write 15,blue_on_time_m             'Whites ON time minutes
    write 16,blue_off_time_h            'Whites OFF time hours
    write 17,blue_off_time_m            'Whites OFF time minutes
    
    Read 10,white_on_time_h              'Whites ON time hours
    Read 11,white_on_time_m              'Whites ON time minutes
    read 12,white_off_time_h             'Whites OFF time hours
    read 13,white_off_time_m             'Whites OFF time minutes
    read 14,blue_on_time_h             'blue ON time hours
    read 15,blue_on_time_m             'blue ON time minutes
    read 16,blue_off_time_h            'blue OFF time hours
    read 17,blue_off_time_m            'blue OFF time minutes
    
    END
    Needles to say it compiles just fine for the 12F683, 16F877, 18F8620 and any other device I try with onboard EEPROM. I've tried this with both PBP3.0.7.4 and with PBP2.60. My MPBLAB installation is v8.88 containing MPASM v5.47.

    /Henrik.

  18. #18
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Richard, you have a PM

    @Henrik - I too have no idea why the error occurs - I've cut and pasted lines, written them in fill - deleted sections and pasted sections - but still the same ! - Puzzling

  19. #19
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Quote Originally Posted by richard View Post
    it might be easier to use a PCF8563 rtc chip with built in alarm and interrupt output
    I use one of these on my wireless remote rain guage its a good thing. works at 3v too

    i'd need to see the full code to see whats wrong with your project
    I have a DS1307 RTC chip, but for some reason in the original project this gave me a lot of issues as the time would randomly revert to 10:10:10 and thus screw up the timings. I'll have a look at the 8563 chip, but really wanted to steer away from external chips in case the same issue happens again

  20. #20
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    What if you start a new/blank project/file, then copy/paste the complete code from my latest post above into it, select the 12F683 (for example) and then try to compile it. Does it still give you the error?

    If this STILL fails can you then please take the source file (the .pbp or .bas file) and attach it to a message here so I can try and compile it on my end. There's got to be something weird going on with your system, I can not make it fail here PBP3 with MPASM or PBP2.60 with MPASM or PM (for 12F and 16F parts) it all works fine with the above code.

    Which chip are you compiling for?

    /Henrik.

  21. #21
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Henrik, I'll try that suggestion later and let you know how I get on. The chip is an 18F4520

  22. #22
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    OK, then PM is out of the question and the only difference between your setup and mine is MPLAB 8.87 vs 8.88 and whatever MPASM version that translates too - there might not even be a different version.

    Just tried compiling for 18F4520 using PBP2.60 and there was no errors.

    Looking forward to the results.

    /Henrik,

  23. #23
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    I have NO idea what's going on with this Illegal Character error. The only thing I can think of is, as I've said before, some kind of hidden character that makes the compiler hick up. I copy/pasted all of the sections in the previous post into MCS, resulting in the following:
    Code:
    Blue_On_Time_H var byte
    Blue_on_Time_M var byte
    Blue_Off_Time_H var byte
    Blue_off_Time_M var byte
    
    White_On_Time_H var byte
    White_on_Time_M var byte
    White_Off_Time_H var byte
    White_off_Time_M var byte
    
    data    14      'Blue ON time hours
    Data    00      'Blue ON time minutes
    data    15      'Blue OFF time hours
    Data    00      'Blue OFF time minutes
    Data    14      'Whites ON time hours
    data    01      'Whites ON time minutes
    data    14      'Whites OFF time hours
    Data    20      'Whites OFF time minutes
        
    write 10,white_on_time_h              'Whites ON time hours
    write 11,white_on_time_m              'Whites ON time minutes
    write 12,white_off_time_h             'Whites OFF time hours
    write 13,white_off_time_m             'Whites OFF time minutes
    write 14,blue_on_time_h             'Whites ON time hours
    write 15,blue_on_time_m             'Whites ON time minutes
    write 16,blue_off_time_h            'Whites OFF time hours
    write 17,blue_off_time_m            'Whites OFF time minutes
    
    Read 10,white_on_time_h              'Whites ON time hours
    Read 11,white_on_time_m              'Whites ON time minutes
    read 12,white_off_time_h             'Whites OFF time hours
    read 13,white_off_time_m             'Whites OFF time minutes
    read 14,blue_on_time_h             'blue ON time hours
    read 15,blue_on_time_m             'blue ON time minutes
    read 16,blue_off_time_h            'blue OFF time hours
    read 17,blue_off_time_m            'blue OFF time minutes
    
    END
    Needles to say it compiles just fine for the 12F683, 16F877, 18F8620 and any other device I try with onboard EEPROM. I've tried this with both PBP3.0.7.4 and with PBP2.60. My MPBLAB installation is v8.88 containing MPASM v5.47.

    /Henrik.
    Just created a new blank page in MCS and copied and pasted the above from post #17, added the config settings etc and tried compiling

    Code:
    '*******************************************************************************
    '  18F4520 config settings - for use with MPSAM
    '*******************************************************************************
    
    ASM 
      __CONFIG    _CONFIG1H, _OSC_HS_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H  
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    '*******************************************************************************
    ' Defines and LCD (20 x 4) set up
    '*******************************************************************************
    
    DEFINE  OSC 20  ; 48 was old config settings 18F4520, 20mhz crystal
    ADCON1 = $0F
    clear
    
    DEFINE  WRITE_USED  1
    
    DEFINE LCD_DREG  PORTB           ' LCD Data port
    DEFINE LCD_DBIT  0               ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB           ' LCD Enable port
    DEFINE LCD_EBIT  5               '     Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB           ' LCD Register Select port
    DEFINE LCD_RSBIT 4               '     Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4               ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 4               ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000        ' Command delay time in us 
    DEFINE LCD_DATAUS 50             ' Data delay time in us 
    
    '*******************************************************************************
    'DS18B20 setting
    '*******************************************************************************
    
    DQ              VAR     PORTA.5         ' One-wire data pin
    temperature     VAR     WORD            ' Temperature storage
    count_remain    VAR     BYTE            ' Count remaining
    count_per_c     VAR     BYTE            ' Count per degree C
    
    '*******************************************************************************
    'analog and Comparator settings
    '*******************************************************************************
    
    ADCON0 = 0                      'Set ADCON0
    ADCON1 = %00001111              'Set D i/o
    CMCON = 7                       'Disable Comparators
    
    '*******************************************************************************
    'Port and Register settings
    '*******************************************************************************
    
    CCP1CON = %00001100             ' 
    CCP2CON = %00001100             '     
    TRISA  = %11101111              '
    TRISB  = %00000011 
    TRISD  = %00000011              '
    T0CON  = %11000111
    
    Blue_On_Time_H var byte
    Blue_on_Time_M var byte
    Blue_Off_Time_H var byte
    Blue_off_Time_M var byte
    
    White_On_Time_H var byte
    White_on_Time_M var byte
    White_Off_Time_H var byte
    White_off_Time_M var byte
    
    data    14      'Blue ON time hours
    Data    00      'Blue ON time minutes
    data    15      'Blue OFF time hours
    Data    00      'Blue OFF time minutes
    Data    14      'Whites ON time hours
    data    01      'Whites ON time minutes
    data    14      'Whites OFF time hours
    Data    20      'Whites OFF time minutes
        
    write 10,white_on_time_h              'Whites ON time hours
    write 11,white_on_time_m              'Whites ON time minutes
    write 12,white_off_time_h             'Whites OFF time hours
    write 13,white_off_time_m             'Whites OFF time minutes
    write 14,blue_on_time_h             'Whites ON time hours
    write 15,blue_on_time_m             'Whites ON time minutes
    write 16,blue_off_time_h            'Whites OFF time hours
    write 17,blue_off_time_m            'Whites OFF time minutes
    
    Read 10,white_on_time_h              'Whites ON time hours
    Read 11,white_on_time_m              'Whites ON time minutes
    read 12,white_off_time_h             'Whites OFF time hours
    read 13,white_off_time_m             'Whites OFF time minutes
    read 14,blue_on_time_h             'blue ON time hours
    read 15,blue_on_time_m             'blue ON time minutes
    read 16,blue_off_time_h            'blue OFF time hours
    read 17,blue_off_time_m            'blue OFF time minutes
    Guess what - I got the error

    If I comment out the write statements it compiles....

  24. #24
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Hi,
    OK, so there was a lot more to the code than you showed earlier....
    The actual problem seems to be the DEFINE WRITE_USED 1. Comment that out and it compiles fine.ything. Where did you find that and what's the purpose of it?

    /Henrik.

  25. #25
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    I can confirm that when that is commented out it too compiles fine this end. I have no Idea where that came from, I guess that's the problem when using previous code from existing projects or porting examples from forums and websites. Chances are a previous project required this for some reason, but with out opening every file I can't say where it came from.

    Thanks for identifying this problem. Could you explain to me what this define means or does, and when it might be used.

    I'll now go back over this thread and see if using the highbyte and lowbyte resolves my other issue of the case statement not changing when the blue on time value matches that of the current clock counter.

    Malcolm

  26. #26
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Could you explain to me what this define means or does, and when it might be used.
    No, not really. That's why I asked where you found it and what the reason for adding it was.

    A bit of forum search turned up a couple of leads, apparently there's a bug in 2.60 which affects WRITE with WORD variables. But now, you might be on a later version of PBP where that bug is not present making the DEFINE either not needed or actually causing problems. I can't really say for sure.

    The issue is described here.

    I strongly suggest you update to 2.60C (or even better to PBP3), you can download the PBP2.60C patch here, scroll down to find 2.60C:
    http://support.melabs.com/content/29...ersion-History

    Someone else might be able to shed some more light on it.

    /Henrik.

  27. #27
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Thanks Henrik, I'll have a browse and look at my options to upgrade.

    Malcolm

  28. #28
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    When applying the patch it looks like it's replacing all the .inc files so if you've edited ANY of them they will have to be re-editied.

    /Henrik.
    Last edited by HenrikOlsson; - 10th November 2013 at 19:02. Reason: Double post...

  29. #29
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    I've been re-reading the reference guide and this may explain it:

    If interrupts are used in a program, they must be turned off (masked, not
    DISABLEd) before executing a WRITE, and turned back on (if desired) after the
    WRITE instruction is complete. An interrupt occurring during a WRITE may cause
    it to fail. The following DEFINE turns interrupts off and then back on within a
    WRITE command. Do not use this DEFINE if interrupts are not used in the
    program.

    DEFINE WRITE_INT 1
    I'm not using interrupts in this code, so it's not needed - I must of added from one of the previous versions which does use interrupts

  30. #30
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    Richard / Henrik

    Code is now working. This is the data section

    Code:
    '*******************************************************************************
    ' Data presets
    '*******************************************************************************
    data @0
        data    00      'Blue fade IN duration hours
        data    30      'Blue fade IN duration minutes
        data    00      'Blues fade OUT duration hours
        data    30      'Blue fade OUT duration minutes
        data    00      'Whites fade IN duration hours
        data    30      'Whites Fade IN duration MINS
        data    00      'Whites Fade OUT duration HOURS
        data    30      'Whites Fade OUT duration MINS
        data    255     'Blue MAX Intensity %
        data    255     'Whites MAX Intensity %
        data    word 842      'Blue ON time 
        Data    word 841      'Whites ON time 
        data    word 1200      'Blue OFF time 
        Data    word 1200      'White OFF time
    Then the read statement

    Code:
    Read 0,fadesetHR[0]    'Blue fade IN duration hours
    Read 1,fadesetMN[0]    'Blue fade IN duration minutes
    Read 2,fadeoutHR[0]    'Blue fade OUT duration hours
    read 3,fadeoutMN[0]    'Blue fade OUT duration minutes
    
    read 4,fadesetHR[1]    'Whites fade IN duration hours
    read 5,fadesetMN[1]    'Whites fade IN duration minutes
    read 6,fadeoutHR[1]    'Whites fade OUT duration hours
    read 7,fadeoutMN[1]    'Whites fade OUT duration minutes
    
    Read 8,B_max
    Read 9,W_max
    
    read 10,Blue_on_Time.lowbyte
    read 11,Blue_on_Time.highbyte
    read 12,white_on_Time.lowbyte
    read 13,white_on_Time.highbyte
    
    read 14,Blue_off_Time.highbyte
    read 15,Blue_off_Time.lowbyte
    read 16,white_off_Time.lowbyte
    read 17,white_off_Time.highbyte
    
    Return
    I then have a simple test line of
    Code:
    lcdout $FE,$D4+11,dec Counter1
    lcdout $FE,$D4+16,dec Blue_on_Time
    This shows the value for Blue_on_time as 842, and the counter starting at 840 as per the data statement. When the counter reaches 842 the case statement changes as required.

    Thank you both, and I apologise for putting you guys to so much trouble having tested parts of the code on various chips. Your guidance and input on my posts have been much appreciated

    Malcolm

  31. #31
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Stumped with word variable

    An alternative to using high/lowbyte for a word is to shift bits within the word

    Some code might be pseudo
    Code:
    word var word
    byte var byte
    
    DATA at EEPROM location 0 = $FF // low byte of the word you want to read
    DATA at EEPROM location 1 = $FF // high byte of the word you want to read
    
    // program run time
    
    READ EEPROM, 0, byte
    word = byte
    word = word << 8
    READ EEPROM, 1,byte
    word = word + byte
    
    // now the word is in memory - word = $FFFF
    
    byte = word
    WRITE EEPROM 0,byte
    word = word >> 8
    byte = word
    WRITE EEPROM 1,byte
    
    // the value in word was not preserved here,
    // it would have been needed to be saved first
    This is helpful if you want to use variables larger than PBP supports
    for some operations.
    It would be simple to do a binary addition on two 64 bit integers this way,
    and is more familiar outside of BASIC.

Similar Threads

  1. When variable may not fits into WORD limitations
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2013, 09:26
  2. How to isolate 10 bits from word variable?
    By rcbandwidth123 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 14th April 2008, 20:18
  3. adding new word variable ?
    By iugmoh in forum General
    Replies: 4
    Last Post: - 21st February 2008, 00:26
  4. WORD vs BYTE variable lengths
    By bartman in forum General
    Replies: 0
    Last Post: - 28th November 2005, 21:16
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

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