EPD_2in7.c 20 KB

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