Electronic – Rotate a 7-segment display in firmware

7segmentdisplayavrhex

I have a board with a 7-segment display controlled by an AVR. I need to rotate the display's characters in the firmware, so that the display is read correctly when physically rotated 180 degrees.

Currently, the display has an output defined by:

#define SEVEN_SEGMENT_PATTERN_0     0x7B
#define SEVEN_SEGMENT_PATTERN_1     0x09
#define SEVEN_SEGMENT_PATTERN_2     0xB3
#define SEVEN_SEGMENT_PATTERN_3     0x9B
#define SEVEN_SEGMENT_PATTERN_4     0xC9
#define SEVEN_SEGMENT_PATTERN_5     0xDA
#define SEVEN_SEGMENT_PATTERN_6     0xFa
#define SEVEN_SEGMENT_PATTERN_7     0x0B
#define SEVEN_SEGMENT_PATTERN_8     0xFB
#define SEVEN_SEGMENT_PATTERN_9     0xDB

#define SEVEN_SEGMENT_PATTERN_A     0xEB
#define SEVEN_SEGMENT_PATTERN_B     0xF8
#define SEVEN_SEGMENT_PATTERN_C     0x72
#define SEVEN_SEGMENT_PATTERN_D     0xB9
#define SEVEN_SEGMENT_PATTERN_E     0xF2
#define SEVEN_SEGMENT_PATTERN_F     0xE2

#define SEVEN_SEGMENT_PATTERN_G     0xdb
#define SEVEN_SEGMENT_PATTERN_H     0xE9
#define SEVEN_SEGMENT_PATTERN_I     0x09
#define SEVEN_SEGMENT_PATTERN_J     0x19
#define SEVEN_SEGMENT_PATTERN_L     0x70
#define SEVEN_SEGMENT_PATTERN_O     0x7b
#define SEVEN_SEGMENT_PATTERN_P     0xe3
#define SEVEN_SEGMENT_PATTERN_R     0xa0
#define SEVEN_SEGMENT_PATTERN_S     0xda
#define SEVEN_SEGMENT_PATTERN_U     0x79

#define SEVEN_SEGMENT_PATTERN_DOT   0x04

Of course, I could use this to extract the pinout of the display and manually figure out the new definitions for flipped characters. However, this would be time consuming and I'm thinking that there must be a smarter way.

Some would remain the same when flipped, such as SEVEN_SEGMENT_PATTERN_0. Some will be easy to flip if I knew the pinout, such as SEVEN_SEGMENT_PATTERN_1.

Is there some smart algorithm or whatever that can help me calculate the flipped values?

Best Answer

Looks like the pinout is, from most to least significant bit, G F E D C dot A B. enter image description here

You could write some code along the lines of

rotatedChar=0;
if (char & 0x01) rotatedChar|=0x20;
if (char & 0x02) rotatedChar|=0x10;
// six more lines here.
Related Topic