Microprocessor and peripheral 2 assignments for AUTH
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

190 lines
6.0 KiB

  1. /*!
  2. * \file alcd.c
  3. * \brief
  4. * A target independent Alpharithmetic LCD driver
  5. *
  6. * Copyright (C) 2014 Christos Choutouridis (http://www.houtouridis.net)
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as
  10. * published by the Free Software Foundation, either version 3
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef __alcd_h__
  23. #define __alcd_h__
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include "jiffies.h"
  28. #include "driver_types.h"
  29. #include <stdint.h>
  30. #include <string.h>
  31. #include <ctype.h>
  32. #include <time.h>
  33. /*
  34. * General Defines
  35. */
  36. #define ALCD_CLOCK (CLOCK)
  37. /*!
  38. * ----------------------------------------------------
  39. * Hitachi HD44780 - Samsung KS0066U
  40. * ----------------------------------------------------
  41. *
  42. *
  43. * Entry Mode Set -----> 0 0 0 0 0 1 I/D S
  44. * ----------------------------------------------------
  45. * I/D = 1 -->Inciment Curs I/D = 0 Decriment
  46. * S = 1 -->Display shift S = 0 Not
  47. *
  48. *
  49. * DispOnOffControll --> 0 0 0 0 1 D C B
  50. * -------------------------------------------------
  51. * D = Display On
  52. * C = Cursor On
  53. * B = Blinking On
  54. *
  55. *
  56. * Cursor/Display Shift --> 0 0 0 1 S/C R/L x x
  57. * ---------------------------------------------------
  58. * S/C = 1 -->Display Shift S/C = 0 -->Cursor Shift
  59. * R/L = 1 -->Shift Right R/L = 0 -->Shift left
  60. *
  61. *
  62. * FunctionSet ------> 0 0 1 DL N F x x
  63. * ---------------------------------------------------
  64. * DL = 1 -->8bit DL = 0 -->4bit
  65. * N = 1 -->2 lines N = 0 -->1 line
  66. * F = 1 -->5x10 dots F = 0 -->5x8 dots
  67. *
  68. */
  69. //#define LCD_LINES (4)
  70. //#define LCD_ROWS (16)
  71. #define LCD_CLRSCR (0x01) /*!< Clear Srean Command Number */
  72. #define LCD_RETHOME (0x02) /*!< Cursor home Un-Shift display DDRam as is */
  73. #define LCD_ENTRYMODE (0x06) /*!< Inc Cursor, Don't shift display */
  74. #define LCD_DISP_ON (0x0C) /*!< No Cursos and Blink */
  75. #define LCD_DISP_OFF (0x08)
  76. #define LCD_CUR_DISP (0x14) /*!< Cursor shift right */
  77. #define LCD_FUNSET_2L8 (0x28) /*!< 4bit, 2lines, 5x8 dots */
  78. #define LCD_FUNSET_1L8 (0x20) /*!< 4bit, 1lines, 5x8 dots */
  79. #define LCD_FUNSET_1L10 (0x24) /*!< 4bit, 1lines, 5x10 dots */
  80. #define LCD_SETCGRAMADDR (0x40)
  81. #define LCD_DDRAMMask (0x80) /*!< DDRAM ------------> 1 ADD[7..0] */
  82. #define LCD_BFMask (0x80) /*!< IR ------------> BF AC[6..0] */
  83. #define LCD_ACMask (0x7f) /*!< ____________________________| */
  84. #define LCD_SHIFT_RIGHT (0x1C)
  85. #define LCD_SHIFT_LEFT (0x18)
  86. typedef enum {
  87. ALCD_1Line_5x8 = LCD_FUNSET_1L8,
  88. ALCD_1Line_5x10 = LCD_FUNSET_1L10,
  89. ALCD_2Lines_5x8 = LCD_FUNSET_2L8
  90. } alcd_funset_en;
  91. /*!
  92. * Alpharithmetic LCD Cursor
  93. */
  94. typedef volatile struct
  95. {
  96. uint8_t x;
  97. uint8_t y;
  98. }alcd_cursor_t;
  99. /*!
  100. * Alpharithmetic LCD Pin assignements.
  101. * Each one can be called xx.DB4(1); or xx.DB4(0); in order to set
  102. * or clear the corresponding pin.
  103. *
  104. * \note These pointers MUST to be assigned from main application.
  105. */
  106. typedef volatile struct
  107. {
  108. //drv_pinout_ft db0;
  109. //drv_pinout_ft db1;
  110. //drv_pinout_ft db2;
  111. //drv_pinout_ft db3;
  112. drv_pinout_ft db4; /*!< Pointer for DB4 pin */
  113. drv_pinout_ft db5; /*!< Pointer for DB5 pin */
  114. drv_pinout_ft db6; /*!< Pointer for DB6 pin */
  115. drv_pinout_ft db7; /*!< Pointer for DB7 pin */
  116. drv_pinout_ft rs; /*!< Pointer for RS pin */
  117. drv_pinout_ft en; /*!< Pointer for EN pin */
  118. drv_pinout_ft bl; /*!< Pointer for Back Light pin*/
  119. }alcd_io_t;
  120. /*!
  121. * Alpharithmetic LCD Public Data struct
  122. */
  123. typedef volatile struct
  124. {
  125. alcd_io_t io; //!< Link to IO struct
  126. alcd_cursor_t c; //!< Link to Cursor struct
  127. uint8_t lines; //!< The lines of attached lcd
  128. uint8_t columns; //!< The columns of attached lcd
  129. //uint8_t bus; //!< Bus length, 4 or 8 bit
  130. drv_status_en status; //!< alcd driver status
  131. }alcd_t;
  132. /*
  133. * ============= PUBLIC ALCD API =============
  134. */
  135. /*
  136. * Link and Glue functions
  137. */
  138. void alcd_link_db4 (alcd_t *alcd, drv_pinout_ft pfun);
  139. void alcd_link_db5 (alcd_t *alcd, drv_pinout_ft pfun);
  140. void alcd_link_db6 (alcd_t *alcd, drv_pinout_ft pfun);
  141. void alcd_link_db7 (alcd_t *alcd, drv_pinout_ft pfun);
  142. void alcd_link_rs (alcd_t *alcd, drv_pinout_ft pfun);
  143. void alcd_link_en (alcd_t *alcd, drv_pinout_ft pfun);
  144. void alcd_link_bl (alcd_t *alcd, drv_pinout_ft pfun);
  145. int alcd_putchar (alcd_t *alcd, int ch);
  146. /*
  147. * Set functions
  148. */
  149. void alcd_set_lines (alcd_t *alcd, int lines);
  150. void alcd_set_columns (alcd_t *alcd, int columns);
  151. /*
  152. * User Functions
  153. */
  154. void alcd_deinit (alcd_t *alcd); /*!< For compatibility */
  155. drv_status_en alcd_init (alcd_t *alcd, alcd_funset_en fs); /*!< For compatibility */
  156. void alcd_backlight (alcd_t *alcd, uint8_t on); /*!< For compatibility */
  157. void alcd_enable (alcd_t *alcd, uint8_t on); /*!< For compatibility */
  158. void alcd_cls (alcd_t *alcd); /*!< For compatibility */
  159. void alcd_shift (alcd_t *alcd, int pos); /*!< For compatibility */
  160. void alcd_createChar (alcd_t *alcd, uint8_t location, uint8_t charmap[]);
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164. #endif //#ifndef __alcd_h__