lcd.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * lcd.h
  3. *
  4. * Created on: 10/06/2018
  5. * Author: Olivier Van den Eede
  6. */
  7. #ifndef LCD_H_
  8. #define LCD_H_
  9. #include "stm32f4xx_hal.h"
  10. #include "string.h"
  11. #include "main.h"
  12. // #define LCD20xN // For 20xN LCDs
  13. #define LCD16xN // For 16xN LCDs
  14. // For row start addresses
  15. extern const uint8_t ROW_16[];
  16. extern const uint8_t ROW_20[];
  17. /************************************** Command register **************************************/
  18. #define CLEAR_DISPLAY 0x01
  19. #define RETURN_HOME 0x02
  20. #define ENTRY_MODE_SET 0x04
  21. #define OPT_S 0x01 // Shift entire display to right
  22. #define OPT_INC 0x02 // Cursor increment
  23. #define DISPLAY_ON_OFF_CONTROL 0x08
  24. #define OPT_D 0x04 // Turn on display
  25. #define OPT_C 0x02 // Turn on cursor
  26. #define OPT_B 0x01 // Turn on cursor blink
  27. #define CURSOR_DISPLAY_SHIFT 0x10 // Move and shift cursor
  28. #define OPT_SC 0x08
  29. #define OPT_RL 0x04
  30. #define FUNCTION_SET 0x20
  31. #define OPT_DL 0x10 // Set interface data length
  32. #define OPT_N 0x08 // Set number of display lines
  33. #define OPT_F 0x04 // Set alternate font
  34. #define SET_DDRAM_ADDR 0x80 // Set DDRAM address
  35. /************************************** Helper macros **************************************/
  36. #define DELAY(X) HAL_Delay(X)
  37. /************************************** LCD defines **************************************/
  38. #define LCD_NIB 4
  39. #define LCD_BYTE 8
  40. #define LCD_DATA_REG 1
  41. #define LCD_COMMAND_REG 0
  42. /************************************** LCD typedefs **************************************/
  43. #define Lcd_PortType GPIO_TypeDef*
  44. #define Lcd_PinType uint16_t
  45. typedef enum {
  46. LCD_4_BIT_MODE,
  47. LCD_8_BIT_MODE
  48. } Lcd_ModeTypeDef;
  49. typedef struct {
  50. Lcd_PortType * data_port;
  51. Lcd_PinType * data_pin;
  52. Lcd_PortType rs_port;
  53. Lcd_PinType rs_pin;
  54. Lcd_PortType en_port;
  55. Lcd_PinType en_pin;
  56. Lcd_ModeTypeDef mode;
  57. } Lcd_HandleTypeDef;
  58. /************************************** Public functions **************************************/
  59. void Lcd_init(Lcd_HandleTypeDef * lcd);
  60. void Lcd_int(Lcd_HandleTypeDef * lcd, int number);
  61. void Lcd_string(Lcd_HandleTypeDef * lcd, char * string);
  62. void Lcd_cursor(Lcd_HandleTypeDef * lcd, uint8_t row, uint8_t col);
  63. Lcd_HandleTypeDef Lcd_create(
  64. Lcd_PortType port[], Lcd_PinType pin[],
  65. Lcd_PortType rs_port, Lcd_PinType rs_pin,
  66. Lcd_PortType en_port, Lcd_PinType en_pin, Lcd_ModeTypeDef mode);
  67. #endif /* LCD_H_ */