EPD_2in7.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*****************************************************************************
  2. * | File : EPD_2in7.c
  3. * | Author : Waveshare team
  4. * | Function : 2.7inch e-paper
  5. * | Info :
  6. *----------------
  7. * | This version: V3.1
  8. * | Date : 2019-10-10
  9. * | Info :
  10. * -----------------------------------------------------------------------------
  11. * V3.1(2019-10-10):
  12. * 1. Add 4 grayscale display
  13. * Add EPD_2in7_gray_lut_vcom[]
  14. * Add EPD_2in7_gray_lut_ww[]
  15. * Add EPD_2in7_gray_lut_bw[]
  16. * Add EPD_2in7_gray_lut_wb[]
  17. * Add EPD_2in7_gray_lut_bb[]
  18. * Add EPD_2in7_gray_SetLut()
  19. * Add EPD_2IN7_Init_4Gray()
  20. * Add EPD_2IN7_4GrayDisplay()
  21. * V3.0(2019-06-12):
  22. * 1.Change:
  23. * lut_vcom_dc[] => EPD_2in7_lut_vcom_dc[]
  24. * lut_ww[] => EPD_2in7_lut_ww[]
  25. * lut_bw[] => EPD_2in7_lut_bw[]
  26. * lut_bb[] => EPD_2in7_lut_bb[]
  27. * lut_wb[] => EPD_2in7_lut_wb[]
  28. * EPD_Reset() => EPD_2in7_Reset()
  29. * EPD_SendCommand() => EPD_2in7_SendCommand()
  30. * EPD_SendData() => EPD_2in7_SendData()
  31. * EPD_WaitUntilIdle() => EPD_2in7_ReadBusy()
  32. * EPD_SetLut() => EPD_2in7_SetLut()
  33. * EPD_Init() => EPD_2in7_Init()
  34. * EPD_Clear() => EPD_2in7_Clear()
  35. * EPD_Display() => EPD_2in7_Display()
  36. * EPD_Sleep() => EPD_2in7_Sleep()
  37. * 2.remove commands define:
  38. * #define PANEL_SETTING 0x00
  39. * #define POWER_SETTING 0x01
  40. * #define POWER_OFF 0x02
  41. * #define POWER_OFF_SEQUENCE_SETTING 0x03
  42. * #define POWER_ON 0x04
  43. * #define POWER_ON_MEASURE 0x05
  44. * #define BOOSTER_SOFT_START 0x06
  45. * #define DEEP_SLEEP 0x07
  46. * #define DATA_START_TRANSMISSION_1 0x10
  47. * #define DATA_STOP 0x11
  48. * #define DISPLAY_REFRESH 0x12
  49. * #define DATA_START_TRANSMISSION_2 0x13
  50. * #define PLL_CONTROL 0x30
  51. * #define TEMPERATURE_SENSOR_COMMAND 0x40
  52. * #define TEMPERATURE_SENSOR_CALIBRATION 0x41
  53. * #define TEMPERATURE_SENSOR_WRITE 0x42
  54. * #define TEMPERATURE_SENSOR_READ 0x43
  55. * #define VCOM_AND_DATA_INTERVAL_SETTING 0x50
  56. * #define LOW_POWER_DETECTION 0x51
  57. * #define TCON_SETTING 0x60
  58. * #define TCON_RESOLUTION 0x61
  59. * #define SOURCE_AND_GATE_START_SETTING 0x62
  60. * #define GET_STATUS 0x71
  61. * #define AUTO_MEASURE_VCOM 0x80
  62. * #define VCOM_VALUE 0x81
  63. * #define VCM_DC_SETTING_REGISTER 0x82
  64. * #define PROGRAM_MODE 0xA0
  65. * #define ACTIVE_PROGRAM 0xA1
  66. * #define READ_OTP_DATA 0xA2
  67. * -----------------------------------------------------------------------------
  68. * V2.0(2018-11-06):
  69. * 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8]
  70. * 2.Change:EPD_Display(UBYTE *Image)
  71. * Need to pass parameters: pointer to cached data
  72. #
  73. # Permission is hereby granted, free of charge, to any person obtaining a copy
  74. # of this software and associated documnetation files (the "Software"), to deal
  75. # in the Software without restriction, including without limitation the rights
  76. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  77. # copies of the Software, and to permit persons to whom the Software is
  78. # furished to do so, subject to the following conditions:
  79. #
  80. # The above copyright notice and this permission notice shall be included in
  81. # all copies or substantial portions of the Software.
  82. #
  83. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  84. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  85. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  86. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  87. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  88. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  89. # THE SOFTWARE.
  90. #
  91. ******************************************************************************/
  92. #include "EPD_2in7.h"
  93. #include "Debug.h"
  94. static const unsigned char EPD_2in7_lut_vcom_dc[] = {
  95. 0x00 ,0x00,
  96. 0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  97. 0x60 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  98. 0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  99. 0x00 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  100. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  101. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  102. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
  103. };
  104. static const unsigned char EPD_2in7_lut_ww[] = {
  105. 0x40 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  106. 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  107. 0x40 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  108. 0xA0 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  109. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  110. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  111. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  112. };
  113. static const unsigned char EPD_2in7_lut_bw[] = {
  114. 0x40 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  115. 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  116. 0x40 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  117. 0xA0 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  118. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  119. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  120. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  121. };
  122. static const unsigned char EPD_2in7_lut_bb[] = {
  123. 0x80 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  124. 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  125. 0x80 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  126. 0x50 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  127. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  128. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  129. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  130. };
  131. static const unsigned char EPD_2in7_lut_wb[] = {
  132. 0x80 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  133. 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  134. 0x80 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  135. 0x50 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  136. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  137. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  138. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  139. };
  140. //////////////////////////////////////full screen update LUT////////////////////////////////////////////
  141. //0~3 gray
  142. static const unsigned char EPD_2in7_gray_lut_vcom[] =
  143. {
  144. 0x00 ,0x00,
  145. 0x00 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  146. 0x60 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  147. 0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  148. 0x00 ,0x13 ,0x0A ,0x01 ,0x00 ,0x01,
  149. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  150. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  151. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  152. };
  153. //R21
  154. static const unsigned char EPD_2in7_gray_lut_ww[] ={
  155. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  156. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  157. 0x10 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  158. 0xA0 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
  159. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  160. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  161. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  162. };
  163. //R22H r
  164. static const unsigned char EPD_2in7_gray_lut_bw[] ={
  165. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  166. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  167. 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  168. 0x99 ,0x0C ,0x01 ,0x03 ,0x04 ,0x01,
  169. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  170. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  171. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  172. };
  173. //R23H w
  174. static const unsigned char EPD_2in7_gray_lut_wb[] ={
  175. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  176. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  177. 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  178. 0x99 ,0x0B ,0x04 ,0x04 ,0x01 ,0x01,
  179. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  180. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  181. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  182. };
  183. //R24H b
  184. static const unsigned char EPD_2in7_gray_lut_bb[] ={
  185. 0x80 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  186. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  187. 0x20 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  188. 0x50 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
  189. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  190. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  191. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  192. };
  193. /******************************************************************************
  194. function : Software reset
  195. parameter:
  196. ******************************************************************************/
  197. static void EPD_2in7_Reset(void)
  198. {
  199. DEV_Digital_Write(EPD_RST_PIN, 1);
  200. DEV_Delay_ms(200);
  201. DEV_Digital_Write(EPD_RST_PIN, 0);
  202. DEV_Delay_ms(2);
  203. DEV_Digital_Write(EPD_RST_PIN, 1);
  204. DEV_Delay_ms(200);
  205. }
  206. /******************************************************************************
  207. function : send command
  208. parameter:
  209. Reg : Command register
  210. ******************************************************************************/
  211. static void EPD_2in7_SendCommand(UBYTE Reg)
  212. {
  213. DEV_Digital_Write(EPD_DC_PIN, 0);
  214. DEV_Digital_Write(EPD_CS_PIN, 0);
  215. DEV_SPI_WriteByte(Reg);
  216. DEV_Digital_Write(EPD_CS_PIN, 1);
  217. }
  218. /******************************************************************************
  219. function : send data
  220. parameter:
  221. Data : Write data
  222. ******************************************************************************/
  223. static void EPD_2in7_SendData(UBYTE Data)
  224. {
  225. DEV_Digital_Write(EPD_DC_PIN, 1);
  226. DEV_Digital_Write(EPD_CS_PIN, 0);
  227. DEV_SPI_WriteByte(Data);
  228. DEV_Digital_Write(EPD_CS_PIN, 1);
  229. }
  230. /******************************************************************************
  231. function : Wait until the busy_pin goes LOW
  232. parameter:
  233. ******************************************************************************/
  234. static void EPD_2in7_ReadBusy(void)
  235. {
  236. unsigned char count = 100;
  237. Debug("e-Paper busy\r\n");
  238. UBYTE busy;
  239. do {
  240. EPD_2in7_SendCommand(0x71);
  241. busy = DEV_Digital_Read(EPD_BUSY_PIN);
  242. busy =!(busy & 0x01);
  243. if(!(count--))
  244. {
  245. Debug("error: e-Paper busy timeout!!!\r\n");
  246. break;
  247. }
  248. else
  249. DEV_Delay_ms(100);
  250. } while(busy);
  251. DEV_Delay_ms(200);
  252. Debug("e-Paper busy release\r\n");
  253. }
  254. /******************************************************************************
  255. function : set the look-up tables
  256. parameter:
  257. ******************************************************************************/
  258. static void EPD_2in7_SetLut(void)
  259. {
  260. unsigned int count;
  261. EPD_2in7_SendCommand(0x20); //vcom
  262. for(count = 0; count < 44; count++) {
  263. EPD_2in7_SendData(EPD_2in7_lut_vcom_dc[count]);
  264. }
  265. EPD_2in7_SendCommand(0x21); //ww --
  266. for(count = 0; count < 42; count++) {
  267. EPD_2in7_SendData(EPD_2in7_lut_ww[count]);
  268. }
  269. EPD_2in7_SendCommand(0x22); //bw r
  270. for(count = 0; count < 42; count++) {
  271. EPD_2in7_SendData(EPD_2in7_lut_bw[count]);
  272. }
  273. EPD_2in7_SendCommand(0x23); //wb w
  274. for(count = 0; count < 42; count++) {
  275. EPD_2in7_SendData(EPD_2in7_lut_bb[count]);
  276. }
  277. EPD_2in7_SendCommand(0x24); //bb b
  278. for(count = 0; count < 42; count++) {
  279. EPD_2in7_SendData(EPD_2in7_lut_wb[count]);
  280. }
  281. }
  282. void EPD_2in7_gray_SetLut(void)
  283. {
  284. unsigned int count;
  285. EPD_2in7_SendCommand(0x20); //vcom
  286. for(count=0;count<44;count++)
  287. {EPD_2in7_SendData(EPD_2in7_gray_lut_vcom[count]);}
  288. EPD_2in7_SendCommand(0x21); //red not use
  289. for(count=0;count<42;count++)
  290. {EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);}
  291. EPD_2in7_SendCommand(0x22); //bw r
  292. for(count=0;count<42;count++)
  293. {EPD_2in7_SendData(EPD_2in7_gray_lut_bw[count]);}
  294. EPD_2in7_SendCommand(0x23); //wb w
  295. for(count=0;count<42;count++)
  296. {EPD_2in7_SendData(EPD_2in7_gray_lut_wb[count]);}
  297. EPD_2in7_SendCommand(0x24); //bb b
  298. for(count=0;count<42;count++)
  299. {EPD_2in7_SendData(EPD_2in7_gray_lut_bb[count]);}
  300. EPD_2in7_SendCommand(0x25); //vcom
  301. for(count=0;count<42;count++)
  302. {EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);}
  303. }
  304. /******************************************************************************
  305. function : Initialize the e-Paper register
  306. parameter:
  307. ******************************************************************************/
  308. void EPD_2IN7_Init(UBYTE mode)
  309. {
  310. EPD_2in7_Reset();
  311. EPD_2in7_SendCommand(0x01); // POWER_SETTING
  312. EPD_2in7_SendData(0x03); // VDS_EN, VDG_EN
  313. EPD_2in7_SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0]
  314. EPD_2in7_SendData(0x2b); // VDH
  315. EPD_2in7_SendData(0x2b); // VDL
  316. EPD_2in7_SendData(0x09); // VDHR
  317. EPD_2in7_SendCommand(0x06); // BOOSTER_SOFT_START
  318. EPD_2in7_SendData(0x07);
  319. EPD_2in7_SendData(0x07);
  320. EPD_2in7_SendData(0x17);
  321. // Power optimization
  322. EPD_2in7_SendCommand(0xF8);
  323. EPD_2in7_SendData(0x60);
  324. EPD_2in7_SendData(0xA5);
  325. // Power optimization
  326. EPD_2in7_SendCommand(0xF8);
  327. EPD_2in7_SendData(0x89);
  328. EPD_2in7_SendData(0xA5);
  329. // Power optimization
  330. EPD_2in7_SendCommand(0xF8);
  331. EPD_2in7_SendData(0x90);
  332. EPD_2in7_SendData(0x00);
  333. // Power optimization
  334. EPD_2in7_SendCommand(0xF8);
  335. EPD_2in7_SendData(0x93);
  336. EPD_2in7_SendData(0x2A);
  337. // Power optimization
  338. EPD_2in7_SendCommand(0xF8);
  339. EPD_2in7_SendData(0xA0);
  340. EPD_2in7_SendData(0xA5);
  341. // Power optimization
  342. EPD_2in7_SendCommand(0xF8);
  343. EPD_2in7_SendData(0xA1);
  344. EPD_2in7_SendData(0x00);
  345. // Power optimization
  346. EPD_2in7_SendCommand(0xF8);
  347. EPD_2in7_SendData(0x73);
  348. EPD_2in7_SendData(0x41);
  349. EPD_2in7_SendCommand(0x16); // PARTIAL_DISPLAY_REFRESH
  350. EPD_2in7_SendData(0x00);
  351. EPD_2in7_SendCommand(0x04); // POWER_ON
  352. EPD_2in7_ReadBusy();
  353. EPD_2in7_SendCommand(0x00); // PANEL_SETTING
  354. EPD_2in7_SendData(0xAF); // KW-BF KWR-AF BWROTP 0f
  355. EPD_2in7_SendCommand(0x30); // PLL_CONTROL
  356. EPD_2in7_SendData(0x3A); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
  357. EPD_2in7_SendCommand(0x82); // VCM_DC_SETTING_REGISTER
  358. EPD_2in7_SendData(0x12);
  359. EPD_2in7_SetLut();
  360. }
  361. void EPD_2IN7_Init_4Gray(void)
  362. {
  363. EPD_2in7_Reset();
  364. EPD_2in7_SendCommand(0x01); //POWER SETTING
  365. EPD_2in7_SendData (0x03);
  366. EPD_2in7_SendData (0x00);
  367. EPD_2in7_SendData (0x2b);
  368. EPD_2in7_SendData (0x2b);
  369. EPD_2in7_SendCommand(0x06); //booster soft start
  370. EPD_2in7_SendData (0x07); //A
  371. EPD_2in7_SendData (0x07); //B
  372. EPD_2in7_SendData (0x17); //C
  373. EPD_2in7_SendCommand(0xF8); //boost??
  374. EPD_2in7_SendData (0x60);
  375. EPD_2in7_SendData (0xA5);
  376. EPD_2in7_SendCommand(0xF8); //boost??
  377. EPD_2in7_SendData (0x89);
  378. EPD_2in7_SendData (0xA5);
  379. EPD_2in7_SendCommand(0xF8); //boost??
  380. EPD_2in7_SendData (0x90);
  381. EPD_2in7_SendData (0x00);
  382. EPD_2in7_SendCommand(0xF8); //boost??
  383. EPD_2in7_SendData (0x93);
  384. EPD_2in7_SendData (0x2A);
  385. EPD_2in7_SendCommand(0xF8); //boost??
  386. EPD_2in7_SendData (0xa0);
  387. EPD_2in7_SendData (0xa5);
  388. EPD_2in7_SendCommand(0xF8); //boost??
  389. EPD_2in7_SendData (0xa1);
  390. EPD_2in7_SendData (0x00);
  391. EPD_2in7_SendCommand(0xF8); //boost??
  392. EPD_2in7_SendData (0x73);
  393. EPD_2in7_SendData (0x41);
  394. EPD_2in7_SendCommand(0x16);
  395. EPD_2in7_SendData(0x00);
  396. EPD_2in7_SendCommand(0x04);
  397. EPD_2in7_ReadBusy();
  398. EPD_2in7_SendCommand(0x00); //panel setting
  399. EPD_2in7_SendData(0xbf); //KW-BF KWR-AF BWROTP 0f
  400. EPD_2in7_SendCommand(0x30); //PLL setting
  401. EPD_2in7_SendData (0x90); //100hz
  402. EPD_2in7_SendCommand(0x61); //resolution setting
  403. EPD_2in7_SendData (0x00); //176
  404. EPD_2in7_SendData (0xb0);
  405. EPD_2in7_SendData (0x01); //264
  406. EPD_2in7_SendData (0x08);
  407. EPD_2in7_SendCommand(0x82); //vcom_DC setting
  408. EPD_2in7_SendData (0x12);
  409. EPD_2in7_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
  410. EPD_2in7_SendData(0x97);
  411. }
  412. /******************************************************************************
  413. function : Clear screen
  414. parameter:
  415. ******************************************************************************/
  416. void EPD_2IN7_Clear(void)
  417. {
  418. UWORD Width, Height;
  419. Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
  420. Height = EPD_2IN7_HEIGHT;
  421. EPD_2in7_SendCommand(0x10);
  422. for (UWORD j = 0; j < Height; j++) {
  423. for (UWORD i = 0; i < Width; i++) {
  424. EPD_2in7_SendData(0XFF);
  425. }
  426. }
  427. EPD_2in7_SendCommand(0x13);
  428. for (UWORD j = 0; j < Height; j++) {
  429. for (UWORD i = 0; i < Width; i++) {
  430. EPD_2in7_SendData(0XFF);
  431. }
  432. }
  433. EPD_2in7_SendCommand(0x12);
  434. EPD_2in7_ReadBusy();
  435. }
  436. /******************************************************************************
  437. function : Sends the image buffer in RAM to e-Paper and displays
  438. parameter:
  439. ******************************************************************************/
  440. void EPD_2IN7_Display(const UBYTE *Image, UBYTE *Image2)
  441. {
  442. UWORD Width, Height;
  443. Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
  444. Height = EPD_2IN7_HEIGHT;
  445. EPD_2in7_SendCommand(0x10);
  446. for (UWORD j = 0; j < Height; j++) {
  447. for (UWORD i = 0; i < Width; i++) {
  448. EPD_2in7_SendData(0XFF);
  449. }
  450. }
  451. EPD_2in7_SendCommand(0x13);
  452. for (UWORD j = 0; j < Height; j++) {
  453. for (UWORD i = 0; i < Width; i++) {
  454. EPD_2in7_SendData(Image[i + j * Width]);
  455. }
  456. }
  457. EPD_2in7_SendCommand(0x12);
  458. EPD_2in7_ReadBusy();
  459. }
  460. void EPD_2IN7_4GrayDisplay(const UBYTE *Image)
  461. {
  462. UDOUBLE i,j,k;
  463. UBYTE temp1,temp2,temp3;
  464. EPD_2in7_SendCommand(0x10);
  465. for(i=0;i<5808;i++) //5808*4 46464
  466. {
  467. temp3=0;
  468. for(j=0;j<2;j++)
  469. {
  470. temp1 = Image[i*2+j];
  471. for(k=0;k<2;k++)
  472. {
  473. temp2 = temp1&0xC0 ;
  474. if(temp2 == 0xC0)
  475. temp3 |= 0x01;//white
  476. else if(temp2 == 0x00)
  477. temp3 |= 0x00; //black
  478. else if(temp2 == 0x80)
  479. temp3 |= 0x01; //gray1
  480. else //0x40
  481. temp3 |= 0x00; //gray2
  482. temp3 <<= 1;
  483. temp1 <<= 2;
  484. temp2 = temp1&0xC0 ;
  485. if(temp2 == 0xC0) //white
  486. temp3 |= 0x01;
  487. else if(temp2 == 0x00) //black
  488. temp3 |= 0x00;
  489. else if(temp2 == 0x80)
  490. temp3 |= 0x01; //gray1
  491. else //0x40
  492. temp3 |= 0x00; //gray2
  493. if(j!=1 || k!=1)
  494. temp3 <<= 1;
  495. temp1 <<= 2;
  496. }
  497. }
  498. EPD_2in7_SendData(temp3);
  499. }
  500. // new data
  501. EPD_2in7_SendCommand(0x13);
  502. for(i=0;i<5808;i++) //5808*4 46464
  503. {
  504. temp3=0;
  505. for(j=0;j<2;j++)
  506. {
  507. temp1 = Image[i*2+j];
  508. for(k=0;k<2;k++)
  509. {
  510. temp2 = temp1&0xC0 ;
  511. if(temp2 == 0xC0)
  512. temp3 |= 0x01;//white
  513. else if(temp2 == 0x00)
  514. temp3 |= 0x00; //black
  515. else if(temp2 == 0x80)
  516. temp3 |= 0x00; //gray1
  517. else //0x40
  518. temp3 |= 0x01; //gray2
  519. temp3 <<= 1;
  520. temp1 <<= 2;
  521. temp2 = temp1&0xC0 ;
  522. if(temp2 == 0xC0) //white
  523. temp3 |= 0x01;
  524. else if(temp2 == 0x00) //black
  525. temp3 |= 0x00;
  526. else if(temp2 == 0x80)
  527. temp3 |= 0x00; //gray1
  528. else //0x40
  529. temp3 |= 0x01; //gray2
  530. if(j!=1 || k!=1)
  531. temp3 <<= 1;
  532. temp1 <<= 2;
  533. }
  534. }
  535. EPD_2in7_SendData(temp3);
  536. }
  537. EPD_2in7_gray_SetLut();
  538. EPD_2in7_SendCommand(0x12);
  539. DEV_Delay_ms(200);
  540. EPD_2in7_ReadBusy();
  541. }
  542. /******************************************************************************
  543. function : Enter sleep mode
  544. parameter:
  545. ******************************************************************************/
  546. void EPD_2IN7_Sleep(void)
  547. {
  548. EPD_2in7_SendCommand(0X50);
  549. EPD_2in7_SendData(0xf7);
  550. EPD_2in7_SendCommand(0X02); //power off
  551. EPD_2in7_SendCommand(0X07); //deep sleep
  552. EPD_2in7_SendData(0xA5);
  553. }