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.
 
 
 
 

740 rivejä
17 KiB

  1. /**
  2. * ---------------------------------------------------------------+
  3. * @desc HD44780 LCD Driver
  4. * ---------------------------------------------------------------+
  5. * Copyright (C) 2020 Marian Hrinko.
  6. * Written by Marian Hrinko (mato.hrinko@gmail.com)
  7. *
  8. * @author Marian Hrinko
  9. * @datum 18.11.2020
  10. * @file hd44780.c
  11. * @tested AVR Atmega16a
  12. *
  13. * @depend hd44780.h
  14. * ---------------------------------------------------------------+
  15. * @usage default set 16x2 LCD
  16. * 4-bit with 3 control wires (RW, RS, E)
  17. */
  18. // include libraries
  19. #include <stdio.h>
  20. //#include <util/delay.h>
  21. //#include <avr/io.h>
  22. #include "define.h"
  23. #include "BoardCfg.h"
  24. #include "hd44780.h"
  25. #include "timer.h"
  26. // +---------------------------+
  27. // | Power on |
  28. // | Wait for more than 15 ms | // 15 ms wait
  29. // | after VCC rises to 4.5 V |
  30. // +---------------------------+
  31. // |
  32. // +---------------------------+
  33. // | RS R/W DB7 DB6 DB5 DB4 |
  34. // | 0 0 0 0 1 1 | // Initial sequence 0x30
  35. // | Wait for more than 4.1 ms | // 4.1 ms us writing DATA into DDRAM or CGRAM
  36. // +---------------------------+
  37. // |
  38. // +---------------------------+
  39. // | RS R/W DB7 DB6 DB5 DB4 |
  40. // | 0 0 0 0 1 1 | // Initial sequence 0x30
  41. // | Wait for more than 0.1 ms | // 100 us writing DATA into DDRAM or CGRAM
  42. // +---------------------------+
  43. // |
  44. // +---------------------------+
  45. // | RS R/W DB7 DB6 DB5 DB4 | // Initial sequence 0x30
  46. // | 0 0 0 0 1 1 | // 37 us writing DATA into DDRAM or CGRAM 4 us tadd - time after busy flag disapeared
  47. // | Wait for more than 45 us | // 37 us + 4 us = 41 us * (270/250) = 45us
  48. // +---------------------------+
  49. // |
  50. // +---------------------------+ // 4bit mode 0x20 !!! MUST BE SET TIME, BF CHECK DOESN'T WORK CORRECTLY !!!
  51. // | RS R/W DB7 DB6 DB5 DB4 | //
  52. // | 0 0 0 0 1 0 | // 37 us writing DATA into DDRAM or CGRAM 4 us tadd - time after busy flag disapeared
  53. // | Wait for more than 45 us | // !!! MUST BE SET DELAY TIME, BUSY FLAG CHECK DOESN'T WORK CORRECTLY !!!
  54. // +---------------------------+
  55. // |
  56. // +---------------------------+
  57. // | RS R/W DB7 DB6 DB5 DB4 | // Display off 0x08
  58. // | 0 0 0 0 1 0 | //
  59. // | 0 0 1 0 0 0 | //
  60. // | Wait for BF Cleared | // Wait for BF Cleared
  61. // +---------------------------+
  62. // |
  63. // +---------------------------+
  64. // | RS R/W DB7 DB6 DB5 DB4 | // Display clear 0x01
  65. // | 0 0 0 0 0 0 | //
  66. // | 0 0 0 0 0 1 | //
  67. // | Wait for BF Cleared | // Wait for BF Cleared
  68. // +---------------------------+
  69. // |
  70. // +---------------------------+
  71. // | RS R/W DB7 DB6 DB5 DB4 | // Entry mode set 0x06
  72. // | 0 0 0 0 0 0 | //
  73. // | 0 0 0 1 1 0 | // shift cursor to the left, without text shifting
  74. // | Wait for BF Cleared | // Wait for BF Cleared
  75. // +---------------------------+
  76. /**
  77. * @desc LCD display clear
  78. *
  79. * @param void
  80. *
  81. * @return void
  82. */
  83. void HD44780_DisplayClear (void)
  84. {
  85. // Diplay clear
  86. HD44780_SendInstruction(HD44780_DISP_CLEAR);
  87. }
  88. /**
  89. * @desc LCD display on
  90. *
  91. * @param void
  92. *
  93. * @return void
  94. */
  95. void HD44780_DisplayOn (void)
  96. {
  97. // send instruction - display on
  98. HD44780_SendInstruction(HD44780_DISP_ON);
  99. }
  100. /**
  101. * @desc LCD cursor on, display on
  102. *
  103. * @param void
  104. *
  105. * @return void
  106. */
  107. void HD44780_CursorOn (void)
  108. {
  109. // send instruction - cursor on
  110. HD44780_SendInstruction(HD44780_CURSOR_ON);
  111. }
  112. /**
  113. * @desc LCD cursor off
  114. *
  115. * @param void
  116. *
  117. * @return void
  118. */
  119. void HD44780_CursorOff (void)
  120. {
  121. // send instruction - cursor on
  122. HD44780_SendInstruction(HD44780_CURSOR_OFF);
  123. }
  124. /**
  125. * @desc LCD cursor blink, cursor on, display on
  126. *
  127. * @param void
  128. *
  129. * @return void
  130. */
  131. void HD44780_CursorBlink (void)
  132. {
  133. // send instruction - Cursor blink
  134. HD44780_SendInstruction(HD44780_CURSOR_BLINK);
  135. }
  136. /**
  137. * @desc LCD draw char
  138. *
  139. * @param char
  140. *
  141. * @return void
  142. */
  143. void HD44780_DrawChar (char character)
  144. {
  145. // Diplay clear
  146. HD44780_SendData(character);
  147. }
  148. /**
  149. * @desc LCD draw string
  150. *
  151. * @param char *
  152. *
  153. * @return void
  154. */
  155. void HD44780_DrawString (char *str)
  156. {
  157. unsigned char i = 0;
  158. // loop through 5 bytes
  159. while (str[i] != '\0') {
  160. //read characters and increment index
  161. HD44780_SendData(str[i++]);
  162. }
  163. }
  164. /**
  165. * @desc Got to position x,y
  166. *
  167. * @param char
  168. * @param char
  169. *
  170. * @return char
  171. */
  172. char HD44780_PositionXY (char x, char y)
  173. {
  174. if (x > HD44780_COLS || y > HD44780_ROWS) {
  175. // error
  176. return ERROR;
  177. }
  178. // check which row
  179. if (y == 0) {
  180. // send instruction 1st row
  181. HD44780_SendInstruction(HD44780_POSITION | (HD44780_ROW1_START + x));
  182. } else if (y == 1) {
  183. // send instruction 2nd row
  184. HD44780_SendInstruction(HD44780_POSITION | (HD44780_ROW2_START + x));
  185. }
  186. // success
  187. return 0;
  188. }
  189. /**
  190. * @desc Shift cursor / display to left / right
  191. *
  192. * @param char item {HD44780_CURSOR; HD44780_DISPLAY}
  193. * @param char direction {HD44780_RIGHT; HD44780_LEFT}
  194. *
  195. * @return char
  196. */
  197. char HD44780_Shift (char item, char direction)
  198. {
  199. // check if item is cursor or display or direction is left or right
  200. if ((item != HD44780_DISPLAY) && (item != HD44780_CURSOR)) {
  201. // error
  202. return ERROR;
  203. }
  204. // check if direction is left or right
  205. if ((direction != HD44780_RIGHT) && (direction != HD44780_LEFT)) {
  206. // error
  207. return ERROR;
  208. }
  209. // cursor shift
  210. if (item == HD44780_CURSOR) {
  211. // right shift
  212. if (direction == HD44780_RIGHT) {
  213. // shit cursor / display to right / left
  214. HD44780_SendInstruction(HD44780_SHIFT | HD44780_CURSOR | HD44780_RIGHT);
  215. } else {
  216. // shit cursor / display to right / left
  217. HD44780_SendInstruction(HD44780_SHIFT | HD44780_CURSOR | HD44780_LEFT);
  218. }
  219. // display shift
  220. } else {
  221. // right shift
  222. if (direction == HD44780_RIGHT) {
  223. // shit cursor / display to right / left
  224. HD44780_SendInstruction(HD44780_SHIFT | HD44780_DISPLAY | HD44780_RIGHT);
  225. } else {
  226. // shit cursor / display to right / left
  227. HD44780_SendInstruction(HD44780_SHIFT | HD44780_DISPLAY | HD44780_LEFT);
  228. }
  229. }
  230. // success
  231. return 0;
  232. }
  233. /**
  234. * @desc LCD init - initialisation routine
  235. *
  236. * @param void
  237. *
  238. * @return void
  239. */
  240. void HD44780_Init (void)
  241. {
  242. // set E as output
  243. //SETBIT(HD44780_DDR_E, HD44780_E);
  244. // set RS as output
  245. //SETBIT(HD44780_DDR_RS, HD44780_RS);
  246. // set RW as output
  247. //SETBIT(HD44780_DDR_RW, HD44780_RW);
  248. // set DB7-DB4 as output
  249. // HD44780_SetDDR_DATA4to7();
  250. // clear RS
  251. // CLRBIT(HD44780_PORT_RS, HD44780_RS);
  252. LCD_RS_PIN = 0;
  253. // clear RW
  254. // CLRBIT(HD44780_PORT_RW, HD44780_RW);
  255. LCD_RW_PIN = 0;
  256. // clear E
  257. // CLRBIT(HD44780_PORT_E, HD44780_E);
  258. LCD_E_PIN = 0;
  259. // delay > 15ms
  260. _delay_ms(16);
  261. // Busy Flag (BF) cannot be checked in these instructions
  262. // ---------------------------------------------------------------------
  263. // Initial sequence 0x30 - send 4 bits in 4 bit mode
  264. // HD44780_SendInstruction(HD44780_INIT_SEQ);JFM
  265. HD44780_Send4bitsIn4bitMode(HD44780_INIT_SEQ);
  266. // delay > 4.1ms
  267. _delay_ms(5);
  268. // pulse E
  269. //HD44780_PulseE();
  270. // delay > 100us
  271. _delay_us(110);
  272. HD44780_Send4bitsIn4bitMode(HD44780_INIT_SEQ);
  273. // pulse E
  274. // HD44780_PulseE();
  275. // delay > 45us (=37+4 * 270/250)
  276. _delay_us(50);
  277. HD44780_Send4bitsIn4bitMode(HD44780_INIT_SEQ);
  278. // 4 bit mode 0x20 - send 4 bits in 4 bit mode
  279. HD44780_Send4bitsIn4bitMode(HD44780_4BIT_MODE);
  280. // pulse E
  281. //HD44780_PulseE();
  282. // delay > 45us (=37+4 * 270/250)
  283. _delay_us(50);
  284. // ----------------------------------------------------------------------
  285. // 4-bit & 2-lines & 5x8-dots 0x28 - send 8 bits in 4 bit mode
  286. HD44780_SendInstruction(HD44780_4BIT_MODE | HD44780_2_ROWS | HD44780_FONT_5x8);
  287. // display off 0x08 - send 8 bits in 4 bit mode
  288. HD44780_SendInstruction(HD44780_DISP_OFF);
  289. // display clear 0x01 - send 8 bits in 4 bit mode
  290. HD44780_SendInstruction(HD44780_DISP_CLEAR);
  291. // entry mode set 0x06 - send 8 bits in 4 bit mode
  292. HD44780_SendInstruction(HD44780_ENTRY_MODE);
  293. }
  294. /**
  295. * @desc Check Busy Flag (BF) in 4 bit mode
  296. *
  297. * @param void
  298. *
  299. * @return void
  300. */
  301. void HD44780_CheckBFin4bitMode (void)
  302. {
  303. unsigned char input = 0;
  304. Sleep(5);
  305. return;
  306. // clear DB7-DB4 as input
  307. HD44780_ClearDDR_DATA4to7();
  308. // set pull-up resistors for DB7-DB4
  309. // HD44780_SetPORT_DATA4to7();
  310. // clear RS
  311. // CLRBIT(HD44780_PORT_RS, HD44780_RS);
  312. LCD_RS_PIN = 0;
  313. // set RW - read instruction
  314. // SETBIT(HD44780_PORT_RW, HD44780_RW);
  315. LCD_RW_PIN = 1;
  316. // test HIGH level on PIN DB7
  317. // after clear PIN DB7 should continue
  318. // -------------------------------------
  319. // us: 0.5|0.5|0.5
  320. // ___ ___
  321. // E: ___/ \___/ \__
  322. // ___ ___
  323. // DB7: \___/ \___/ \__
  324. //
  325. while (1) {
  326. // Read upper nibble
  327. // --------------------------------
  328. // Set E
  329. // SETBIT(HD44780_PORT_E, HD44780_E);
  330. LCD_E_PIN = 1;
  331. // PWeh > 0.5us
  332. _delay_us(0.5);
  333. // read upper nibble (tDDR > 360ns)
  334. input = HD44780_PIN_DATA;
  335. // Clear E
  336. // CLRBIT(HD44780_PORT_E, HD44780_E);
  337. LCD_E_PIN = 0;
  338. // TcycE > 1000ns -> delay depends on PWeh delay time
  339. // delay = TcycE - PWeh = 1000 - 500 = 500ns
  340. _delay_us(0.5);
  341. // Read lower nibble
  342. // --------------------------------
  343. // Set E
  344. // SETBIT(HD44780_PORT_E, HD44780_E);
  345. LCD_E_PIN = 1;
  346. // PWeh > 0.5us
  347. _delay_us(0.5);
  348. // read lower nibble (tDDR > 360ns)
  349. //input |= (unsigned char)(HD44780_PIN_DATA >> 4);
  350. char IsBusy = (HD44780_DATA7 == 1);
  351. // Clear E
  352. // CLRBIT(HD44780_PORT_E, HD44780_E);
  353. LCD_E_PIN = 0;
  354. // TcycE > 1000ns -> delay depends on PWeh delay time
  355. // delay = TcycE - PWeh = 1000 - 500 = 500ns
  356. _delay_us(0.5);
  357. // // check if DB7 is cleared
  358. // if (!(input & (1 << HD44780_DATA7)))
  359. if (IsBusy == 0)
  360. {
  361. // if BF cleared -> end loop
  362. break;
  363. }
  364. }
  365. // clear RW
  366. // CLRBIT(HD44780_PORT_RW, HD44780_RW);
  367. LCD_RW_PIN = 0;
  368. // set DB7-DB4 as output
  369. HD44780_SetDDR_DATA4to7();
  370. }
  371. /**
  372. * @desc Check Busy Flag (BF) in 8 bit mode
  373. *
  374. * @param void
  375. * @return void
  376. */
  377. void HD44780_CheckBFin8bitMode (void)
  378. {
  379. }
  380. /**
  381. * @desc LCD send instruction
  382. *
  383. * @param unsigned short int
  384. *
  385. * @return void
  386. */
  387. void HD44780_SendInstruction (unsigned short int data)
  388. {
  389. // Clear RS
  390. // HD44780_PORT_RS &= ~(1 << HD44780_RS);
  391. LCD_RS_PIN = 0;
  392. // 4bit mode
  393. // ------------------------------------------
  394. if (HD44780_MODE == HD44780_4BIT_MODE) {
  395. // send required data in required mode
  396. HD44780_Send8bitsIn4bitMode(data);
  397. // check busy flag
  398. HD44780_CheckBFin4bitMode();
  399. // 8 bit mode
  400. // ------------------------------------------
  401. } else if (HD44780_MODE == HD44780_8BIT_MODE) {
  402. // send required data in required mode
  403. HD44780_Send8bitsIn8bitMode(data);
  404. // check busy flag
  405. HD44780_CheckBFin8bitMode();
  406. }
  407. }
  408. /**
  409. * @desc LCD send data
  410. *
  411. * @param unsigned short int
  412. *
  413. * @return void
  414. */
  415. void HD44780_SendData (unsigned short int data)
  416. {
  417. // Set RS
  418. // SETBIT(HD44780_PORT_RS, HD44780_RS);
  419. LCD_RS_PIN = 1;
  420. // 4bit mode
  421. // ------------------------------------------
  422. if (HD44780_MODE == HD44780_4BIT_MODE) {
  423. // send required data in required mode
  424. HD44780_Send8bitsIn4bitMode(data);
  425. // check busy flag
  426. HD44780_CheckBFin4bitMode();
  427. // 8 bit mode
  428. // ------------------------------------------
  429. } else if (HD44780_MODE == HD44780_8BIT_MODE) {
  430. // send required data in required mode
  431. HD44780_Send8bitsIn8bitMode(data);
  432. // check busy flag
  433. HD44780_CheckBFin8bitMode();
  434. }
  435. // Clear RS
  436. // CLRBIT(HD44780_PORT_RS, HD44780_RS);
  437. LCD_RS_PIN = 0;
  438. }
  439. /**
  440. * @desc LCD send 4bits instruction in 4 bit mode
  441. *
  442. * @param unsigned short int
  443. *
  444. * @return void
  445. */
  446. void HD44780_Send4bitsIn4bitMode (unsigned short int data)
  447. {
  448. // Set E
  449. // SETBIT(HD44780_PORT_E, HD44780_E);
  450. LCD_E_PIN = 1;
  451. // send data to LCD
  452. HD44780_SetUppNibble(data);
  453. // PWeh delay time > 450ns
  454. _delay_us(0.5);
  455. // Clear E
  456. // CLRBIT(HD44780_PORT_E, HD44780_E);
  457. LCD_E_PIN = 0;
  458. // TcycE > 1000ns -> delay depends on PWeh delay time
  459. // delay = TcycE - PWeh = 1000 - 500 = 500ns
  460. _delay_us(0.5);
  461. }
  462. /**
  463. * @desc LCD send 8bits instruction in 4 bit mode
  464. *
  465. * @param unsigned short int
  466. *
  467. * @return void
  468. */
  469. void HD44780_Send8bitsIn4bitMode (unsigned short int data)
  470. {
  471. // Send upper nibble
  472. // ----------------------------------
  473. // Set E
  474. // SETBIT(HD44780_PORT_E, HD44780_E);
  475. LCD_E_PIN = 1;
  476. // send data to LCD
  477. HD44780_SetUppNibble(data);
  478. // PWeh delay time > 450ns
  479. _delay_us(0.5);
  480. // Clear E
  481. // CLRBIT(HD44780_PORT_E, HD44780_E);
  482. LCD_E_PIN = 0;
  483. // TcycE > 1000ns -> delay depends on PWeh delay time
  484. // delay = TcycE - PWeh = 1000 - 500 = 500ns
  485. _delay_us(0.5);
  486. // Send lower nibble
  487. // ----------------------------------
  488. // Set E
  489. // SETBIT(HD44780_PORT_E, HD44780_E);
  490. LCD_E_PIN = 1;
  491. // send data to LCD
  492. HD44780_SetUppNibble(data << 4);
  493. // PWeh delay time > 450ns
  494. _delay_us(0.5);
  495. // Clear E
  496. // CLRBIT(HD44780_PORT_E, HD44780_E);
  497. LCD_E_PIN = 0;
  498. // TcycE > 1000ns -> delay depends on PWeh delay time
  499. // delay = TcycE - PWeh = 1000 - 500 = 500ns
  500. _delay_us(0.5);
  501. }
  502. /**
  503. * @desc LCD send 8bits instruction in 8 bit mode
  504. *
  505. * @param unsigned short int
  506. *
  507. * @return void
  508. */
  509. void HD44780_Send8bitsIn8bitMode (unsigned short int data)
  510. {
  511. // Set E
  512. SETBIT(HD44780_PORT_E, HD44780_E);
  513. // send data to LCD
  514. HD44780_SetUppNibble(data);
  515. // send data to LCD
  516. HD44780_SetLowNibble(data);
  517. // PWeh delay time > 450ns
  518. _delay_us(0.5);
  519. // Clear E
  520. CLRBIT(HD44780_PORT_E, HD44780_E);
  521. // TcycE > 1000ns -> delay depends on PWeh delay time
  522. // delay = TcycE - PWeh = 1000 - 500 = 500ns
  523. _delay_us(0.5);
  524. }
  525. /**
  526. * @desc LCD send upper nibble
  527. *
  528. * @param unsigned short int
  529. *
  530. * @return void
  531. */
  532. void HD44780_SetUppNibble (unsigned short int data)
  533. {
  534. // LCD_DB4_PIN = 0;
  535. // LCD_DB5_PIN = 0;
  536. // LCD_DB6_PIN = 0;
  537. // LCD_DB7_PIN = 0;
  538. unsigned short test = data;
  539. if (data & 0x80)
  540. {
  541. LCD_DB7_PIN = 1;
  542. }
  543. else
  544. {
  545. LCD_DB7_PIN = 0;
  546. }
  547. if (data & 0x40)
  548. {
  549. LCD_DB6_PIN = 1;
  550. }
  551. else
  552. {
  553. LCD_DB6_PIN = 0;
  554. }
  555. if (data & 0x20)
  556. {
  557. LCD_DB5_PIN = 1;
  558. }
  559. else
  560. {
  561. LCD_DB5_PIN = 0;
  562. }
  563. if (data & 0x10)
  564. {
  565. LCD_DB4_PIN = 1;
  566. }
  567. else
  568. {
  569. LCD_DB4_PIN = 0;
  570. }
  571. // clear bits DB7-DB4
  572. // CLRBIT(HD44780_PORT_DATA, HD44780_DATA7);
  573. // CLRBIT(HD44780_PORT_DATA, HD44780_DATA6);
  574. // CLRBIT(HD44780_PORT_DATA, HD44780_DATA5);
  575. // CLRBIT(HD44780_PORT_DATA, HD44780_DATA4);
  576. // // set DB7-DB4 if corresponding bit is set
  577. // if (data & 0x80) { SETBIT(HD44780_PORT_DATA, HD44780_DATA7); }
  578. // if (data & 0x40) { SETBIT(HD44780_PORT_DATA, HD44780_DATA6); }
  579. // if (data & 0x20) { SETBIT(HD44780_PORT_DATA, HD44780_DATA5); }
  580. // if (data & 0x10) { SETBIT(HD44780_PORT_DATA, HD44780_DATA4); }
  581. }
  582. /**
  583. * @desc LCD send lower nibble
  584. *
  585. * @param unsigned short int
  586. *
  587. * @return void
  588. */
  589. void HD44780_SetLowNibble (unsigned short int data)
  590. {
  591. // clear bits DB7-DB4
  592. CLRBIT(HD44780_PORT_DATA, HD44780_DATA3);
  593. CLRBIT(HD44780_PORT_DATA, HD44780_DATA2);
  594. CLRBIT(HD44780_PORT_DATA, HD44780_DATA1);
  595. CLRBIT(HD44780_PORT_DATA, HD44780_DATA0);
  596. // set DB7-DB4 if corresponding bit is set
  597. if (data & 0x08) { SETBIT(HD44780_PORT_DATA, HD44780_DATA3); }
  598. if (data & 0x04) { SETBIT(HD44780_PORT_DATA, HD44780_DATA2); }
  599. if (data & 0x02) { SETBIT(HD44780_PORT_DATA, HD44780_DATA1); }
  600. if (data & 0x01) { SETBIT(HD44780_PORT_DATA, HD44780_DATA0); }
  601. }
  602. /**
  603. * @desc LCD pulse E
  604. *
  605. * @param void
  606. *
  607. * @return void
  608. */
  609. void HD44780_PulseE (void)
  610. {
  611. // Set E
  612. // SETBIT(HD44780_PORT_E, HD44780_E);
  613. LCD_E_PIN = 1;
  614. // PWeh delay time > 450ns
  615. _delay_us(0.5);
  616. // Clear E
  617. // CLRBIT(HD44780_PORT_E, HD44780_E);
  618. LCD_E_PIN = 0;
  619. // TcycE > 1000ns -> delay depends on PWeh delay time
  620. // delay = TcycE - PWeh = 1000 - 500 = 500ns
  621. _delay_us(0.5);
  622. }
  623. /**
  624. * @desc Set PORT DB4 to DB7
  625. *
  626. * @param void
  627. *
  628. * @return void
  629. */
  630. void HD44780_SetPORT_DATA4to7 (void)
  631. {
  632. // set DB4-DB7
  633. LCD_DB4_PIN = 1;
  634. LCD_DB5_PIN = 1;
  635. LCD_DB6_PIN = 1;
  636. LCD_DB7_PIN = 1;
  637. // SETBIT(HD44780_PORT_DATA, HD44780_DATA4);
  638. // SETBIT(HD44780_PORT_DATA, HD44780_DATA5);
  639. // SETBIT(HD44780_PORT_DATA, HD44780_DATA6);
  640. // SETBIT(HD44780_PORT_DATA, HD44780_DATA7);
  641. }
  642. /**
  643. * @desc Clear DDR DB4 to DB7
  644. *
  645. * @param void
  646. *
  647. * @return void
  648. */
  649. void HD44780_SetDDR_DATA4to7 (void)
  650. {
  651. // set DB4-DB7
  652. LCD_DB4_PIN_DIR = PIN_OUTPUT;
  653. LCD_DB5_PIN_DIR = PIN_OUTPUT;
  654. LCD_DB6_PIN_DIR = PIN_OUTPUT;
  655. LCD_DB7_PIN_DIR = PIN_OUTPUT;
  656. // CLRBIT(HD44780_DDR_DATA, HD44780_DATA4);
  657. // CLRBIT(HD44780_DDR_DATA, HD44780_DATA5);
  658. // CLRBIT(HD44780_DDR_DATA, HD44780_DATA6);
  659. // CLRBIT(HD44780_DDR_DATA, HD44780_DATA7);
  660. }
  661. /**
  662. * @desc Set DDR DB4 to DB7
  663. *
  664. * @param void
  665. *
  666. * @return void
  667. */
  668. void HD44780_ClearDDR_DATA4to7 (void)
  669. {
  670. LCD_DB4_PIN_DIR = PIN_INPUT;
  671. LCD_DB5_PIN_DIR = PIN_INPUT;
  672. LCD_DB6_PIN_DIR = PIN_INPUT;
  673. LCD_DB7_PIN_DIR = PIN_INPUT;
  674. // SETBIT(HD44780_DDR_DATA, HD44780_DATA4);
  675. // SETBIT(HD44780_DDR_DATA, HD44780_DATA5);
  676. // SETBIT(HD44780_DDR_DATA, HD44780_DATA6);
  677. // SETBIT(HD44780_DDR_DATA, HD44780_DATA7);
  678. }