Joining 5 bit variables and splitting them into 8 bit ones later?


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: Joining 5 bit variables and splitting them into 8 bit ones later?

    What if I create 32 bit array, write bits in sequence and then read it in appropriate chunks?

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Joining 5 bit variables and splitting them into 8 bit ones later?

    Something like this?
    Code:
    ' 001110 001110 001110 001110
    FullDisp VAR LONG
    FullDisp.31 = 0
    FullDisp.30 = 0
    FullDisp.29 = 1
    FullDisp.28 = 1
    FullDisp.27 = 1
    FullDisp.26 = 0
    FullDisp.25 = 0
    ... ... ... ... ... ...

  3. #3
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: Joining 5 bit variables and splitting them into 8 bit ones later?

    Yes, but have no idea if can use another variable instead of 31 and other digits.
    Like displayvar.X=Y

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


    Did you find this post helpful? Yes | No

    Default Re: Joining 5 bit variables and splitting them into 8 bit ones later?

    I suspect this is what you want:
    Code:
    displayvar.0[X]=Y
    But I also suspect we've covered this before so instead of me trying to repeat what's already been covered in detail I just leave it all to Melanie :-)
    http://www.picbasic.co.uk/forum/showthread.php?t=544

  5. #5
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: Joining 5 bit variables and splitting them into 8 bit ones later?

    So it should look like this, right? (have no access to PBP at this moment).
    Code:
    SCREEN32 VAR BIT[32] 'MAIN VARIABLE
    LINE1=%10101 'VARIABLE WITH BIT DATA
    FOR X=0 TO 4 'READ BITS
    SCREEN32[X+1]=LINE1.0(X) 'WRITE INTO ARRAY
    NEXT

  6. #6
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: Joining 5 bit variables and splitting them into 8 bit ones later?

    So here it is, almost finished (not tested in PBP yet, written in notepad).
    Digit data are stored as 4 bit width sequences, each char compromising of 4x8 pixels (width & height). They are stored by pairs in eeprom (1st address holds bitmaps for 1 & 2, 2nd address - for 3 & 4 and so on).
    This routine should display value of 4 digit CNTR variable on screen. It does that by reading 4 bit graphic data from eeprom, adding 1 space between pixels and assembling into 32 bit array, which later should be cut into 4 bytes and sent to MAX7219. For simplicity, code is shown for sending only 1 line. However, I'm stuck, how to read values from 32 bit array and convert them into bytes.
    Code:
    LINE VAR BIT[32] 'line of MAX7219 buffer
    DBIT var byte    'digit bit eeprom address
    DOFF var byte    'digit offset 0 for first, 4 for next
    DSHF var byte    'Shift value for next digit data
    CNTR var word    'Input variable
    Y var byte    'Temporary digit variable
    X var byte    'digit scan variable
    Z var byte    'digit row variable
    BT var bit    'bit variable for font hold
    
    ' decoder routine
    DECODER:
    DSHF=0    'reset char shift variable
    for x=0 to 3 'read all 4 digits
    Y=CNTR DIG X 'EXTRACT VARIABLE DIGIT
    IF Y=1 THEN DBIT=0: DOFF=0 'set the font offset
    IF Y=2 THEN DBIT=0: DOFF=4
    IF Y=3 THEN DBIT=8: DOFF=0
    IF Y=4 THEN DBIT=8: DOFF=4
    IF Y=5 THEN DBIT=16: DOFF=0
    IF Y=6 THEN DBIT=16: DOFF=4
    IF Y=7 THEN DBIT=24: DOFF=0
    IF Y=8 THEN DBIT=24: DOFF=4
    IF Y=9 THEN DBIT=32: DOFF=0
    IF Y=0 THEN DBIT=32: DOFF=4
    
    for Z=0 to 4 'read font data and write into rows
    READ DBIT+DOFF+Z,BT 'read bit from eeprom
    LINE[Z+DSHF]=BT 'write into array
    next
    DSHF=DSHF+5    'increment char shift variable
    
    'now here should extract bits from array and convert into bytes
    'to send to MAX7219, but how?
    next
    Last edited by CuriousOne; - 15th December 2020 at 21:44.

  7. #7
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: Joining 5 bit variables and splitting them into 8 bit ones later?

    I decided to return to this code, and have some advancement, but having issues into reading bits from array into an variable.
    I have a SCREEN[32] bit array, which should be read into 4 consecutive variables - SEGA, SEGB, SEGC, SEGD.
    I know how to access individual bits within variable, but complete byte?

    If I understand correctly, the code should look like this
    Code:
    FOR X=0 to 7
    SEGA.0(X)=SCREEN[X]
    SEGB.0(8+X)=SCREEN[X]
    SEGC.0(16+X)=SCREEN[16+X]
    SEGD.0(24+X)=SCREEN[24+X]
    NEXT
    Is this correct?

Similar Threads

  1. 32 Bit NEC IR Constants/Variables
    By Zebryk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd July 2013, 14:51
  2. Joining variables and displaying on an LCD
    By Navaidstech in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th April 2009, 04:12
  3. 32-bit Variables and DIV32, Hourmeter 99999.9
    By Darrel Taylor in forum Code Examples
    Replies: 9
    Last Post: - 23rd November 2006, 07:23
  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. Bit variables... typo?
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th November 2004, 18:11

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