Stumped with word variable


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    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

  2. #2
    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, 10: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, 21:18
  3. adding new word variable ?
    By iugmoh in forum General
    Replies: 4
    Last Post: - 21st February 2008, 01:26
  4. WORD vs BYTE variable lengths
    By bartman in forum General
    Replies: 0
    Last Post: - 28th November 2005, 22:16
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 20: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