UC1601S-I2C.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "UC1601S-I2C.h"
  2. void uc1601s_write_command(unsigned char cmd) {
  3. expander_set_bit_no_send(UC1601S_CS_PORT, UC1601S_CS, 0);
  4. expander_set_bit_no_send(UC1601S_CD_PORT, UC1601S_CD, 0);
  5. exp_output[0] = cmd;
  6. expander_write(0);
  7. expander_set_bit(UC1601S_WR_PORT, UC1601S_WR, 0);
  8. expander_set_bit(UC1601S_WR_PORT, UC1601S_WR, 1);
  9. expander_set_bit(UC1601S_CS_PORT, UC1601S_CS, 1);
  10. }
  11. void uc1601s_write_data(unsigned char data) {
  12. expander_set_bit_no_send(UC1601S_CS_PORT, UC1601S_CS, 0);
  13. expander_set_bit(UC1601S_CD_PORT, UC1601S_CD, 1);
  14. exp_output[0] = data;
  15. expander_write(0);
  16. expander_set_bit(UC1601S_WR_PORT, UC1601S_WR, 0);
  17. expander_set_bit(UC1601S_WR_PORT, UC1601S_WR, 1);
  18. expander_set_bit(UC1601S_CS_PORT, UC1601S_CS, 1);
  19. }
  20. unsigned char uc1601s_read_data(void) {
  21. unsigned char out;
  22. UC1601S_DATA_INPUT();
  23. expander_set_bit_no_send(UC1601S_CS_PORT, UC1601S_CS, 0);
  24. expander_set_bit_no_send(UC1601S_CD_PORT, UC1601S_CD, 1);
  25. expander_set_bit(UC1601S_RD_PORT, UC1601S_RD, 0);
  26. out = expander_read_byte(0, 0);
  27. expander_set_bit_no_send(UC1601S_RD_PORT, UC1601S_RD, 1);
  28. expander_set_bit(UC1601S_CS_PORT, UC1601S_CS, 1);
  29. UC1601S_DATA_OUTPUT();
  30. return out;
  31. }
  32. #define UC1601S_INTERNAL_VLCD 0x6
  33. void LCD_Initialize(void) {
  34. expander_set_bit(UC1601S_RST_PORT, UC1601S_RST, 1);
  35. _delay_ms(5);
  36. expander_set_bit_no_send(UC1601S_RD_PORT, UC1601S_RD, 1);
  37. expander_set_bit(UC1601S_WR_PORT, UC1601S_WR, 1);
  38. UC1601S_DATA_OUTPUT();
  39. // uc1601s_system_reset();
  40. uc1601s_set_lcd_bias_ratio(UC1601S_BIAS_RATIO_8);
  41. uc1601s_set_vbias(0xee);
  42. uc1601s_set_display_enable(1);
  43. uc1601s_set_power_control(UC1601S_INTERNAL_VLCD);
  44. uc1601s_set_all_pixel_on(1);
  45. _delay_ms(2);
  46. }