EPD_2in7.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. Debug("e-Paper busy\r\n");
  237. UBYTE busy;
  238. do {
  239. EPD_2in7_SendCommand(0x71);
  240. busy = DEV_Digital_Read(EPD_BUSY_PIN);
  241. busy =!(busy & 0x01);
  242. } while(busy);
  243. DEV_Delay_ms(200);
  244. Debug("e-Paper busy release\r\n");
  245. }
  246. /******************************************************************************
  247. function : set the look-up tables
  248. parameter:
  249. ******************************************************************************/
  250. static void EPD_2in7_SetLut(void)
  251. {
  252. unsigned int count;
  253. EPD_2in7_SendCommand(0x20); //vcom
  254. for(count = 0; count < 44; count++) {
  255. EPD_2in7_SendData(EPD_2in7_lut_vcom_dc[count]);
  256. }
  257. EPD_2in7_SendCommand(0x21); //ww --
  258. for(count = 0; count < 42; count++) {
  259. EPD_2in7_SendData(EPD_2in7_lut_ww[count]);
  260. }
  261. EPD_2in7_SendCommand(0x22); //bw r
  262. for(count = 0; count < 42; count++) {
  263. EPD_2in7_SendData(EPD_2in7_lut_bw[count]);
  264. }
  265. EPD_2in7_SendCommand(0x23); //wb w
  266. for(count = 0; count < 42; count++) {
  267. EPD_2in7_SendData(EPD_2in7_lut_bb[count]);
  268. }
  269. EPD_2in7_SendCommand(0x24); //bb b
  270. for(count = 0; count < 42; count++) {
  271. EPD_2in7_SendData(EPD_2in7_lut_wb[count]);
  272. }
  273. }
  274. void EPD_2in7_gray_SetLut(void)
  275. {
  276. unsigned int count;
  277. EPD_2in7_SendCommand(0x20); //vcom
  278. for(count=0;count<44;count++)
  279. {EPD_2in7_SendData(EPD_2in7_gray_lut_vcom[count]);}
  280. EPD_2in7_SendCommand(0x21); //red not use
  281. for(count=0;count<42;count++)
  282. {EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);}
  283. EPD_2in7_SendCommand(0x22); //bw r
  284. for(count=0;count<42;count++)
  285. {EPD_2in7_SendData(EPD_2in7_gray_lut_bw[count]);}
  286. EPD_2in7_SendCommand(0x23); //wb w
  287. for(count=0;count<42;count++)
  288. {EPD_2in7_SendData(EPD_2in7_gray_lut_wb[count]);}
  289. EPD_2in7_SendCommand(0x24); //bb b
  290. for(count=0;count<42;count++)
  291. {EPD_2in7_SendData(EPD_2in7_gray_lut_bb[count]);}
  292. EPD_2in7_SendCommand(0x25); //vcom
  293. for(count=0;count<42;count++)
  294. {EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);}
  295. }
  296. /******************************************************************************
  297. function : Initialize the e-Paper register
  298. parameter:
  299. ******************************************************************************/
  300. void EPD_2IN7_Init(void)
  301. {
  302. EPD_2in7_Reset();
  303. EPD_2in7_SendCommand(0x01); // POWER_SETTING
  304. EPD_2in7_SendData(0x03); // VDS_EN, VDG_EN
  305. EPD_2in7_SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0]
  306. EPD_2in7_SendData(0x2b); // VDH
  307. EPD_2in7_SendData(0x2b); // VDL
  308. EPD_2in7_SendData(0x09); // VDHR
  309. EPD_2in7_SendCommand(0x06); // BOOSTER_SOFT_START
  310. EPD_2in7_SendData(0x07);
  311. EPD_2in7_SendData(0x07);
  312. EPD_2in7_SendData(0x17);
  313. // Power optimization
  314. EPD_2in7_SendCommand(0xF8);
  315. EPD_2in7_SendData(0x60);
  316. EPD_2in7_SendData(0xA5);
  317. // Power optimization
  318. EPD_2in7_SendCommand(0xF8);
  319. EPD_2in7_SendData(0x89);
  320. EPD_2in7_SendData(0xA5);
  321. // Power optimization
  322. EPD_2in7_SendCommand(0xF8);
  323. EPD_2in7_SendData(0x90);
  324. EPD_2in7_SendData(0x00);
  325. // Power optimization
  326. EPD_2in7_SendCommand(0xF8);
  327. EPD_2in7_SendData(0x93);
  328. EPD_2in7_SendData(0x2A);
  329. // Power optimization
  330. EPD_2in7_SendCommand(0xF8);
  331. EPD_2in7_SendData(0xA0);
  332. EPD_2in7_SendData(0xA5);
  333. // Power optimization
  334. EPD_2in7_SendCommand(0xF8);
  335. EPD_2in7_SendData(0xA1);
  336. EPD_2in7_SendData(0x00);
  337. // Power optimization
  338. EPD_2in7_SendCommand(0xF8);
  339. EPD_2in7_SendData(0x73);
  340. EPD_2in7_SendData(0x41);
  341. EPD_2in7_SendCommand(0x16); // PARTIAL_DISPLAY_REFRESH
  342. EPD_2in7_SendData(0x00);
  343. EPD_2in7_SendCommand(0x04); // POWER_ON
  344. EPD_2in7_ReadBusy();
  345. EPD_2in7_SendCommand(0x00); // PANEL_SETTING
  346. EPD_2in7_SendData(0xAF); // KW-BF KWR-AF BWROTP 0f
  347. EPD_2in7_SendCommand(0x30); // PLL_CONTROL
  348. EPD_2in7_SendData(0x3A); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
  349. EPD_2in7_SendCommand(0x82); // VCM_DC_SETTING_REGISTER
  350. EPD_2in7_SendData(0x12);
  351. EPD_2in7_SetLut();
  352. }
  353. void EPD_2IN7_Init_4Gray(void)
  354. {
  355. EPD_2in7_Reset();
  356. EPD_2in7_SendCommand(0x01); //POWER SETTING
  357. EPD_2in7_SendData (0x03);
  358. EPD_2in7_SendData (0x00);
  359. EPD_2in7_SendData (0x2b);
  360. EPD_2in7_SendData (0x2b);
  361. EPD_2in7_SendCommand(0x06); //booster soft start
  362. EPD_2in7_SendData (0x07); //A
  363. EPD_2in7_SendData (0x07); //B
  364. EPD_2in7_SendData (0x17); //C
  365. EPD_2in7_SendCommand(0xF8); //boost??
  366. EPD_2in7_SendData (0x60);
  367. EPD_2in7_SendData (0xA5);
  368. EPD_2in7_SendCommand(0xF8); //boost??
  369. EPD_2in7_SendData (0x89);
  370. EPD_2in7_SendData (0xA5);
  371. EPD_2in7_SendCommand(0xF8); //boost??
  372. EPD_2in7_SendData (0x90);
  373. EPD_2in7_SendData (0x00);
  374. EPD_2in7_SendCommand(0xF8); //boost??
  375. EPD_2in7_SendData (0x93);
  376. EPD_2in7_SendData (0x2A);
  377. EPD_2in7_SendCommand(0xF8); //boost??
  378. EPD_2in7_SendData (0xa0);
  379. EPD_2in7_SendData (0xa5);
  380. EPD_2in7_SendCommand(0xF8); //boost??
  381. EPD_2in7_SendData (0xa1);
  382. EPD_2in7_SendData (0x00);
  383. EPD_2in7_SendCommand(0xF8); //boost??
  384. EPD_2in7_SendData (0x73);
  385. EPD_2in7_SendData (0x41);
  386. EPD_2in7_SendCommand(0x16);
  387. EPD_2in7_SendData(0x00);
  388. EPD_2in7_SendCommand(0x04);
  389. EPD_2in7_ReadBusy();
  390. EPD_2in7_SendCommand(0x00); //panel setting
  391. EPD_2in7_SendData(0xbf); //KW-BF KWR-AF BWROTP 0f
  392. EPD_2in7_SendCommand(0x30); //PLL setting
  393. EPD_2in7_SendData (0x90); //100hz
  394. EPD_2in7_SendCommand(0x61); //resolution setting
  395. EPD_2in7_SendData (0x00); //176
  396. EPD_2in7_SendData (0xb0);
  397. EPD_2in7_SendData (0x01); //264
  398. EPD_2in7_SendData (0x08);
  399. EPD_2in7_SendCommand(0x82); //vcom_DC setting
  400. EPD_2in7_SendData (0x12);
  401. EPD_2in7_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
  402. EPD_2in7_SendData(0x97);
  403. }
  404. /******************************************************************************
  405. function : Clear screen
  406. parameter:
  407. ******************************************************************************/
  408. void EPD_2IN7_Clear(void)
  409. {
  410. UWORD Width, Height;
  411. Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
  412. Height = EPD_2IN7_HEIGHT;
  413. EPD_2in7_SendCommand(0x10);
  414. for (UWORD j = 0; j < Height; j++) {
  415. for (UWORD i = 0; i < Width; i++) {
  416. EPD_2in7_SendData(0XFF);
  417. }
  418. }
  419. EPD_2in7_SendCommand(0x13);
  420. for (UWORD j = 0; j < Height; j++) {
  421. for (UWORD i = 0; i < Width; i++) {
  422. EPD_2in7_SendData(0XFF);
  423. }
  424. }
  425. EPD_2in7_SendCommand(0x12);
  426. EPD_2in7_ReadBusy();
  427. }
  428. /******************************************************************************
  429. function : Sends the image buffer in RAM to e-Paper and displays
  430. parameter:
  431. ******************************************************************************/
  432. void EPD_2IN7_Display(const UBYTE *Image)
  433. {
  434. UWORD Width, Height;
  435. Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
  436. Height = EPD_2IN7_HEIGHT;
  437. EPD_2in7_SendCommand(0x10);
  438. for (UWORD j = 0; j < Height; j++) {
  439. for (UWORD i = 0; i < Width; i++) {
  440. EPD_2in7_SendData(0XFF);
  441. }
  442. }
  443. EPD_2in7_SendCommand(0x13);
  444. for (UWORD j = 0; j < Height; j++) {
  445. for (UWORD i = 0; i < Width; i++) {
  446. EPD_2in7_SendData(Image[i + j * Width]);
  447. }
  448. }
  449. EPD_2in7_SendCommand(0x12);
  450. EPD_2in7_ReadBusy();
  451. }
  452. void EPD_2IN7_4GrayDisplay(const UBYTE *Image)
  453. {
  454. UDOUBLE i,j,k;
  455. UBYTE temp1,temp2,temp3;
  456. EPD_2in7_SendCommand(0x10);
  457. for(i=0;i<5808;i++) //5808*4 46464
  458. {
  459. temp3=0;
  460. for(j=0;j<2;j++)
  461. {
  462. temp1 = Image[i*2+j];
  463. for(k=0;k<2;k++)
  464. {
  465. temp2 = temp1&0xC0 ;
  466. if(temp2 == 0xC0)
  467. temp3 |= 0x01;//white
  468. else if(temp2 == 0x00)
  469. temp3 |= 0x00; //black
  470. else if(temp2 == 0x80)
  471. temp3 |= 0x01; //gray1
  472. else //0x40
  473. temp3 |= 0x00; //gray2
  474. temp3 <<= 1;
  475. temp1 <<= 2;
  476. temp2 = temp1&0xC0 ;
  477. if(temp2 == 0xC0) //white
  478. temp3 |= 0x01;
  479. else if(temp2 == 0x00) //black
  480. temp3 |= 0x00;
  481. else if(temp2 == 0x80)
  482. temp3 |= 0x01; //gray1
  483. else //0x40
  484. temp3 |= 0x00; //gray2
  485. if(j!=1 || k!=1)
  486. temp3 <<= 1;
  487. temp1 <<= 2;
  488. }
  489. }
  490. EPD_2in7_SendData(temp3);
  491. }
  492. // new data
  493. EPD_2in7_SendCommand(0x13);
  494. for(i=0;i<5808;i++) //5808*4 46464
  495. {
  496. temp3=0;
  497. for(j=0;j<2;j++)
  498. {
  499. temp1 = Image[i*2+j];
  500. for(k=0;k<2;k++)
  501. {
  502. temp2 = temp1&0xC0 ;
  503. if(temp2 == 0xC0)
  504. temp3 |= 0x01;//white
  505. else if(temp2 == 0x00)
  506. temp3 |= 0x00; //black
  507. else if(temp2 == 0x80)
  508. temp3 |= 0x00; //gray1
  509. else //0x40
  510. temp3 |= 0x01; //gray2
  511. temp3 <<= 1;
  512. temp1 <<= 2;
  513. temp2 = temp1&0xC0 ;
  514. if(temp2 == 0xC0) //white
  515. temp3 |= 0x01;
  516. else if(temp2 == 0x00) //black
  517. temp3 |= 0x00;
  518. else if(temp2 == 0x80)
  519. temp3 |= 0x00; //gray1
  520. else //0x40
  521. temp3 |= 0x01; //gray2
  522. if(j!=1 || k!=1)
  523. temp3 <<= 1;
  524. temp1 <<= 2;
  525. }
  526. }
  527. EPD_2in7_SendData(temp3);
  528. }
  529. EPD_2in7_gray_SetLut();
  530. EPD_2in7_SendCommand(0x12);
  531. DEV_Delay_ms(200);
  532. EPD_2in7_ReadBusy();
  533. }
  534. /******************************************************************************
  535. function : Enter sleep mode
  536. parameter:
  537. ******************************************************************************/
  538. void EPD_2IN7_Sleep(void)
  539. {
  540. EPD_2in7_SendCommand(0X50);
  541. EPD_2in7_SendData(0xf7);
  542. EPD_2in7_SendCommand(0X02); //power off
  543. EPD_2in7_SendCommand(0X07); //deep sleep
  544. EPD_2in7_SendData(0xA5);
  545. }