3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

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,

Thanks,
Drew

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

2 answers
Aug 5, 2010. 6:06 PMorksecurity says:
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.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!