Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. /*******************************************
  2. File: lcd.c
  3. Description:
  4. Driver for an alphanumeric LCD with parallel interface. Only
  5. 4Bit interface is supported.
  6. *******************************************/
  7.  
  8. /*wenn im c file änderungen vorgenommen werden ohne das das h file included wird, dann überprüft der compiler nicht ob die prototypen
  9. vorhanden sind*/
  10.  
  11. #include "HTLStddef.h"
  12. #include "lcd.h"
  13. #include "lcd_constants.h"
  14.  
  15. /****************** Declaration of private funktions *******************/
  16. void LcdOut4Bit (unsigned char aByte);
  17. void LcdEnable(void);
  18. TBool LcdCommand(unsigned char);
  19. TBool LcdCheckBusy(void);
  20. TBool LcdReadBusyFlag(void);
  21. TBool LcdReadBusyFlag(void);
  22. unsigned char LcdReadAddress(void);
  23. unsigned char LcdRead4Bit(void);
  24.  
  25.  
  26. /****************** Public functions ************************/
  27.  
  28. void LcdInit(void) {
  29. LCD_PORT_DATA &= ~(1 << LCD_DB);
  30. LCD_DDR_DATA |= (1 << LCD_DB);
  31.  
  32. LCD_PORT_RS &= ~(1 << LCD_RS);
  33. LCD_DDR_RS |= (1 << LCD_RS);
  34.  
  35. LCD_PORT_RW &= ~(1 << LCD_RW);
  36. LCD_DDR_RW |= (1 << LCD_RW);
  37.  
  38. LCD_PORT_EN &= ~(1 << LCD_EN);
  39. LCD_DDR_EN |= (1 << LCD_EN);
  40.  
  41. //zeit zum hochfahren geben
  42. DelayMs(LCD_BOOTUP_MS);
  43.  
  44. // Software reset 3 times
  45. LcdOut4Bit(LCD_SOFT_RESET);
  46. DelayMs(LCD_SOFT_RESET_MS1);
  47. LcdOut4Bit(LCD_SOFT_RESET);
  48. DelayMs(LCD_SOFT_RESET_MS2);
  49. LcdOut4Bit(LCD_SOFT_RESET);
  50. DelayMs(LCD_SOFT_RESET_MS3);
  51.  
  52. /* Set to 4 bit mode*/
  53. LcdOut4Bit(LCD_SET_FUNCTION | LCD_FUNCTION_4BIT);
  54. DelayMs(LCD_SET_4BITMODE_MS);
  55.  
  56. /* Initialize 2 lines, 5x7 matrix */
  57. LcdCommand(LCD_SET_FUNCTION | LCD_FUNCTION_4BIT | LCD_FUNCTION_2LINE | LCD_FUNCTION_5X7);
  58.  
  59. /* Initialize cursor */
  60. LcdCommand(LCD_SET_DISPLAY | LCD_DISPLAY_ON | LCD_CURSOR_OFF | LCD_BLINKING_OFF);
  61.  
  62. LcdClear();
  63. }
  64.  
  65. void LcdWriteString(char* aString) {
  66. unsigned int i;
  67. for(i = 0; aString[i] != 0; i++){
  68. LcdWriteChar();
  69. }
  70. }
  71.  
  72. void LcdWriteChar(char aCharacter) {
  73. LCD_PORT_RS |= (1 << LCD_RS);
  74. LCD_PORT_RW &= ~(1 << LCD_RW);
  75.  
  76. LcdOut4Bit(aCharacter);
  77. LcdOut4Bit(aCharacter << 4);
  78. LcdCheckBusy();
  79. }
  80.  
  81. void LcdClear() {
  82. LcdCommand(LCD_CLEAR_DISPLAY);
  83. DelayMs(LCD_CLEAR_DISPLAY_MS);
  84. }
  85.  
  86. void LcdSetPosition(unsigned char aRow, unsigned char aColum) {
  87. int adr;
  88. switch(aColum){
  89. case 0:
  90. adr = LCD_DDADR_LINE1;
  91. break;
  92.  
  93. case 1:
  94. adr = LCD_DDADR_LINE2;
  95. break;
  96.  
  97. case 2:
  98. adr = LCD_DDADR_LINE3;
  99. break;
  100.  
  101. case 3:
  102. adr = LCD_DDADR_LINE4;
  103. break;
  104.  
  105. default:
  106. return;
  107. }
  108.  
  109. adr += aRow;
  110. LcdCommand(LCD_SET_DDADR + adr);
  111. }
  112.  
  113. /*************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement