• AVR Freaks

Hot!Font lookup

Author
upand_at_them
Super Member
  • Total Posts : 576
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: offline
2020/05/01 07:25:57 (permalink)
0

Font lookup

I came up with this routine for calculating the font lookup and sending the bytes via I2C.  Can this be improved any?
 
ssd1306_char
   addlw .224 ; subtract 32 by adding two's complement (not using chars 0-31)
   movwf FSR1L ; routine enters with character in WREG
   clrf FSR1H
   lslf FSR1L, f ; multipy by 2 (doesn't generate carry since character is < 127)
   lslf FSR1L, f ; multiply by 2 again
   rlf FSR1H ; move carry into FSR1H
   addwf FSR1L ; add W (for a total of x5, character set is 5 bytes wide)
   clrw
   addwfc FSR1H, f ; update FSR1H
   movlw LOW font5x7 ; LOW byte of character set location
   addwf FSR1L
   movlw HIGH (font5x7 + 0x8000) ; HIGH byte of character set, w/ linear data offset
   addwfc FSR1H, f
  
   call i2c_start ; send the 5 bytes that make up the character
   movlw SSD1306_ADDRESS
   call i2c_tx_byte
   movlw 0x40
   call i2c_tx_byte
   movlw .5
   movwf i2ccounter1
ssdcharloop
   moviw FSR1++
   call i2c_tx_byte
   decfsz i2ccounter1, f
   goto ssdcharloop
   call i2c_stop
   return

 
#1

4 Replies Related Threads

    upand_at_them
    Super Member
    • Total Posts : 576
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: Font lookup 2020/05/01 07:31:08 (permalink)
    0
    Here's a better looking render of the code.
     

    Attached Image(s)

    #2
    1and0
    Access is Denied
    • Total Posts : 10985
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Font lookup 2020/05/01 10:56:45 (permalink)
    0
    upand_at_them
    I came up with this routine for calculating the font lookup and sending the bytes via I2C.  Can this be improved any?
     

     
    Here's one that reduces two code words:
    ssd1306_char
            movwf   FSR1L
            clrf    FSR1H
           
            lslf    FSR1L
            lslf    FSR1L
            rlf     FSR1H
           
            addwf   FSR1L
            skpnc
            incf    FSR1H
           
            movlw   low (font5x7 + 0x8000 - 5*.32)
            addwf   FSR1L
            movlw   high(font5x7 + 0x8000 - 5*.32)
            addwfc  FSR1H
           
            call    i2c_start        ; send the 5 bytes that make up the character
            movlw   SSD1306_ADDRESS
            call    i2c_tx_byte
            movlw   0x40
            call    i2c_tx_byte
            movlw   .5
            movwf   i2ccounter1
    ssdcharloop
            moviw   FSR1++
            call    i2c_tx_byte
            decfsz  i2ccounter1, f
            goto    ssdcharloop
            goto    i2c_stop

     
    #3
    upand_at_them
    Super Member
    • Total Posts : 576
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: Font lookup 2020/05/01 11:21:23 (permalink)
    0
    Thanks!  Good to know that I was close to efficient.
    #4
    upand_at_them
    Super Member
    • Total Posts : 576
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: Font lookup 2020/05/01 12:19:20 (permalink)
    0
    I like putting the fixed values into where the assembler can deal with them instead of wasting runtime on them.  I also like the neat trick of using the last routine call as the return instead of wasting time coming back just to return.
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5