| ??? 12/15/08 07:39 Read: times |
#160934 - Table Lookup is Used Responding to: ???'s previous message |
It is normal practice that you would use a table to decode the character code and provide the resulting LED on/off pixel data for that character.
For example if your LED array has five columns of LEDs for each character position and it takes 8 pixels of on/off data in each column to specify the LED states then each character in the table can be represented by 5 bytes. Next decide on what coding scheme you want to use to represent each character code as received over the UART from the PC. A common scheme is to use the ASCII encoding as shown here: http://www.carousel-design.com/ASCII_Chart.html Lets say you decide to use ASCII and want to support just the 26 characters from "A" to "Z". What you need to do is gather the 5 bytes of pixel data for each of these characters and pack the 5 byte sets together in sequence into a byte array of 26*5=130 bytes. Arrange to put these into the code space and give the table some name like FONT_TABLE. Now whenever you receive a character A to Z from the UART port you can easily find its pixel pattern by taking the character and subtracting a constant from it so that if it was "A" you get 0, if it was "B" you get 1 and so forth. This resulting number can be thought of as a index for that character. Here is the formula to use for this example. Index = Char - 'A' ....where 'A' is the constant that I mentioned above. Next you multiply this index by 5 to get an offset in the FONT_TABLE. The 5 is due to fact that each font table entry has five bytes of pixels associated with it. The formula for this offset could be one of these: Offset = Index * 5 or Offset = (Index * 4) + Index or Offset = (Index SHL 2) + Index Once you have the offset you now need to make up a pointer to where the actual characters pixel data is located. The table name FONT_TABLE may be used directly as the address in code memory for the start of the table. You get the pointer by adding on the offset to the table address like: FontPtr = FONT_TABLE + Offset This FontPtr value may now be placed into the DPTR register and you may use the MOVC instruction to read the bytes of the decoded character into the ACC register. If you read in sequence five times each time followed by an INC DPTR you can read all 5 bytes of the pixel data for that character. While you loop to read the five bytes of the pixel data for the character you will move it to the appropriate location in the byte array that represents the actual display image. That should get you started at seeing how you can decode the received characters without having to write a CJNE for each character code received. Michael Karas |



