Advertisement
phillip_bourdon234

LCD_Driver.h

Feb 28th, 2021
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.38 KB | None | 0 0
  1. /Here is an example of a custom character declaration
  2. //  uint8_t static battery[8] =
  3. //  {
  4. //      0x04,   //0b00000100,
  5. //      0x1F,   //0b00011111,
  6. //      0x11,   //0b00010001,
  7. //      0x11,   //0b00010001,
  8. //      0x1F,   //0b00011111,
  9. //      0x1F,   //0b00011111,
  10. //      0x1F,   //0b00011111,
  11. //      0x1F,   //0b00011111
  12. //  };
  13.  
  14. #ifndef LCD_Driver
  15. #define LCD_Driver
  16.  
  17. #include "stm32f10x.h"
  18. #include "system_stm32f10x.h"
  19. #include "GPIO_Driver.h"
  20.  
  21. #define EIGHT_BIT_MODE  0x30
  22. #define FOUR_BIT_MODE   0x28
  23. #define DISPLAY_OFF         0x08
  24. #define DISPLAY_CLEAR   0x01
  25. #define EM_INCREMENT        0x06
  26. #define EM_DECREMENT        0x04
  27. #define DISPLAY_ON_CON  0x0F
  28. #define DISPLAY_ON_COFF 0x0C
  29. #define SHIFT_RIGHT         0x14
  30. #define SHIFT_LEFT          0x10
  31.  
  32. //The lcd_init function initizlizees the LCD to the following modes:
  33. // - four pin operation
  34. // - increment mode
  35. // - display on with the cursor off
  36. //The user passes in the desired ports and pins that correlate to the different
  37. //pins on the LCD screen. The lcd_init function will handle the gpio initilzation as well
  38. void lcd_init(GPIO_TypeDef *D4port, uint8_t D4pin, GPIO_TypeDef *D5port, uint8_t D5pin,
  39.                             GPIO_TypeDef *D6port, uint8_t D6pin, GPIO_TypeDef *D7port, uint8_t D7pin,
  40.                             GPIO_TypeDef *ENport, uint8_t ENpin, GPIO_TypeDef *RWport, uint8_t RWpin,
  41.                             GPIO_TypeDef *RSport, uint8_t RSpin);
  42.  
  43. //The lcd_clock function writes a logical 1 to the EN pin for 1 ms and then writes a logical 0 to
  44. //the EN pin and waits for 1 ms. This satisfies the timing requiremnts in the datasheet for
  45. //my LCD module (HD44780U). This should be called whenever data wants to be sent to the LCD module
  46. //NOTE: all the functions include this command so the user rarely ever calls this function
  47. void lcd_clock(void);
  48.  
  49. //The lcd_command function takes in a byte that corresponds to a specific LCD command. This
  50. //function is different from the lcd_write_char function based on the fact that in the datasheet,
  51. //it says that a command is written when the RS pin is low, where as a character is written when the
  52. //RS pin is high
  53. void lcd_command(uint8_t command);
  54.  
  55. //The lcd_write_char function takes in a byte that corresponds to a character in the
  56. //LCDs DDRAM or CGRAM and prints it on the screen
  57. void lcd_write_char(uint8_t character);
  58.  
  59. //The write number function takes a number with the size of 2 bytes and prints out the correct
  60. //number onto the screen. This function handles the converstion from a regular variable to
  61. //appropriate characters in the LCDs DDRAM
  62. void lcd_write_number(uint16_t number);
  63.  
  64. //The lcd_set_cursor function sets the position of the lcd cursor to the user specified position
  65. //(row first, then collumn)
  66. void lcd_set_cursor(uint8_t yPos, uint8_t xPos);
  67.  
  68. //The lcd_clear function writes an empty space character to the user specfied position. For
  69. //example, if the user wants to clear the entire first row, the user would say
  70. //lcd_clear(0, 0, 16)
  71. void lcd_clear(uint8_t row, uint8_t start_collumn, uint8_t end_collumn);
  72.  
  73. //The lcd_create_character function takes in an address (0-7) and a "character" pointer that
  74. //is defined by the user (an example of this can be found at the top of the header file.
  75. //The function then loads the character inside the LCDs CGRAM and can be displayed by calling
  76. //the lcd_write_char function with the input being the address of the character (0-7)
  77. void lcd_create_character(uint8_t address, uint8_t *character);
  78.  
  79.  
  80. #endif
  81.  
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement