"Stretching" a byte variable into two byte variables?


Closed Thread
Results 1 to 10 of 10

Hybrid View

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

    Default "Stretching" a byte variable into two byte variables?

    Hello
    I don't know the exact term I need, so here's what I'm doing. Since I've created custom 8x8 fonts for ST7920, I also want it to be able to display bigger letters too. Stretching vertically is not a problem - just double the lines and that's all. But when it comes to horizontal stretching, I'm facing some issues. The code should work as follows - initial bitmap data, read from single byte in eeprom, should be "stretched" into two byte variables and written to display. The code below shows how I see it. But it has a lot of if-then lines, and my guess is, that there should be a something simpler to do this task. Any ideas?

    Code:
    'bytes in eeprom at left, what should be at output - at right
    'this is a letter "A"
    'A		B	 C
    '(eeprom)	(MSB)	 (LSB)
    '00111100	00001111 11110000
    '01000010	00110000 00001100
    '01000010	00110000 00001100
    '01111110	00111111 11111100
    '01000010	00110000 00001100
    '01000010	00110000 00001100
    	
    IF A.0=0 THEN B.0=0:B.1=0
    IF A.0=1 THEN B.0=1:B.1=1
    IF A.1=0 THEN B.2=0:B.3=0
    IF A.1=1 THEN B.2=1:B.3=1
    IF A.2=0 THEN B.4=0:B.5=0
    IF A.2=1 THEN B.4=1:B.5=1
    IF A.3=0 THEN B.6=0:B.7=0
    IF A.3=1 THEN B.6=1:B.7=1
    
    
    IF A.4=0 THEN C.0=0:C.1=0
    IF A.4=1 THEN C.0=1:C.1=1
    IF A.5=0 THEN C.2=0:C.3=0
    IF A.5=1 THEN C.2=1:C.3=1
    IF A.6=0 THEN C.4=0:C.5=0
    IF A.6=1 THEN C.4=1:C.5=1
    IF A.7=0 THEN C.6=0:C.7=0
    IF A.7=1 THEN C.6=1:C.7=1

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


    Did you find this post helpful? Yes | No

    Default Re: "Stretching" a byte variable into two byte variables?

    sample the msb of your byte
    if its set add three to your word var
    shift left the byte var 1 bit the word 2 bits
    repeat for all 8 bits
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: "Stretching" a byte variable into two byte variables?

    and if it not?

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


    Did you find this post helpful? Yes | No

    Default Re: "Stretching" a byte variable into two byte variables?

    don't add 3
    Warning I'm not a teacher

  5. #5
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

    Default Re: "Stretching" a byte variable into two byte variables?

    If you start off with B=0 and C=0 you can skip half those statements and only do the ones where A.x = 1

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


    Did you find this post helpful? Yes | No

    Default Re: "Stretching" a byte variable into two byte variables?

    I wanted it to be shorter, by using loop and

    X.Y=Z
    but as I can see, you can't use another variable as bit reference, only static values.

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


    Did you find this post helpful? Yes | No

    Default Re: "Stretching" a byte variable into two byte variables?

    full test code here
    Warning I'm not a teacher

Similar Threads

  1. "Variable already an alias" - is there a way to avoid this?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 18th June 2022, 22:22
  2. Byte from variable
    By Lilleljung in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th February 2015, 22:29
  3. Replies: 0
    Last Post: - 14th November 2013, 03:32
  4. Replies: 3
    Last Post: - 15th October 2012, 08:06
  5. AN Question for "word" variable read The serial port
    By redfoen in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2007, 17:39

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