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,154


    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?

  2. #2
    Join Date
    Feb 2013
    Posts
    1,154


    Did you find this post helpful? Yes | No

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

    Houston, we're having a problem!

    Below is the code which works, but it works only if bits in array are aligned to bytes. If I want to shift them to make them less spaced (characters used have 4 pixel width, +1 pixel for spacing), image becomes garbled and shifted in wrong direction, as shown on attached pictures. What I'm doing wrong?

    Code:
    DATA $60,$90,$90,$90,$90,$90,$90,$60 '0  'digits, left justified 4 bits used in each 8 bits
    DATA $20,$60,$A0,$20,$20,$20,$20,$F0 '1
    DATA $60,$90,$90,$10,$60,$80,$80,$F0 '2
    DATA $60,$90,$10,$60,$10,$90,$90,$60 '3
    DATA $90,$90,$90,$70,$10,$10,$10,$10 '4
    DATA $F0,$80,$80,$E0,$10,$90,$90,$60 '5
    DATA $60,$90,$80,$E0,$90,$90,$90,$60 '6
    DATA $F0,$10,$10,$20,$20,$40,$40,$40 '7
    DATA $60,$90,$90,$60,$90,$90,$90,$60 '8
    DATA $60,$90,$90,$70,$10,$90,$90,$60 '9
    
    INVAR=1234
    FOR I=0 TO 7 'Read digit data from apropriate positions in EEPROM into own CHAR variables
    
    READ 6+I+8*INVAR DIG 3, CHAR1
    READ 6+I+8*INVAR DIG 2, CHAR2
    READ 6+I+8*INVAR DIG 1, CHAR3
    READ 6+I+8*INVAR DIG 0, CHAR4
    
    FOR Y=0 TO 7 'write CHAR DATA INTO ARRAY WITH OFFSET
    SCREEN32[Y]=CHAR1.0(Y)
    SCREEN32[Y+8]=CHAR2.0(Y) 'OFSETS ARE SET HERE
    SCREEN32[Y+16]=CHAR3.0(Y)
    SCREEN32[Y+24]=CHAR4.0(Y)
    NEXT
    
    'read array data into 8 bit variables
    
    FOR C=0 to 7
    SEGA.0(C)=SCREEN32[C]
    SEGB.0(C)=SCREEN32[8+C]
    SEGC.0(C)=SCREEN32[16+C]
    SEGD.0(C)=SCREEN32[24+C]
    NEXT
    
    'WRITE ARRAY DATA INTO DISPLAY AND GO TO NEXT LINE
    LOW LOAD
    shiftout datapin,clockpin,1,[1+I, SEGA]	
    shiftout datapin,clockpin,1,[1+I, SEGB] 
    shiftout datapin,clockpin,1,[1+I, SEGC] 
    shiftout datapin,clockpin,1,[1+I, SEGD] 
    HIGH LOAD
    
    NEXT
    END
    Name:  normal.jpg
Views: 3767
Size:  90.8 KB

    Name:  notnormal.jpg
Views: 3621
Size:  194.7 KB

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,690


    Did you find this post helpful? Yes | No

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

    you are dealing with a matrix that fills like this


    Name:  ledm.jpg
Views: 3754
Size:  111.2 KB
    its not a particularly easy format to leverage font images that traverse cells , and you cannot read back the data from the matrix
    to make life easy i would make a memory array [frame buffer] mapped to the matrix like this


    Name:  mem.jpg
Views: 4191
Size:  108.9 KB


    it's then quite straight forward to overlay a font chr into any location
    and then create a simple routine to write the frame buffer to the display
    in the bit order the matrix demands
    Last edited by richard; - 4th January 2021 at 03:06.
    Warning I'm not a teacher

  4. #4
    Join Date
    Feb 2013
    Posts
    1,154


    Did you find this post helpful? Yes | No

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

    Well, I already have buffer, but 32x1 pixels in size, because the data is sent to display line by line.
    But the problem is different, I can't understand why this works only per 8 bit: SCREEN32[Y+8]=CHAR2.0(Y) - if I enter any other number instead of 8, which is not multiple of 8, say 5 or 17, everything becomes garbled, while it should not. So, maybe I'm writing in array incorrectly?

    I was able to solve this problem by replacing array with string of Boolean logic operations, but I'd like to keep array, because later I want to display more letters, with variable width...
    Code:
    char1=char1 | char2>>5
    char2=char2 <<3 | char3>>2
    char2=char2 | char4>>7
    char3=char4<<1
    char4=0

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


    Did you find this post helpful? Yes | No

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

    Oh, and by the way, is there any possibility to increase SPI speed? I'm running 16F886 @ 8mhz, and update rate is clearly not good - forget about scrolling letters and other stuff like that.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,690


    Did you find this post helpful? Yes | No

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

    Oh, and by the way, is there any possibility to increase SPI speed? I'm running 16F886 @ 8mhz, and update rate is clearly not good - forget about scrolling letters and other stuff like that.
    yes don't use shiftout, on a chip that has a mssp module it's an order of magnitude or two slower than spi
    its like having a dog and barking yourself

    Well, I already have buffer, but 32x1 pixels in size, because the data is sent to display line by line.
    yet characters persist over 8 lines and you are ignoring that present data, furthermore there is no way to recover that data from the chip
    you figure it out
    Warning I'm not a teacher

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,690


    Did you find this post helpful? Yes | No

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

    after some thought ,

    Well, I already have buffer, but 32x1 pixels in size, because the data is sent to display line by line.
    But the problem is different, I can't understand why this works only per 8 bit: SCREEN32[Y+8]=CHAR2.0(Y) - if I enter any other number instead of 8, which is not multiple of 8, say 5 or 17, everything becomes garbled, while it should not. So, maybe I'm writing in array incorrectly?
    i assume SCREEN32 is your 32 bit array ,
    SCREEN32[Y+8] is then a complete nonsense as the only valid locations are 0 to 3

    similarly wtf is char2 ? if its a byte then
    CHAR2.0(Y) a valid y value can only be 0 to 7

    then we have this, wtf is char1 a byte a word an array ? , a pointless snippet

    char1=char1 | char2>>5
    char2=char2 <<3 | char3>>2
    char2=char2 | char4>>7
    char3=char4<<1char4=0
    Warning I'm not a teacher

  8. #8
    Join Date
    Feb 2013
    Posts
    1,154


    Did you find this post helpful? Yes | No

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

    Yes, SCREEN32 is 32 bit array.
    And why locations only can be from 0 to 3 ?
    There are 32 bits, or what you want to say, that is not possible to write into specific bit of bit array?

    I'm reading a bit from variable and writing it into bit of an array, to later read bits as needed.

Similar Threads

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