hd44780_direct_sender.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <stdint.h>
  2. #include <stddef.h>
  3. #include <stdbool.h>
  4. #include <cx/chlcd.h>
  5. #include <cx/chlcd/__helper.h>
  6. chlcd_error_t chlcd_hd44780_direct_sender_init(void *self_pointer) {
  7. chlcd_hd44780_direct_connector_t *self
  8. = (chlcd_hd44780_direct_connector_t *) self_pointer;
  9. __R(chlcd_pin_set_output(self->e));
  10. __R(chlcd_pin_set_output(self->rs));
  11. __R(chlcd_pin_set_output(self->d4));
  12. __R(chlcd_pin_set_output(self->d5));
  13. __R(chlcd_pin_set_output(self->d6));
  14. __R(chlcd_pin_set_output(self->d7));
  15. __R(chlcd_pin_write(self->d7, false));
  16. __R(chlcd_pin_write(self->d6, false));
  17. __R(chlcd_pin_write(self->d5, false));
  18. __R(chlcd_pin_write(self->d4, false));
  19. __R(chlcd_pin_write(self->rs, false));
  20. __R(chlcd_pin_write(self->e, false));
  21. return CHLCD_SUCCESS;
  22. }
  23. chlcd_error_t __chlcd_hd44780_direct_sender_send_half_byte(
  24. chlcd_hd44780_direct_connector_t *self,
  25. uint8_t content,
  26. bool is_command
  27. ) {
  28. __R(chlcd_pin_write(self->d7, (content & 0b10000000)));
  29. __R(chlcd_pin_write(self->d6, (content & 0b01000000)));
  30. __R(chlcd_pin_write(self->d5, (content & 0b00100000)));
  31. __R(chlcd_pin_write(self->d4, (content & 0b00010000)));
  32. __R(chlcd_pin_write(self->rs, !is_command));
  33. __R(chlcd_pin_write(self->e, true));
  34. __R(chlcd_sleep_us(2000));
  35. __R(chlcd_pin_write(self->e, false));
  36. __R(chlcd_sleep_us(2000));
  37. return CHLCD_SUCCESS;
  38. }
  39. chlcd_error_t chlcd_hd44780_direct_sender(
  40. void *self_pointer,
  41. chlcd_data_t content,
  42. bool is_command,
  43. bool is_half_word
  44. ) {
  45. chlcd_hd44780_direct_connector_t *self
  46. = (chlcd_hd44780_direct_connector_t *) self_pointer;
  47. if (!is_half_word) {
  48. __R(__chlcd_hd44780_direct_sender_send_half_byte(
  49. self,
  50. content,
  51. is_command
  52. ));
  53. }
  54. content = content << 4;
  55. __R(__chlcd_hd44780_direct_sender_send_half_byte(
  56. self,
  57. content,
  58. is_command
  59. ));
  60. return CHLCD_SUCCESS;
  61. }