What's the best way to do a lookup table in C? -
I am working on an embedded C project. I have an LCD display and 5x7 dot matrix for each character. I To display a specific character, you have to make a change in 5 bytes, which in turn are correlated with dots. So I need to create some sort of look-up table where I can pass in an ASCII character, and get an array of 5 bytes ... For example, call this function like this, < / P>
GetDisplayBytes ('A');
`An array like this should be returned ...
C [0] = 0x7E: C [1] = 0x90: C [2] = 0x90: c [3] = 0x90: c [4] = 0x7E
What would be the best way to do this in C?
I will create arrays for those ASCII blocks which you want to use. Information. Something like this:
uint8_t displayBytesLetters [] = {0x73, 0x90, 0x90, 0x90, 0x73, // 'A'. . . }; Uint8_t displayBytesDigits [] = {0x12, 0x15, 0x25, 0x58, 0x80, // '0'. . };
Then your GetDisplayBytes ()
is something like this:
uint8_t * GetDisplayBytes (char c) {if (isdigit (c) )) Returns and displaysbettes [5 * (C - '0')]; And if (Asperger (C)) Returns and displaysbettes [5 * (C - 'A')]; And return of return; }
Pass any function that returns the returned indicator:
Zero DoDisplay (uint8_t * displayBytes) {int i; (SendOutput (displayBytes [i]);}}