Is it possible to map data to values in C (for AVR)?

I am trying to make a USB 8x8 pixel LED screen that will display single characters received over serial emulation. I have a proof of concept device but due to my lack of knowledge of C I'm struggling slightly with a specific aspect of the code.

To display a character I need to take the 'source' char (such as 0x41) and look it up in the flash memory of the AVR, returning an array of chars (which will be used to render the character). It would be desirable for that information to reside in its own file (a Header perhaps?) - because this would enable multiple interchangeable fonts.

This is certainly possible in PIC micro-controller (I made a program utilising data blocks in Assembler a while ago for PIC) and I can't imagine that it's difficult on an Assembler level for AVR either, but I am unsure what I am looking for in the C language.

Any help would be appreciated,


P.S. I'm a Java programmer but new to C and AVR.

orksecurity7 years ago
C table lookup can be done with the [] array operator, or with pointer arithmetic. (These two syntaxes are actually translated very similarly, and can be used interchangably to some degree.) It sounds like what you want to is simply a 256-value-long array which contains or points to the rendering information. If the renderings are the same length in all cases, that would be a classic array-of-arrays-of-characters. If they're of varying length, and you don't want to allocate every row as the maximum length, an array-of-pointers-to-characters, where each pointer references the start of the appropriate data block (which is either tagged with its length or null-terminated or whatever) would do the job. Hitting a C tutorial with those keywords whould find plenty of examples. You can usually think of C as "high level assembler". If you can express it in assembler, you can usually implement it almost the same way in C.
andy (author)  orksecurity7 years ago
Literally slapped my forehead at that one - not sure how on Earth I missed that. I blame Java :P.

Thanks very much for the concise and fast response,