1-Wire tester, shows ROM code and temperature on an LCD screen

lcd.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #pragma once
  2. // HD44780 LCD display driver - 4-bit mode
  3. //
  4. // LCD pins are configured using a file lcd_config.h, which you
  5. // have to add next to your main.c file.
  6. //
  7. // Content can be something like this:
  8. //
  9. //
  10. #include <stdint.h>
  11. #include <stdbool.h>
  12. #define LCD_RS D2
  13. #define LCD_RW D3
  14. #define LCD_E D4
  15. #define LCD_D4 D5
  16. #define LCD_D5 D6
  17. #define LCD_D6 D7
  18. #define LCD_D7 D8
  19. // --- Commands ---
  20. // Clear screen (reset)
  21. #define LCD_CLEAR 0b00000001
  22. // Move cursor to (0,0), unshift...
  23. #define LCD_HOME 0b00000010
  24. // Set mode: Increment + NoShift
  25. #define LCD_MODE_INC 0b00000110
  26. // Set mode: Increment + Shift
  27. #define LCD_MODE_INC_SHIFT 0b00000111
  28. // Set mode: Decrement + NoShift
  29. #define LCD_MODE_DEC 0b00000100
  30. // Set mode: Decrement + Shift
  31. #define LCD_MODE_DEC_SHIFT 0b00000101
  32. // Disable display (data remains untouched)
  33. #define LCD_DISABLE 0b00001000
  34. // Disable cursor
  35. #define LCD_CURSOR_NONE 0b00001100
  36. // Set cursor to still underscore
  37. #define LCD_CURSOR_BAR 0b00001110
  38. // Set cursor to blinking block
  39. #define LCD_CURSOR_BLINK 0b00001101
  40. // Set cursor to both of the above at once
  41. #define LCD_CURSOR_BOTH (LCD_CURSOR_BAR | LCD_CURSOR_BLINK)
  42. // Move cursor
  43. #define LCD_MOVE_LEFT 0b00010000
  44. #define LCD_MOVE_RIGHT 0b00010100
  45. // Shift display
  46. #define LCD_SHIFT_LEFT 0b00011000
  47. #define LCD_SHIFT_RIGHT 0b00011100
  48. // Set iface to 5x7 font, 1-line
  49. #define LCD_IFACE_4BIT_1LINE 0b00100000
  50. #define LCD_IFACE_8BIT_1LINE 0b00110000
  51. // Set iface to 5x7 font, 2-line
  52. #define LCD_IFACE_4BIT_2LINE 0b00101000
  53. #define LCD_IFACE_8BIT_2LINE 0b00111000
  54. extern const uint8_t LCD_ROW_ADDR[4];
  55. /** Initialize the display */
  56. void lcd_init();
  57. /** Write an instruction byte */
  58. void lcd_command(uint8_t bb);
  59. /** Write a data byte */
  60. void lcd_write(uint8_t bb);
  61. /** Read BF & Address */
  62. uint8_t lcd_read_bf_addr();
  63. /** Read CGRAM or DDRAM */
  64. uint8_t lcd_read();
  65. /** Send a string to LCD */
  66. void lcd_puts(char* str_p);
  67. /** Send a string to LCD from program memory */
  68. void lcd_puts_P(const char* str_p);
  69. /** Sedn a char to LCD */
  70. void lcd_putc(const char c);
  71. /** Show string at X, Y */
  72. #define lcd_puts_xy(x, y, str_p) do { lcd_xy((x), (y)); lcd_puts((str_p)); } while(0)
  73. /** Show string at X, Y */
  74. #define lcd_puts_xy_P(x, y, str_p) do { lcd_xy((x), (y)); lcd_puts_P((str_p)); } while(0)
  75. /** Show char at X, Y */
  76. #define lcd_putc_xy(x, y, c) do { lcd_xy((x), (y)); lcd_putc((c)); } while(0)
  77. /** Set cursor position */
  78. void lcd_xy(const uint8_t x, const uint8_t y);
  79. /** Set LCD cursor. If not enabled, only remember it. */
  80. #define CURSOR_NONE 0b00
  81. #define CURSOR_BAR 0b10
  82. #define CURSOR_BLINK 0b01
  83. #define CURSOR_BOTH 0b11
  84. void lcd_cursor(uint8_t type);
  85. /** Display display (preserving cursor) */
  86. void lcd_disable();
  87. /** Enable display (restoring cursor) */
  88. void lcd_enable();
  89. /** Go home */
  90. void lcd_home();
  91. /** Clear the screen */
  92. void lcd_clear();
  93. /** Define a glyph - 8 bytes, right 5 bits are used */
  94. void lcd_glyph(const uint8_t index, const uint8_t* array);
  95. /** Define a glyph that's in PROGMEM */
  96. void lcd_glyph_P(const uint8_t index, const uint8_t* array);
  97. /** Set address in CGRAM */
  98. void lcd_addr_cg(const uint8_t acg);
  99. /** Set address in DDRAM */
  100. void lcd_addr(const uint8_t add);