Advertisement
Guest User

Untitled

a guest
Apr 18th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | Source Code | 0 0
  1. typedef struct
  2. {
  3.   int d0, d1, d2, d3, d4, d5, d6, d7;
  4.   int is_4bits;
  5. } lcd_module;
  6.  
  7. void lcd_attach(lcd_module* lcd)
  8. {
  9.   if (lcd->is_4bits)
  10.   {
  11.     // Attach 4 bits
  12.   }
  13.   else
  14.   {
  15.     // Attach 8 bits
  16.   }
  17. }
  18.  
  19. void lcd_send_cmd(lcd_module* lcd, int cmd)
  20. {
  21.   if (lcd->is_4bits)
  22.   {
  23.     // Send 4 bits command
  24.   }
  25.   else
  26.   {
  27.     // Send 8 bits command
  28.   }
  29. }
  30.  
  31. int main(void)
  32. {
  33.   lcd_module lcd4;
  34.   lcd_module lcd8;
  35.  
  36.   // Setup
  37.   lcd4.d4 = 1;
  38.   lcd4.is_4bits = 1;
  39.  
  40.   lcd8.d0 = 2;
  41.   lcd8.is_4bits = 0;
  42.   // Etc
  43.  
  44.   // Attach
  45.   lcd_attach(&lcd4);
  46.   lcd_attach(&lcd8);
  47.   return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement