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.
 
 
 
 
 
 

178 lines
5.4 KiB

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