How to convert from alphabets to pixels

一世执手 提交于 2019-11-28 14:34:08

The only solution is to use font.

  1. well for HW implementation I usually used EGA/VGA 8x8 font

    extracted from gfx card BIOS you can do it easy in MS-DOS environment

  2. another way is to extract font programaticaly from image

    draw entire font to bitmap (in line or in matrix ..., or use some already created like mine). Use fixed pitch, font size most suitable your needs and do not forget that almost none modern font supports fixed pitch so use OEM_CHARSET and System named font from it. Set color properly (ideal is black background and white font) and read image pixel by pixel and store it as table of numbers. Pixel with not background color is set pixel.

    Do not compare to font color because of anti-aliasing and filters. Now read all characters and set/res corresponding bit inside font table. First compute start x,y of character in image (from ASCII code and image organization) then do 2 nested 8-steps x,y for loops (in order according to your font[] organization)

    set/res corresponding font[] bits at addresses 8*ASCII to 8*ASCII+8

  3. I assume you use MCU to control LED panel

    the font organization in memory is usually that 8-bit number represents single row in character. Of course if your LED panel is meant to display animated scroll then column organization of font and also HW implementation will ease things up a lot. If you have 16 bit MCU and IO access than you can use 16-bit / pixels font size.

    if you have more than 8 pixels and only 8 bit MCU you can still use 16 bit data but the IO access will be in two steps via two IO ports instead of 1. I strongly recommend whole data-wide IO access instead of set/res individual IO lines its much quicker and can prevent flickering

OK here is my old 8x8 font I used back in the days ... I think this one is extracted from EGA/VGA BIOS but I am not shore ... it was too many years ago

Now the fun part

const BYTE font[8*256]={ 0,0,0,0,0,0,0,0, ... }

any character is represented as 8 numbers. if bit is 0 then it means paper (background pixel) if bit is 1 then it means ink (font pixel). Now there are more combinations (left to right, up to down and their combinations)

OK ( row-vise | left to right | up to down ) organization means:

  • first number is up most row of char
  • msb is left most pixel
  • lsb is right most pixel

so for example char '1' in 8x8 will be something like this (b means binary number):

00000000b,
00001000b,
00011000b,
00101000b,
00001000b,
00001000b,
00111100b,
00000000b,

When you have extracted all characters to font table than save it as source code to file which you will later include in your MCU code (can be placed in EEPROM for pgm-code)

Now the algorithm to print char on LED panel is strongly depended on your HW implementation

  • so please post a circuit diagram of interconnection between LED panel and control system
  • specify target platform and language
  • specify desired functionality

I assume you want left moving scroll by pixel step

  1. the best fit will be if your LED panel is driven by columns not rows

    You can activate single column of LEDs by some data IO port (all bits can be active at a time) and selecting which one column is active is driven by another select IO port (only single bit can be active at a time). So in this case compute the start address of the column to display in font table:

    • address = (8*ASCII + x_offset)
    • send font[8*ASCII + x_offset] to data IO port
    • activate select IO port with the correct bit active
    • wait a while (1-10ms) ... so you can actually see the light if delay is too short then there is no brightness if delay is too long then there is flickering so you need to experiment a little (depends on number of select bits).
    • deactivate select IO port
    • repeat with the next column
    • x_offset is the scrolling shift
  2. if your HW implementation does not fit in such way don't worry

    just use bit SHIFT,AND,OR operations to create the data words in memory and then send them in similar manner

Hope it helps a litle

You could try to find a font that looks the way you want (probably a monospaced font such as Courier), draw/rasterize it with a certain size (8pt?), without anti-aliasing, and convert the resulting image to your matrix format.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!