lcd.h 2.1 KB

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