0

I am trying to set a Nokia LCD screen to turn all pixels off, all pixels on, inverse mode on and normal mode on, depending on which button the user pushes. I have all the code complete apart for setting the mode of the LCD screen. This is because they are displayed as enumerated type structs and I am not familiar with either concepts. The struct is:

typedef enum lcd_display_mode_t {
    lcd_display_all_off = 0b000,
    lcd_display_all_on  = 0b001,
    lcd_display_normal  = 0b100,
    lcd_display_inverse = 0b101,
} lcd_display_mode_t;

My best guess is that, being a enumerate type, I would simply have to type:

if SWITCH X IS ON{
    lcd_display_mode_t = 0;
}

Which would set the display mode to lcd_display_all_off. Is this the correct use of structs in this context? If not, what would I type to set the display modes?

david_10001
  • 492
  • 1
  • 6
  • 22

1 Answers1

3

An enum is not a struct. Using enums for storing binary data is a bad idea. One gets all kinds of weird side effects such as the type used being a signed int - which in turn is entirely unsuitable for the kind of hardware-related programming it will be used for. In addition, binary literals are not even standard C.

Note that the typedef makes lcd_display_mode_t a type, not a variable. Whoever wrote the code was a bit confused, it would be sufficient to just write typedef enum { ... } lcd_display_mode_t;.

They intended you to use the code like this:

lcd_display_mode_t mode;
...
mode = lcd_display_all_off;
Lundin
  • 195,001
  • 40
  • 254
  • 396
  • So if I had to put an if statement in there like I have done above, what would it look like? i.e. if this switch is on, then this mode is x... – david_10001 May 09 '18 at 12:54
  • @david_10001 You use it like any other variable. – Lundin May 09 '18 at 12:58
  • Ohh I think I get it. So I declare it like you have, with mode being the variable? And then treat that as any other variable in my if statement? You're right, the way they have stored the data s a bit confusing – david_10001 May 09 '18 at 13:00