lcd.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef HD44780_LCD_H_
  2. #define HD44780_LCD_H_
  3. #include "util.h"
  4. #include <stdint.h>
  5. /*** Hardware pin assignments ***/
  6. #define LCD_PORT PORTA /* LCD PORT register */
  7. #define LCD_DDR DDRA /* LCD DDR register */
  8. #define LCD_PIN_E (1u << 3u) /* E pin */
  9. #define LCD_PIN_RS (1u << 2u) /* RS pin */
  10. #define LCD_DATA_SHIFT 4u /* Data pins at D4-D7 */
  11. /*** Hardware parameters ***/
  12. #define LCD_NR_LINES 2u /* Linecount. Must be power of two. */
  13. #define LCD_NR_COLUMNS 16u /* Columncount. Must be power of two. */
  14. #define LCD_FONT_5x10 0u /* 5x10 or 5x8 font? */
  15. /*** Hardware access ***/
  16. void lcd_init(void);
  17. void lcd_commit(void);
  18. void lcd_cmd_cursor(uint8_t line, uint8_t column);
  19. void lcd_cmd_dispctl(uint8_t display_on,
  20. uint8_t cursor_on,
  21. uint8_t cursor_blink);
  22. void lcd_upload_char(uint8_t char_code,
  23. const uint8_t PROGPTR *char_tab);
  24. /*** Software buffer access ***/
  25. void lcd_put_char(char c);
  26. /** lcd_printf -- Formatted print to the LCD buffer. */
  27. void _lcd_printf(const char PROGPTR *_fmt, ...);
  28. #define lcd_printf(fmt, ...) _lcd_printf(PSTR(fmt) ,##__VA_ARGS__)
  29. /** lcd_put_str -- Write prog-str to LCD buffer. */
  30. void lcd_put_pstr(const char PROGPTR *str);
  31. #define lcd_put_str(str) lcd_put_pstr(PSTR(str))
  32. void lcd_clear_buffer(void);
  33. /** lcd_cursor - Move the LCD software cursor. */
  34. static inline void lcd_cursor(uint8_t line, uint8_t column)
  35. {
  36. extern uint8_t lcd_cursor_pos;
  37. lcd_cursor_pos = (uint8_t)((line * LCD_NR_COLUMNS) + column);
  38. }
  39. /** lcd_getline - Returns the current LCD software cursor line. */
  40. static inline uint8_t lcd_getline(void)
  41. {
  42. extern uint8_t lcd_cursor_pos;
  43. return lcd_cursor_pos / LCD_NR_COLUMNS;
  44. }
  45. /** lcd_getcolumn - Returns the current LCD software cursor column. */
  46. static inline uint8_t lcd_getcolumn(void)
  47. {
  48. extern uint8_t lcd_cursor_pos;
  49. return lcd_cursor_pos % LCD_NR_COLUMNS;
  50. }
  51. #endif /* HD44780_LCD_H_ */