lcd.c 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988
  1. #include "lcd.h"
  2. #include "dwt.h"
  3. #include "font.h"
  4. #include "stdlib.h"
  5. //////////////////////////////////////////////////////////////////////////////////
  6. //本程序只供学习使用,未经作者许可,不得用于其它任何用途
  7. // ALIENTEK战舰STM32开发板
  8. // 2.4寸/2.8寸/3.5寸/4.3寸 TFT液晶驱动
  9. //支持驱动IC型号包括:ILI9341/ILI9325/RM68042/RM68021/ILI9320/ILI9328/LGDP4531/LGDP4535/
  10. // SPFD5408/SSD1289/1505/B505/C505/NT35310/NT35510等
  11. //正点原子@ALIENTEK
  12. //技术论坛:www.openedv.com
  13. //修改日期:2014/2/11
  14. //版本:V2.5
  15. //版权所有,盗版必究。
  16. // Copyright(C) 广州市星翼电子科技有限公司 2009-2019
  17. // All rights reserved
  18. //********************************************************************************
  19. // V1.2修改说明
  20. //支持了SPFD5408的驱动,另外把液晶ID直接打印成HEX格式.方便查看LCD驱动IC.
  21. // V1.3
  22. //加入了快速IO的支持
  23. //修改了背光控制的极性(适用于V1.8及以后的开发板版本)
  24. //对于1.8版本之前(不包括1.8)的液晶模块,请修改LCD_Init函数的LCD_LED=1;为LCD_LED=1;
  25. // V1.4
  26. //修改了LCD_ShowChar函数,使用画点功能画字符。
  27. //加入了横竖屏显示的支持
  28. // V1.5 20110730
  29. // 1,修改了B505液晶读颜色有误的bug.
  30. // 2,修改了快速IO及横竖屏的设置方式.
  31. // V1.6 20111116
  32. // 1,加入对LGDP4535液晶的驱动支持
  33. // V1.7 20120713
  34. // 1,增加LCD_RD_DATA函数
  35. // 2,增加对ILI9341的支持
  36. // 3,增加ILI9325的独立驱动代码
  37. // 4,增加LCD_Scan_Dir函数(慎重使用)
  38. // 6,另外修改了部分原来的函数,以适应9341的操作
  39. // V1.8 20120905
  40. // 1,加入LCD重要参数设置结构体lcddev
  41. // 2,加入LCD_Display_Dir函数,支持在线横竖屏切换
  42. // V1.9 20120911
  43. // 1,新增RM68042驱动(ID:6804),但是6804不支持横屏显示!!原因:改变扫描方式,
  44. //导致6804坐标设置失效,试过很多方法都不行,暂时无解。
  45. // V2.0 20120924
  46. //在不硬件复位的情况下,ILI9341的ID读取会被误读成9300,修改LCD_Init,将无法识别
  47. //的情况(读到ID为9300/非法ID),强制指定驱动IC为ILI9341,执行9341的初始化。
  48. // V2.1 20120930
  49. //修正ILI9325读颜色的bug。
  50. // V2.2 20121007
  51. //修正LCD_Scan_Dir的bug。
  52. // V2.3 20130120
  53. //新增6804支持横屏显示
  54. // V2.4 20131120
  55. // 1,新增NT35310(ID:5310)驱动器的支持
  56. // 2,新增LCD_Set_Window函数,用于设置窗口,对快速填充,比较有用,但是该函数在横屏时,不支持6804.
  57. // V2.5 20140211
  58. // 1,新增NT35510(ID:5510)驱动器的支持
  59. //////////////////////////////////////////////////////////////////////////////////
  60. // LCD的画笔颜色和背景色
  61. u16 POINT_COLOR = 0x0000; //画笔颜色
  62. u16 BACK_COLOR = 0xFFFF; //背景色
  63. //管理LCD重要参数
  64. //默认为竖屏
  65. _lcd_dev lcddev;
  66. //写寄存器函数
  67. // regval:寄存器值
  68. void LCD_WR_REG(volatile u16 regval)
  69. {
  70. regval = regval; //使用-O2优化的时候,必须插入的延时
  71. LCD->LCD_REG = regval; //写入要写的寄存器序号
  72. }
  73. //写LCD数据
  74. // data:要写入的值
  75. void LCD_WR_DATA(volatile u16 data)
  76. {
  77. data = data; //使用-O2优化的时候,必须插入的延时
  78. LCD->LCD_RAM = data;
  79. }
  80. //读LCD数据
  81. //返回值:读到的值
  82. u16 LCD_RD_DATA(void)
  83. {
  84. volatile u16 ram; //防止被优化
  85. ram = LCD->LCD_RAM;
  86. return ram;
  87. }
  88. //写寄存器
  89. // LCD_Reg:寄存器地址
  90. // LCD_RegValue:要写入的数据
  91. void LCD_WriteReg(u16 LCD_Reg, u16 LCD_RegValue)
  92. {
  93. LCD->LCD_REG = LCD_Reg; //写入要写的寄存器序号
  94. LCD->LCD_RAM = LCD_RegValue; //写入数据
  95. }
  96. //读寄存器
  97. // LCD_Reg:寄存器地址
  98. //返回值:读到的数据
  99. u16 LCD_ReadReg(u16 LCD_Reg)
  100. {
  101. LCD_WR_REG(LCD_Reg); //写入要读的寄存器序号
  102. us_delay(5);
  103. return LCD_RD_DATA(); //返回读到的值
  104. }
  105. //开始写GRAM
  106. void LCD_WriteRAM_Prepare(void)
  107. {
  108. LCD->LCD_REG = lcddev.wramcmd;
  109. }
  110. // LCD写GRAM
  111. // RGB_Code:颜色值
  112. void LCD_WriteRAM(u16 RGB_Code)
  113. {
  114. LCD->LCD_RAM = RGB_Code; //写十六位GRAM
  115. }
  116. //从ILI93xx读出的数据为GBR格式,而我们写入的时候为RGB格式。
  117. //通过该函数转换
  118. // c:GBR格式的颜色值
  119. //返回值:RGB格式的颜色值
  120. u16 LCD_BGR2RGB(u16 c)
  121. {
  122. u16 r, g, b, rgb;
  123. b = (c >> 0) & 0x1f;
  124. g = (c >> 5) & 0x3f;
  125. r = (c >> 11) & 0x1f;
  126. rgb = (b << 11) + (g << 5) + (r << 0);
  127. return (rgb);
  128. }
  129. //当mdk -O1时间优化时需要设置
  130. //延时i
  131. void opt_delay(u8 i)
  132. {
  133. while (i--)
  134. ;
  135. }
  136. //读取个某点的颜色值
  137. // x,y:坐标
  138. //返回值:此点的颜色
  139. u16 LCD_ReadPoint(u16 x, u16 y)
  140. {
  141. u16 r = 0, g = 0, b = 0;
  142. if (x >= lcddev.width || y >= lcddev.height)
  143. return 0; //超过了范围,直接返回
  144. LCD_SetCursor(x, y);
  145. if (lcddev.id == 0X9341 || lcddev.id == 0X6804 || lcddev.id == 0X5310)
  146. LCD_WR_REG(0X2E); // 9341/6804/3510 发送读GRAM指令
  147. else if (lcddev.id == 0X5510)
  148. LCD_WR_REG(0X2E00); // 5510 发送读GRAM指令
  149. else
  150. LCD_WR_REG(R34); //其他IC发送读GRAM指令
  151. if (lcddev.id == 0X9320)
  152. opt_delay(2); // FOR 9320,延时2us
  153. if (LCD->LCD_RAM)
  154. r = 0; // dummy Read
  155. opt_delay(2);
  156. r = LCD->LCD_RAM; //实际坐标颜色
  157. if (lcddev.id == 0X9341 || lcddev.id == 0X5310 || lcddev.id == 0X5510) // 9341/NT35310/NT35510要分2次读出
  158. {
  159. opt_delay(2);
  160. b = LCD->LCD_RAM;
  161. g = r & 0XFF; //对于9341/5310/5510,第一次读取的是RG的值,R在前,G在后,各占8位
  162. g <<= 8;
  163. }
  164. else if (lcddev.id == 0X6804)
  165. r = LCD->LCD_RAM; // 6804第二次读取的才是真实值
  166. if (lcddev.id == 0X9325 || lcddev.id == 0X4535 || lcddev.id == 0X4531 || lcddev.id == 0X8989 || lcddev.id == 0XB505)
  167. return r; //这几种IC直接返回颜色值
  168. else if (lcddev.id == 0X9341 || lcddev.id == 0X5310 || lcddev.id == 0X5510)
  169. return (((r >> 11) << 11) | ((g >> 10) << 5) | (b >> 11)); // ILI9341/NT35310/NT35510需要公式转换一下
  170. else
  171. return LCD_BGR2RGB(r); //其他IC
  172. }
  173. // LCD开启显示
  174. void LCD_DisplayOn(void)
  175. {
  176. if (lcddev.id == 0X9341 || lcddev.id == 0X6804 || lcddev.id == 0X5310)
  177. LCD_WR_REG(0X29); //开启显示
  178. else if (lcddev.id == 0X5510)
  179. LCD_WR_REG(0X2900); //开启显示
  180. else
  181. LCD_WriteReg(R7, 0x0173); //开启显示
  182. }
  183. // LCD关闭显示
  184. void LCD_DisplayOff(void)
  185. {
  186. if (lcddev.id == 0X9341 || lcddev.id == 0X6804 || lcddev.id == 0X5310)
  187. LCD_WR_REG(0X28); //关闭显示
  188. else if (lcddev.id == 0X5510)
  189. LCD_WR_REG(0X2800); //关闭显示
  190. else
  191. LCD_WriteReg(R7, 0x0); //关闭显示
  192. }
  193. //设置光标位置
  194. // Xpos:横坐标
  195. // Ypos:纵坐标
  196. void LCD_SetCursor(u16 Xpos, u16 Ypos)
  197. {
  198. if (lcddev.id == 0X9341 || lcddev.id == 0X5310)
  199. {
  200. LCD_WR_REG(lcddev.setxcmd);
  201. LCD_WR_DATA(Xpos >> 8);
  202. LCD_WR_DATA(Xpos & 0XFF);
  203. LCD_WR_REG(lcddev.setycmd);
  204. LCD_WR_DATA(Ypos >> 8);
  205. LCD_WR_DATA(Ypos & 0XFF);
  206. }
  207. else if (lcddev.id == 0X6804)
  208. {
  209. if (lcddev.dir == 1)
  210. Xpos = lcddev.width - 1 - Xpos; //横屏时处理
  211. LCD_WR_REG(lcddev.setxcmd);
  212. LCD_WR_DATA(Xpos >> 8);
  213. LCD_WR_DATA(Xpos & 0XFF);
  214. LCD_WR_REG(lcddev.setycmd);
  215. LCD_WR_DATA(Ypos >> 8);
  216. LCD_WR_DATA(Ypos & 0XFF);
  217. }
  218. else if (lcddev.id == 0X5510)
  219. {
  220. LCD_WR_REG(lcddev.setxcmd);
  221. LCD_WR_DATA(Xpos >> 8);
  222. LCD_WR_REG(lcddev.setxcmd + 1);
  223. LCD_WR_DATA(Xpos & 0XFF);
  224. LCD_WR_REG(lcddev.setycmd);
  225. LCD_WR_DATA(Ypos >> 8);
  226. LCD_WR_REG(lcddev.setycmd + 1);
  227. LCD_WR_DATA(Ypos & 0XFF);
  228. }
  229. else
  230. {
  231. if (lcddev.dir == 1)
  232. Xpos = lcddev.width - 1 - Xpos; //横屏其实就是调转x,y坐标
  233. LCD_WriteReg(lcddev.setxcmd, Xpos);
  234. LCD_WriteReg(lcddev.setycmd, Ypos);
  235. }
  236. }
  237. //设置LCD的自动扫描方向
  238. //注意:其他函数可能会受到此函数设置的影响(尤其是9341/6804这两个奇葩),
  239. //所以,一般设置为L2R_U2D即可,如果设置为其他扫描方式,可能导致显示不正常.
  240. // dir:0~7,代表8个方向(具体定义见lcd.h)
  241. // 9320/9325/9328/4531/4535/1505/b505/8989/5408/9341/5310/5510等IC已经实际测试
  242. void LCD_Scan_Dir(uint8_t dir)
  243. {
  244. uint16_t regval = 0;
  245. uint16_t dirreg = 0;
  246. uint16_t temp;
  247. if ((lcddev.dir == 1 && lcddev.id != 0X6804 && lcddev.id != 0X1963) || (lcddev.dir == 0 && lcddev.id == 0X1963)) //横屏时,对6804和1963不改变扫描方向!竖屏时1963改变方向
  248. {
  249. switch (dir) //方向转换
  250. {
  251. case 0:
  252. dir = 6;
  253. break;
  254. case 1:
  255. dir = 7;
  256. break;
  257. case 2:
  258. dir = 4;
  259. break;
  260. case 3:
  261. dir = 5;
  262. break;
  263. case 4:
  264. dir = 1;
  265. break;
  266. case 5:
  267. dir = 0;
  268. break;
  269. case 6:
  270. dir = 3;
  271. break;
  272. case 7:
  273. dir = 2;
  274. break;
  275. }
  276. }
  277. if (lcddev.id == 0x9341 || lcddev.id == 0X6804 || lcddev.id == 0X5310 || lcddev.id == 0X5510 || lcddev.id == 0X1963) // 9341/6804/5310/5510/1963,特殊处理
  278. {
  279. switch (dir)
  280. {
  281. case L2R_U2D: //从左到右,从上到下
  282. regval |= (0 << 7) | (0 << 6) | (0 << 5);
  283. break;
  284. case L2R_D2U: //从左到右,从下到上
  285. regval |= (1 << 7) | (0 << 6) | (0 << 5);
  286. break;
  287. case R2L_U2D: //从右到左,从上到下
  288. regval |= (0 << 7) | (1 << 6) | (0 << 5);
  289. break;
  290. case R2L_D2U: //从右到左,从下到上
  291. regval |= (1 << 7) | (1 << 6) | (0 << 5);
  292. break;
  293. case U2D_L2R: //从上到下,从左到右
  294. regval |= (0 << 7) | (0 << 6) | (1 << 5);
  295. break;
  296. case U2D_R2L: //从上到下,从右到左
  297. regval |= (0 << 7) | (1 << 6) | (1 << 5);
  298. break;
  299. case D2U_L2R: //从下到上,从左到右
  300. regval |= (1 << 7) | (0 << 6) | (1 << 5);
  301. break;
  302. case D2U_R2L: //从下到上,从右到左
  303. regval |= (1 << 7) | (1 << 6) | (1 << 5);
  304. break;
  305. }
  306. if (lcddev.id == 0X5510)
  307. dirreg = 0X3600;
  308. else
  309. dirreg = 0X36;
  310. if ((lcddev.id != 0X5310) && (lcddev.id != 0X5510) && (lcddev.id != 0X1963))
  311. regval |= 0X08; // 5310/5510/1963不需要BGR
  312. if (lcddev.id == 0X6804)
  313. regval |= 0x02; // 6804的BIT6和9341的反了
  314. LCD_WriteReg(dirreg, regval);
  315. if (lcddev.id != 0X1963) // 1963不做坐标处理
  316. {
  317. if (regval & 0X20)
  318. {
  319. if (lcddev.width < lcddev.height) //交换X,Y
  320. {
  321. temp = lcddev.width;
  322. lcddev.width = lcddev.height;
  323. lcddev.height = temp;
  324. }
  325. }
  326. else
  327. {
  328. if (lcddev.width > lcddev.height) //交换X,Y
  329. {
  330. temp = lcddev.width;
  331. lcddev.width = lcddev.height;
  332. lcddev.height = temp;
  333. }
  334. }
  335. }
  336. if (lcddev.id == 0X5510)
  337. {
  338. LCD_WR_REG(lcddev.setxcmd);
  339. LCD_WR_DATA(0);
  340. LCD_WR_REG(lcddev.setxcmd + 1);
  341. LCD_WR_DATA(0);
  342. LCD_WR_REG(lcddev.setxcmd + 2);
  343. LCD_WR_DATA((lcddev.width - 1) >> 8);
  344. LCD_WR_REG(lcddev.setxcmd + 3);
  345. LCD_WR_DATA((lcddev.width - 1) & 0XFF);
  346. LCD_WR_REG(lcddev.setycmd);
  347. LCD_WR_DATA(0);
  348. LCD_WR_REG(lcddev.setycmd + 1);
  349. LCD_WR_DATA(0);
  350. LCD_WR_REG(lcddev.setycmd + 2);
  351. LCD_WR_DATA((lcddev.height - 1) >> 8);
  352. LCD_WR_REG(lcddev.setycmd + 3);
  353. LCD_WR_DATA((lcddev.height - 1) & 0XFF);
  354. }
  355. else
  356. {
  357. LCD_WR_REG(lcddev.setxcmd);
  358. LCD_WR_DATA(0);
  359. LCD_WR_DATA(0);
  360. LCD_WR_DATA((lcddev.width - 1) >> 8);
  361. LCD_WR_DATA((lcddev.width - 1) & 0XFF);
  362. LCD_WR_REG(lcddev.setycmd);
  363. LCD_WR_DATA(0);
  364. LCD_WR_DATA(0);
  365. LCD_WR_DATA((lcddev.height - 1) >> 8);
  366. LCD_WR_DATA((lcddev.height - 1) & 0XFF);
  367. }
  368. }
  369. else
  370. {
  371. switch (dir)
  372. {
  373. case L2R_U2D: //从左到右,从上到下
  374. regval |= (1 << 5) | (1 << 4) | (0 << 3);
  375. break;
  376. case L2R_D2U: //从左到右,从下到上
  377. regval |= (0 << 5) | (1 << 4) | (0 << 3);
  378. break;
  379. case R2L_U2D: //从右到左,从上到下
  380. regval |= (1 << 5) | (0 << 4) | (0 << 3);
  381. break;
  382. case R2L_D2U: //从右到左,从下到上
  383. regval |= (0 << 5) | (0 << 4) | (0 << 3);
  384. break;
  385. case U2D_L2R: //从上到下,从左到右
  386. regval |= (1 << 5) | (1 << 4) | (1 << 3);
  387. break;
  388. case U2D_R2L: //从上到下,从右到左
  389. regval |= (1 << 5) | (0 << 4) | (1 << 3);
  390. break;
  391. case D2U_L2R: //从下到上,从左到右
  392. regval |= (0 << 5) | (1 << 4) | (1 << 3);
  393. break;
  394. case D2U_R2L: //从下到上,从右到左
  395. regval |= (0 << 5) | (0 << 4) | (1 << 3);
  396. break;
  397. }
  398. dirreg = 0X03;
  399. regval |= 1 << 12;
  400. LCD_WriteReg(dirreg, regval);
  401. }
  402. }
  403. //画点
  404. // x,y:坐标
  405. // POINT_COLOR:此点的颜色
  406. void LCD_DrawPoint(u16 x, u16 y)
  407. {
  408. LCD_SetCursor(x, y); //设置光标位置
  409. LCD_WriteRAM_Prepare(); //开始写入GRAM
  410. LCD->LCD_RAM = POINT_COLOR;
  411. }
  412. //快速画点
  413. // x,y:坐标
  414. // color:颜色
  415. void LCD_Fast_DrawPoint(u16 x, u16 y, u16 color)
  416. {
  417. if (lcddev.id == 0X9341 || lcddev.id == 0X5310)
  418. {
  419. LCD_WR_REG(lcddev.setxcmd);
  420. LCD_WR_DATA(x >> 8);
  421. LCD_WR_DATA(x & 0XFF);
  422. LCD_WR_REG(lcddev.setycmd);
  423. LCD_WR_DATA(y >> 8);
  424. LCD_WR_DATA(y & 0XFF);
  425. }
  426. else if (lcddev.id == 0X5510)
  427. {
  428. LCD_WR_REG(lcddev.setxcmd);
  429. LCD_WR_DATA(x >> 8);
  430. LCD_WR_REG(lcddev.setxcmd + 1);
  431. LCD_WR_DATA(x & 0XFF);
  432. LCD_WR_REG(lcddev.setycmd);
  433. LCD_WR_DATA(y >> 8);
  434. LCD_WR_REG(lcddev.setycmd + 1);
  435. LCD_WR_DATA(y & 0XFF);
  436. }
  437. else if (lcddev.id == 0X6804)
  438. {
  439. if (lcddev.dir == 1)
  440. x = lcddev.width - 1 - x; //横屏时处理
  441. LCD_WR_REG(lcddev.setxcmd);
  442. LCD_WR_DATA(x >> 8);
  443. LCD_WR_DATA(x & 0XFF);
  444. LCD_WR_REG(lcddev.setycmd);
  445. LCD_WR_DATA(y >> 8);
  446. LCD_WR_DATA(y & 0XFF);
  447. }
  448. else
  449. {
  450. if (lcddev.dir == 1)
  451. x = lcddev.width - 1 - x; //横屏其实就是调转x,y坐标
  452. LCD_WriteReg(lcddev.setxcmd, x);
  453. LCD_WriteReg(lcddev.setycmd, y);
  454. }
  455. LCD->LCD_REG = lcddev.wramcmd;
  456. LCD->LCD_RAM = color;
  457. }
  458. //设置LCD显示方向
  459. // dir:0,竖屏;1,横屏
  460. void LCD_Display_Dir(u8 dir)
  461. {
  462. if (dir == 0) //竖屏
  463. {
  464. lcddev.dir = 0; //竖屏
  465. lcddev.width = 240;
  466. lcddev.height = 320;
  467. if (lcddev.id == 0X9341 || lcddev.id == 0X6804 || lcddev.id == 0X5310)
  468. {
  469. lcddev.wramcmd = 0X2C;
  470. lcddev.setxcmd = 0X2A;
  471. lcddev.setycmd = 0X2B;
  472. if (lcddev.id == 0X6804 || lcddev.id == 0X5310)
  473. {
  474. lcddev.width = 320;
  475. lcddev.height = 480;
  476. }
  477. }
  478. else if (lcddev.id == 0X8989)
  479. {
  480. lcddev.wramcmd = R34;
  481. lcddev.setxcmd = 0X4E;
  482. lcddev.setycmd = 0X4F;
  483. }
  484. else if (lcddev.id == 0x5510)
  485. {
  486. lcddev.wramcmd = 0X2C00;
  487. lcddev.setxcmd = 0X2A00;
  488. lcddev.setycmd = 0X2B00;
  489. lcddev.width = 480;
  490. lcddev.height = 800;
  491. }
  492. else
  493. {
  494. lcddev.wramcmd = R34;
  495. lcddev.setxcmd = R32;
  496. lcddev.setycmd = R33;
  497. }
  498. }
  499. else //横屏
  500. {
  501. lcddev.dir = 1; //横屏
  502. lcddev.width = 320;
  503. lcddev.height = 240;
  504. if (lcddev.id == 0X9341 || lcddev.id == 0X5310)
  505. {
  506. lcddev.wramcmd = 0X2C;
  507. lcddev.setxcmd = 0X2A;
  508. lcddev.setycmd = 0X2B;
  509. }
  510. else if (lcddev.id == 0X6804)
  511. {
  512. lcddev.wramcmd = 0X2C;
  513. lcddev.setxcmd = 0X2B;
  514. lcddev.setycmd = 0X2A;
  515. }
  516. else if (lcddev.id == 0X8989)
  517. {
  518. lcddev.wramcmd = R34;
  519. lcddev.setxcmd = 0X4F;
  520. lcddev.setycmd = 0X4E;
  521. }
  522. else if (lcddev.id == 0x5510)
  523. {
  524. lcddev.wramcmd = 0X2C00;
  525. lcddev.setxcmd = 0X2A00;
  526. lcddev.setycmd = 0X2B00;
  527. lcddev.width = 800;
  528. lcddev.height = 480;
  529. }
  530. else
  531. {
  532. lcddev.wramcmd = R34;
  533. lcddev.setxcmd = R33;
  534. lcddev.setycmd = R32;
  535. }
  536. if (lcddev.id == 0X6804 || lcddev.id == 0X5310)
  537. {
  538. lcddev.width = 480;
  539. lcddev.height = 320;
  540. }
  541. }
  542. LCD_Scan_Dir(DFT_SCAN_DIR); //默认扫描方向
  543. }
  544. //设置窗口,并自动设置画点坐标到窗口左上角(sx,sy).
  545. // sx,sy:窗口起始坐标(左上角)
  546. // width,height:窗口宽度和高度,必须大于0!!
  547. //窗体大小:width*height.
  548. // 68042,横屏时不支持窗口设置!!
  549. void LCD_Set_Window(u16 sx, u16 sy, u16 width, u16 height)
  550. {
  551. u8 hsareg, heareg, vsareg, veareg;
  552. u16 hsaval, heaval, vsaval, veaval;
  553. width = sx + width - 1;
  554. height = sy + height - 1;
  555. if (lcddev.id == 0X9341 || lcddev.id == 0X5310 || lcddev.id == 0X6804) // 6804横屏不支持
  556. {
  557. LCD_WR_REG(lcddev.setxcmd);
  558. LCD_WR_DATA(sx >> 8);
  559. LCD_WR_DATA(sx & 0XFF);
  560. LCD_WR_DATA(width >> 8);
  561. LCD_WR_DATA(width & 0XFF);
  562. LCD_WR_REG(lcddev.setycmd);
  563. LCD_WR_DATA(sy >> 8);
  564. LCD_WR_DATA(sy & 0XFF);
  565. LCD_WR_DATA(height >> 8);
  566. LCD_WR_DATA(height & 0XFF);
  567. }
  568. else if (lcddev.id == 0X5510)
  569. {
  570. LCD_WR_REG(lcddev.setxcmd);
  571. LCD_WR_DATA(sx >> 8);
  572. LCD_WR_REG(lcddev.setxcmd + 1);
  573. LCD_WR_DATA(sx & 0XFF);
  574. LCD_WR_REG(lcddev.setxcmd + 2);
  575. LCD_WR_DATA(width >> 8);
  576. LCD_WR_REG(lcddev.setxcmd + 3);
  577. LCD_WR_DATA(width & 0XFF);
  578. LCD_WR_REG(lcddev.setycmd);
  579. LCD_WR_DATA(sy >> 8);
  580. LCD_WR_REG(lcddev.setycmd + 1);
  581. LCD_WR_DATA(sy & 0XFF);
  582. LCD_WR_REG(lcddev.setycmd + 2);
  583. LCD_WR_DATA(height >> 8);
  584. LCD_WR_REG(lcddev.setycmd + 3);
  585. LCD_WR_DATA(height & 0XFF);
  586. }
  587. else //其他驱动IC
  588. {
  589. if (lcddev.dir == 1) //横屏
  590. {
  591. //窗口值
  592. hsaval = sy;
  593. heaval = height;
  594. vsaval = lcddev.width - width - 1;
  595. veaval = lcddev.width - sx - 1;
  596. }
  597. else
  598. {
  599. hsaval = sx;
  600. heaval = width;
  601. vsaval = sy;
  602. veaval = height;
  603. }
  604. if (lcddev.id == 0X8989) // 8989 IC
  605. {
  606. hsareg = 0X44;
  607. heareg = 0X44; //水平方向窗口寄存器 (1289的由一个寄存器控制)
  608. hsaval |= (heaval << 8); //得到寄存器值.
  609. heaval = hsaval;
  610. vsareg = 0X45;
  611. veareg = 0X46; //垂直方向窗口寄存器
  612. }
  613. else //其他驱动IC
  614. {
  615. hsareg = 0X50;
  616. heareg = 0X51; //水平方向窗口寄存器
  617. vsareg = 0X52;
  618. veareg = 0X53; //垂直方向窗口寄存器
  619. }
  620. //设置寄存器值
  621. LCD_WriteReg(hsareg, hsaval);
  622. LCD_WriteReg(heareg, heaval);
  623. LCD_WriteReg(vsareg, vsaval);
  624. LCD_WriteReg(veareg, veaval);
  625. LCD_SetCursor(sx, sy); //设置光标位置
  626. }
  627. }
  628. //初始化lcd
  629. //该初始化函数可以初始化各种ILI93XX液晶,但是其他函数是基于ILI9320的!!!
  630. //在其他型号的驱动芯片上没有测试!
  631. void LCD_Init(void)
  632. {
  633. FSMC_NORSRAMInitTypeDef init;
  634. FSMC_NORSRAMTimingInitTypeDef timingWrite;
  635. FSMC_NORSRAMTimingInitTypeDef timingRead;
  636. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // PB0 推挽输出 背光
  637. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  638. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  639. // GPIO_Init(GPIOB, &GPIO_InitStructure);
  640. // // PORTD复用推挽输出
  641. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15; // //PORTD复用推挽输出
  642. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
  643. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  644. // GPIO_Init(GPIOD, &GPIO_InitStructure);
  645. // // PORTE复用推挽输出
  646. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; // //PORTD复用推挽输出
  647. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
  648. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  649. // GPIO_Init(GPIOE, &GPIO_InitStructure);
  650. // // //PORTG12复用推挽输出 A0
  651. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_12; // //PORTD复用推挽输出
  652. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
  653. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  654. // GPIO_Init(GPIOG, &GPIO_InitStructure);
  655. timingWrite.FSMC_AddressSetupTime = 4;
  656. timingWrite.FSMC_AddressHoldTime = 0;
  657. timingWrite.FSMC_DataSetupTime = 6;
  658. timingWrite.FSMC_BusTurnAroundDuration = 1;
  659. timingWrite.FSMC_CLKDivision = 0;
  660. timingWrite.FSMC_DataLatency = 0;
  661. timingWrite.FSMC_AccessMode = FSMC_AccessMode_A;
  662. timingRead.FSMC_AddressSetupTime = 4;
  663. timingRead.FSMC_AddressHoldTime = 0;
  664. timingRead.FSMC_DataSetupTime = 8;
  665. timingRead.FSMC_BusTurnAroundDuration = 1;
  666. timingRead.FSMC_CLKDivision = 0;
  667. timingRead.FSMC_DataLatency = 0;
  668. timingRead.FSMC_AccessMode = FSMC_AccessMode_A;
  669. init.FSMC_Bank = FSMC_Bank1_NORSRAM4;
  670. init.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
  671. init.FSMC_MemoryType = FSMC_MemoryType_SRAM;
  672. init.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
  673. init.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  674. init.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
  675. init.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  676. init.FSMC_WrapMode = FSMC_WrapMode_Disable;
  677. init.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  678. init.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  679. init.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
  680. init.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  681. init.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  682. init.FSMC_ReadWriteTimingStruct = &timingRead;
  683. init.FSMC_WriteTimingStruct = &timingWrite;
  684. FSMC_NORSRAMInit(&init);
  685. /* - BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
  686. FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
  687. ms_delay(50); // delay 50 ms
  688. LCD_WriteReg(0x0000, 0x0001);
  689. ms_delay(50); // delay 50 ms
  690. lcddev.id = LCD_ReadReg(0x0000);
  691. if (lcddev.id < 0XFF || lcddev.id == 0XFFFF || lcddev.id == 0X9300) //读到ID不正确,新增lcddev.id==0X9300判断,因为9341在未被复位的情况下会被读成9300
  692. {
  693. //尝试9341 ID的读取
  694. LCD_WR_REG(0XD3);
  695. LCD_RD_DATA(); // dummy read
  696. LCD_RD_DATA(); //读到0X00
  697. lcddev.id = LCD_RD_DATA(); //读取93
  698. lcddev.id <<= 8;
  699. lcddev.id |= LCD_RD_DATA(); //读取41
  700. if (lcddev.id != 0X9341) //非9341,尝试是不是6804
  701. {
  702. LCD_WR_REG(0XBF);
  703. LCD_RD_DATA(); // dummy read
  704. LCD_RD_DATA(); //读回0X01
  705. LCD_RD_DATA(); //读回0XD0
  706. lcddev.id = LCD_RD_DATA(); //这里读回0X68
  707. lcddev.id <<= 8;
  708. lcddev.id |= LCD_RD_DATA(); //这里读回0X04
  709. if (lcddev.id != 0X6804) //也不是6804,尝试看看是不是NT35310
  710. {
  711. LCD_WR_REG(0XD4);
  712. LCD_RD_DATA(); // dummy read
  713. LCD_RD_DATA(); //读回0X01
  714. lcddev.id = LCD_RD_DATA(); //读回0X53
  715. lcddev.id <<= 8;
  716. lcddev.id |= LCD_RD_DATA(); //这里读回0X10
  717. if (lcddev.id != 0X5310) //也不是NT35310,尝试看看是不是NT35510
  718. {
  719. LCD_WR_REG(0XDA00);
  720. LCD_RD_DATA(); //读回0X00
  721. LCD_WR_REG(0XDB00);
  722. lcddev.id = LCD_RD_DATA(); //读回0X80
  723. lcddev.id <<= 8;
  724. LCD_WR_REG(0XDC00);
  725. lcddev.id |= LCD_RD_DATA(); //读回0X00
  726. if (lcddev.id == 0x8000)
  727. lcddev.id = 0x5510; // NT35510读回的ID是8000H,为方便区分,我们强制设置为5510
  728. }
  729. }
  730. }
  731. }
  732. printf(" LCD ID:%x\r\n", lcddev.id); //打印LCD ID
  733. if (lcddev.id == 0X9341) // 9341初始化
  734. {
  735. LCD_WR_REG(0xCF);
  736. LCD_WR_DATA(0x00);
  737. LCD_WR_DATA(0xC1);
  738. LCD_WR_DATA(0X30);
  739. LCD_WR_REG(0xED);
  740. LCD_WR_DATA(0x64);
  741. LCD_WR_DATA(0x03);
  742. LCD_WR_DATA(0X12);
  743. LCD_WR_DATA(0X81);
  744. LCD_WR_REG(0xE8);
  745. LCD_WR_DATA(0x85);
  746. LCD_WR_DATA(0x10);
  747. LCD_WR_DATA(0x7A);
  748. LCD_WR_REG(0xCB);
  749. LCD_WR_DATA(0x39);
  750. LCD_WR_DATA(0x2C);
  751. LCD_WR_DATA(0x00);
  752. LCD_WR_DATA(0x34);
  753. LCD_WR_DATA(0x02);
  754. LCD_WR_REG(0xF7);
  755. LCD_WR_DATA(0x20);
  756. LCD_WR_REG(0xEA);
  757. LCD_WR_DATA(0x00);
  758. LCD_WR_DATA(0x00);
  759. LCD_WR_REG(0xC0); // Power control
  760. LCD_WR_DATA(0x1B); // VRH[5:0]
  761. LCD_WR_REG(0xC1); // Power control
  762. LCD_WR_DATA(0x01); // SAP[2:0];BT[3:0]
  763. LCD_WR_REG(0xC5); // VCM control
  764. LCD_WR_DATA(0x30); // 3F
  765. LCD_WR_DATA(0x30); // 3C
  766. LCD_WR_REG(0xC7); // VCM control2
  767. LCD_WR_DATA(0XB7);
  768. LCD_WR_REG(0x36); // Memory Access Control
  769. LCD_WR_DATA(0x48);
  770. LCD_WR_REG(0x3A);
  771. LCD_WR_DATA(0x55);
  772. LCD_WR_REG(0xB1);
  773. LCD_WR_DATA(0x00);
  774. LCD_WR_DATA(0x1A);
  775. LCD_WR_REG(0xB6); // Display Function Control
  776. LCD_WR_DATA(0x0A);
  777. LCD_WR_DATA(0xA2);
  778. LCD_WR_REG(0xF2); // 3Gamma Function Disable
  779. LCD_WR_DATA(0x00);
  780. LCD_WR_REG(0x26); // Gamma curve selected
  781. LCD_WR_DATA(0x01);
  782. LCD_WR_REG(0xE0); // Set Gamma
  783. LCD_WR_DATA(0x0F);
  784. LCD_WR_DATA(0x2A);
  785. LCD_WR_DATA(0x28);
  786. LCD_WR_DATA(0x08);
  787. LCD_WR_DATA(0x0E);
  788. LCD_WR_DATA(0x08);
  789. LCD_WR_DATA(0x54);
  790. LCD_WR_DATA(0XA9);
  791. LCD_WR_DATA(0x43);
  792. LCD_WR_DATA(0x0A);
  793. LCD_WR_DATA(0x0F);
  794. LCD_WR_DATA(0x00);
  795. LCD_WR_DATA(0x00);
  796. LCD_WR_DATA(0x00);
  797. LCD_WR_DATA(0x00);
  798. LCD_WR_REG(0XE1); // Set Gamma
  799. LCD_WR_DATA(0x00);
  800. LCD_WR_DATA(0x15);
  801. LCD_WR_DATA(0x17);
  802. LCD_WR_DATA(0x07);
  803. LCD_WR_DATA(0x11);
  804. LCD_WR_DATA(0x06);
  805. LCD_WR_DATA(0x2B);
  806. LCD_WR_DATA(0x56);
  807. LCD_WR_DATA(0x3C);
  808. LCD_WR_DATA(0x05);
  809. LCD_WR_DATA(0x10);
  810. LCD_WR_DATA(0x0F);
  811. LCD_WR_DATA(0x3F);
  812. LCD_WR_DATA(0x3F);
  813. LCD_WR_DATA(0x0F);
  814. LCD_WR_REG(0x2B);
  815. LCD_WR_DATA(0x00);
  816. LCD_WR_DATA(0x00);
  817. LCD_WR_DATA(0x01);
  818. LCD_WR_DATA(0x3f);
  819. LCD_WR_REG(0x2A);
  820. LCD_WR_DATA(0x00);
  821. LCD_WR_DATA(0x00);
  822. LCD_WR_DATA(0x00);
  823. LCD_WR_DATA(0xef);
  824. LCD_WR_REG(0x11); // Exit Sleep
  825. ms_delay(120);
  826. LCD_WR_REG(0x29); // display on
  827. }
  828. else if (lcddev.id == 0x6804) // 6804初始化
  829. {
  830. LCD_WR_REG(0X11);
  831. ms_delay(20);
  832. LCD_WR_REG(0XD0); // VCI1 VCL VGH VGL DDVDH VREG1OUT power amplitude setting
  833. LCD_WR_DATA(0X07);
  834. LCD_WR_DATA(0X42);
  835. LCD_WR_DATA(0X1D);
  836. LCD_WR_REG(0XD1); // VCOMH VCOM_AC amplitude setting
  837. LCD_WR_DATA(0X00);
  838. LCD_WR_DATA(0X1a);
  839. LCD_WR_DATA(0X09);
  840. LCD_WR_REG(0XD2); // Operational Amplifier Circuit Constant Current Adjust , charge pump frequency setting
  841. LCD_WR_DATA(0X01);
  842. LCD_WR_DATA(0X22);
  843. LCD_WR_REG(0XC0); // REV SM GS
  844. LCD_WR_DATA(0X10);
  845. LCD_WR_DATA(0X3B);
  846. LCD_WR_DATA(0X00);
  847. LCD_WR_DATA(0X02);
  848. LCD_WR_DATA(0X11);
  849. LCD_WR_REG(0XC5); // Frame rate setting = 72HZ when setting 0x03
  850. LCD_WR_DATA(0X03);
  851. LCD_WR_REG(0XC8); // Gamma setting
  852. LCD_WR_DATA(0X00);
  853. LCD_WR_DATA(0X25);
  854. LCD_WR_DATA(0X21);
  855. LCD_WR_DATA(0X05);
  856. LCD_WR_DATA(0X00);
  857. LCD_WR_DATA(0X0a);
  858. LCD_WR_DATA(0X65);
  859. LCD_WR_DATA(0X25);
  860. LCD_WR_DATA(0X77);
  861. LCD_WR_DATA(0X50);
  862. LCD_WR_DATA(0X0f);
  863. LCD_WR_DATA(0X00);
  864. LCD_WR_REG(0XF8);
  865. LCD_WR_DATA(0X01);
  866. LCD_WR_REG(0XFE);
  867. LCD_WR_DATA(0X00);
  868. LCD_WR_DATA(0X02);
  869. LCD_WR_REG(0X20); // Exit invert mode
  870. LCD_WR_REG(0X36);
  871. LCD_WR_DATA(0X08); //原来是a
  872. LCD_WR_REG(0X3A);
  873. LCD_WR_DATA(0X55); // 16位模式
  874. LCD_WR_REG(0X2B);
  875. LCD_WR_DATA(0X00);
  876. LCD_WR_DATA(0X00);
  877. LCD_WR_DATA(0X01);
  878. LCD_WR_DATA(0X3F);
  879. LCD_WR_REG(0X2A);
  880. LCD_WR_DATA(0X00);
  881. LCD_WR_DATA(0X00);
  882. LCD_WR_DATA(0X01);
  883. LCD_WR_DATA(0XDF);
  884. ms_delay(120);
  885. LCD_WR_REG(0X29);
  886. }
  887. else if (lcddev.id == 0x5310)
  888. {
  889. LCD_WR_REG(0xED);
  890. LCD_WR_DATA(0x01);
  891. LCD_WR_DATA(0xFE);
  892. LCD_WR_REG(0xEE);
  893. LCD_WR_DATA(0xDE);
  894. LCD_WR_DATA(0x21);
  895. LCD_WR_REG(0xF1);
  896. LCD_WR_DATA(0x01);
  897. LCD_WR_REG(0xDF);
  898. LCD_WR_DATA(0x10);
  899. // VCOMvoltage//
  900. LCD_WR_REG(0xC4);
  901. LCD_WR_DATA(0x8F); // 5f
  902. LCD_WR_REG(0xC6);
  903. LCD_WR_DATA(0x00);
  904. LCD_WR_DATA(0xE2);
  905. LCD_WR_DATA(0xE2);
  906. LCD_WR_DATA(0xE2);
  907. LCD_WR_REG(0xBF);
  908. LCD_WR_DATA(0xAA);
  909. LCD_WR_REG(0xB0);
  910. LCD_WR_DATA(0x0D);
  911. LCD_WR_DATA(0x00);
  912. LCD_WR_DATA(0x0D);
  913. LCD_WR_DATA(0x00);
  914. LCD_WR_DATA(0x11);
  915. LCD_WR_DATA(0x00);
  916. LCD_WR_DATA(0x19);
  917. LCD_WR_DATA(0x00);
  918. LCD_WR_DATA(0x21);
  919. LCD_WR_DATA(0x00);
  920. LCD_WR_DATA(0x2D);
  921. LCD_WR_DATA(0x00);
  922. LCD_WR_DATA(0x3D);
  923. LCD_WR_DATA(0x00);
  924. LCD_WR_DATA(0x5D);
  925. LCD_WR_DATA(0x00);
  926. LCD_WR_DATA(0x5D);
  927. LCD_WR_DATA(0x00);
  928. LCD_WR_REG(0xB1);
  929. LCD_WR_DATA(0x80);
  930. LCD_WR_DATA(0x00);
  931. LCD_WR_DATA(0x8B);
  932. LCD_WR_DATA(0x00);
  933. LCD_WR_DATA(0x96);
  934. LCD_WR_DATA(0x00);
  935. LCD_WR_REG(0xB2);
  936. LCD_WR_DATA(0x00);
  937. LCD_WR_DATA(0x00);
  938. LCD_WR_DATA(0x02);
  939. LCD_WR_DATA(0x00);
  940. LCD_WR_DATA(0x03);
  941. LCD_WR_DATA(0x00);
  942. LCD_WR_REG(0xB3);
  943. LCD_WR_DATA(0x00);
  944. LCD_WR_DATA(0x00);
  945. LCD_WR_DATA(0x00);
  946. LCD_WR_DATA(0x00);
  947. LCD_WR_DATA(0x00);
  948. LCD_WR_DATA(0x00);
  949. LCD_WR_DATA(0x00);
  950. LCD_WR_DATA(0x00);
  951. LCD_WR_DATA(0x00);
  952. LCD_WR_DATA(0x00);
  953. LCD_WR_DATA(0x00);
  954. LCD_WR_DATA(0x00);
  955. LCD_WR_DATA(0x00);
  956. LCD_WR_DATA(0x00);
  957. LCD_WR_DATA(0x00);
  958. LCD_WR_DATA(0x00);
  959. LCD_WR_DATA(0x00);
  960. LCD_WR_DATA(0x00);
  961. LCD_WR_DATA(0x00);
  962. LCD_WR_DATA(0x00);
  963. LCD_WR_DATA(0x00);
  964. LCD_WR_DATA(0x00);
  965. LCD_WR_DATA(0x00);
  966. LCD_WR_DATA(0x00);
  967. LCD_WR_REG(0xB4);
  968. LCD_WR_DATA(0x8B);
  969. LCD_WR_DATA(0x00);
  970. LCD_WR_DATA(0x96);
  971. LCD_WR_DATA(0x00);
  972. LCD_WR_DATA(0xA1);
  973. LCD_WR_DATA(0x00);
  974. LCD_WR_REG(0xB5);
  975. LCD_WR_DATA(0x02);
  976. LCD_WR_DATA(0x00);
  977. LCD_WR_DATA(0x03);
  978. LCD_WR_DATA(0x00);
  979. LCD_WR_DATA(0x04);
  980. LCD_WR_DATA(0x00);
  981. LCD_WR_REG(0xB6);
  982. LCD_WR_DATA(0x00);
  983. LCD_WR_DATA(0x00);
  984. LCD_WR_REG(0xB7);
  985. LCD_WR_DATA(0x00);
  986. LCD_WR_DATA(0x00);
  987. LCD_WR_DATA(0x3F);
  988. LCD_WR_DATA(0x00);
  989. LCD_WR_DATA(0x5E);
  990. LCD_WR_DATA(0x00);
  991. LCD_WR_DATA(0x64);
  992. LCD_WR_DATA(0x00);
  993. LCD_WR_DATA(0x8C);
  994. LCD_WR_DATA(0x00);
  995. LCD_WR_DATA(0xAC);
  996. LCD_WR_DATA(0x00);
  997. LCD_WR_DATA(0xDC);
  998. LCD_WR_DATA(0x00);
  999. LCD_WR_DATA(0x70);
  1000. LCD_WR_DATA(0x00);
  1001. LCD_WR_DATA(0x90);
  1002. LCD_WR_DATA(0x00);
  1003. LCD_WR_DATA(0xEB);
  1004. LCD_WR_DATA(0x00);
  1005. LCD_WR_DATA(0xDC);
  1006. LCD_WR_DATA(0x00);
  1007. LCD_WR_REG(0xB8);
  1008. LCD_WR_DATA(0x00);
  1009. LCD_WR_DATA(0x00);
  1010. LCD_WR_DATA(0x00);
  1011. LCD_WR_DATA(0x00);
  1012. LCD_WR_DATA(0x00);
  1013. LCD_WR_DATA(0x00);
  1014. LCD_WR_DATA(0x00);
  1015. LCD_WR_DATA(0x00);
  1016. LCD_WR_REG(0xBA);
  1017. LCD_WR_DATA(0x24);
  1018. LCD_WR_DATA(0x00);
  1019. LCD_WR_DATA(0x00);
  1020. LCD_WR_DATA(0x00);
  1021. LCD_WR_REG(0xC1);
  1022. LCD_WR_DATA(0x20);
  1023. LCD_WR_DATA(0x00);
  1024. LCD_WR_DATA(0x54);
  1025. LCD_WR_DATA(0x00);
  1026. LCD_WR_DATA(0xFF);
  1027. LCD_WR_DATA(0x00);
  1028. LCD_WR_REG(0xC2);
  1029. LCD_WR_DATA(0x0A);
  1030. LCD_WR_DATA(0x00);
  1031. LCD_WR_DATA(0x04);
  1032. LCD_WR_DATA(0x00);
  1033. LCD_WR_REG(0xC3);
  1034. LCD_WR_DATA(0x3C);
  1035. LCD_WR_DATA(0x00);
  1036. LCD_WR_DATA(0x3A);
  1037. LCD_WR_DATA(0x00);
  1038. LCD_WR_DATA(0x39);
  1039. LCD_WR_DATA(0x00);
  1040. LCD_WR_DATA(0x37);
  1041. LCD_WR_DATA(0x00);
  1042. LCD_WR_DATA(0x3C);
  1043. LCD_WR_DATA(0x00);
  1044. LCD_WR_DATA(0x36);
  1045. LCD_WR_DATA(0x00);
  1046. LCD_WR_DATA(0x32);
  1047. LCD_WR_DATA(0x00);
  1048. LCD_WR_DATA(0x2F);
  1049. LCD_WR_DATA(0x00);
  1050. LCD_WR_DATA(0x2C);
  1051. LCD_WR_DATA(0x00);
  1052. LCD_WR_DATA(0x29);
  1053. LCD_WR_DATA(0x00);
  1054. LCD_WR_DATA(0x26);
  1055. LCD_WR_DATA(0x00);
  1056. LCD_WR_DATA(0x24);
  1057. LCD_WR_DATA(0x00);
  1058. LCD_WR_DATA(0x24);
  1059. LCD_WR_DATA(0x00);
  1060. LCD_WR_DATA(0x23);
  1061. LCD_WR_DATA(0x00);
  1062. LCD_WR_DATA(0x3C);
  1063. LCD_WR_DATA(0x00);
  1064. LCD_WR_DATA(0x36);
  1065. LCD_WR_DATA(0x00);
  1066. LCD_WR_DATA(0x32);
  1067. LCD_WR_DATA(0x00);
  1068. LCD_WR_DATA(0x2F);
  1069. LCD_WR_DATA(0x00);
  1070. LCD_WR_DATA(0x2C);
  1071. LCD_WR_DATA(0x00);
  1072. LCD_WR_DATA(0x29);
  1073. LCD_WR_DATA(0x00);
  1074. LCD_WR_DATA(0x26);
  1075. LCD_WR_DATA(0x00);
  1076. LCD_WR_DATA(0x24);
  1077. LCD_WR_DATA(0x00);
  1078. LCD_WR_DATA(0x24);
  1079. LCD_WR_DATA(0x00);
  1080. LCD_WR_DATA(0x23);
  1081. LCD_WR_DATA(0x00);
  1082. LCD_WR_REG(0xC4);
  1083. LCD_WR_DATA(0x62);
  1084. LCD_WR_DATA(0x00);
  1085. LCD_WR_DATA(0x05);
  1086. LCD_WR_DATA(0x00);
  1087. LCD_WR_DATA(0x84);
  1088. LCD_WR_DATA(0x00);
  1089. LCD_WR_DATA(0xF0);
  1090. LCD_WR_DATA(0x00);
  1091. LCD_WR_DATA(0x18);
  1092. LCD_WR_DATA(0x00);
  1093. LCD_WR_DATA(0xA4);
  1094. LCD_WR_DATA(0x00);
  1095. LCD_WR_DATA(0x18);
  1096. LCD_WR_DATA(0x00);
  1097. LCD_WR_DATA(0x50);
  1098. LCD_WR_DATA(0x00);
  1099. LCD_WR_DATA(0x0C);
  1100. LCD_WR_DATA(0x00);
  1101. LCD_WR_DATA(0x17);
  1102. LCD_WR_DATA(0x00);
  1103. LCD_WR_DATA(0x95);
  1104. LCD_WR_DATA(0x00);
  1105. LCD_WR_DATA(0xF3);
  1106. LCD_WR_DATA(0x00);
  1107. LCD_WR_DATA(0xE6);
  1108. LCD_WR_DATA(0x00);
  1109. LCD_WR_REG(0xC5);
  1110. LCD_WR_DATA(0x32);
  1111. LCD_WR_DATA(0x00);
  1112. LCD_WR_DATA(0x44);
  1113. LCD_WR_DATA(0x00);
  1114. LCD_WR_DATA(0x65);
  1115. LCD_WR_DATA(0x00);
  1116. LCD_WR_DATA(0x76);
  1117. LCD_WR_DATA(0x00);
  1118. LCD_WR_DATA(0x88);
  1119. LCD_WR_DATA(0x00);
  1120. LCD_WR_REG(0xC6);
  1121. LCD_WR_DATA(0x20);
  1122. LCD_WR_DATA(0x00);
  1123. LCD_WR_DATA(0x17);
  1124. LCD_WR_DATA(0x00);
  1125. LCD_WR_DATA(0x01);
  1126. LCD_WR_DATA(0x00);
  1127. LCD_WR_REG(0xC7);
  1128. LCD_WR_DATA(0x00);
  1129. LCD_WR_DATA(0x00);
  1130. LCD_WR_DATA(0x00);
  1131. LCD_WR_DATA(0x00);
  1132. LCD_WR_REG(0xC8);
  1133. LCD_WR_DATA(0x00);
  1134. LCD_WR_DATA(0x00);
  1135. LCD_WR_DATA(0x00);
  1136. LCD_WR_DATA(0x00);
  1137. LCD_WR_REG(0xC9);
  1138. LCD_WR_DATA(0x00);
  1139. LCD_WR_DATA(0x00);
  1140. LCD_WR_DATA(0x00);
  1141. LCD_WR_DATA(0x00);
  1142. LCD_WR_DATA(0x00);
  1143. LCD_WR_DATA(0x00);
  1144. LCD_WR_DATA(0x00);
  1145. LCD_WR_DATA(0x00);
  1146. LCD_WR_DATA(0x00);
  1147. LCD_WR_DATA(0x00);
  1148. LCD_WR_DATA(0x00);
  1149. LCD_WR_DATA(0x00);
  1150. LCD_WR_DATA(0x00);
  1151. LCD_WR_DATA(0x00);
  1152. LCD_WR_DATA(0x00);
  1153. LCD_WR_DATA(0x00);
  1154. LCD_WR_REG(0xE0);
  1155. LCD_WR_DATA(0x16);
  1156. LCD_WR_DATA(0x00);
  1157. LCD_WR_DATA(0x1C);
  1158. LCD_WR_DATA(0x00);
  1159. LCD_WR_DATA(0x21);
  1160. LCD_WR_DATA(0x00);
  1161. LCD_WR_DATA(0x36);
  1162. LCD_WR_DATA(0x00);
  1163. LCD_WR_DATA(0x46);
  1164. LCD_WR_DATA(0x00);
  1165. LCD_WR_DATA(0x52);
  1166. LCD_WR_DATA(0x00);
  1167. LCD_WR_DATA(0x64);
  1168. LCD_WR_DATA(0x00);
  1169. LCD_WR_DATA(0x7A);
  1170. LCD_WR_DATA(0x00);
  1171. LCD_WR_DATA(0x8B);
  1172. LCD_WR_DATA(0x00);
  1173. LCD_WR_DATA(0x99);
  1174. LCD_WR_DATA(0x00);
  1175. LCD_WR_DATA(0xA8);
  1176. LCD_WR_DATA(0x00);
  1177. LCD_WR_DATA(0xB9);
  1178. LCD_WR_DATA(0x00);
  1179. LCD_WR_DATA(0xC4);
  1180. LCD_WR_DATA(0x00);
  1181. LCD_WR_DATA(0xCA);
  1182. LCD_WR_DATA(0x00);
  1183. LCD_WR_DATA(0xD2);
  1184. LCD_WR_DATA(0x00);
  1185. LCD_WR_DATA(0xD9);
  1186. LCD_WR_DATA(0x00);
  1187. LCD_WR_DATA(0xE0);
  1188. LCD_WR_DATA(0x00);
  1189. LCD_WR_DATA(0xF3);
  1190. LCD_WR_DATA(0x00);
  1191. LCD_WR_REG(0xE1);
  1192. LCD_WR_DATA(0x16);
  1193. LCD_WR_DATA(0x00);
  1194. LCD_WR_DATA(0x1C);
  1195. LCD_WR_DATA(0x00);
  1196. LCD_WR_DATA(0x22);
  1197. LCD_WR_DATA(0x00);
  1198. LCD_WR_DATA(0x36);
  1199. LCD_WR_DATA(0x00);
  1200. LCD_WR_DATA(0x45);
  1201. LCD_WR_DATA(0x00);
  1202. LCD_WR_DATA(0x52);
  1203. LCD_WR_DATA(0x00);
  1204. LCD_WR_DATA(0x64);
  1205. LCD_WR_DATA(0x00);
  1206. LCD_WR_DATA(0x7A);
  1207. LCD_WR_DATA(0x00);
  1208. LCD_WR_DATA(0x8B);
  1209. LCD_WR_DATA(0x00);
  1210. LCD_WR_DATA(0x99);
  1211. LCD_WR_DATA(0x00);
  1212. LCD_WR_DATA(0xA8);
  1213. LCD_WR_DATA(0x00);
  1214. LCD_WR_DATA(0xB9);
  1215. LCD_WR_DATA(0x00);
  1216. LCD_WR_DATA(0xC4);
  1217. LCD_WR_DATA(0x00);
  1218. LCD_WR_DATA(0xCA);
  1219. LCD_WR_DATA(0x00);
  1220. LCD_WR_DATA(0xD2);
  1221. LCD_WR_DATA(0x00);
  1222. LCD_WR_DATA(0xD8);
  1223. LCD_WR_DATA(0x00);
  1224. LCD_WR_DATA(0xE0);
  1225. LCD_WR_DATA(0x00);
  1226. LCD_WR_DATA(0xF3);
  1227. LCD_WR_DATA(0x00);
  1228. LCD_WR_REG(0xE2);
  1229. LCD_WR_DATA(0x05);
  1230. LCD_WR_DATA(0x00);
  1231. LCD_WR_DATA(0x0B);
  1232. LCD_WR_DATA(0x00);
  1233. LCD_WR_DATA(0x1B);
  1234. LCD_WR_DATA(0x00);
  1235. LCD_WR_DATA(0x34);
  1236. LCD_WR_DATA(0x00);
  1237. LCD_WR_DATA(0x44);
  1238. LCD_WR_DATA(0x00);
  1239. LCD_WR_DATA(0x4F);
  1240. LCD_WR_DATA(0x00);
  1241. LCD_WR_DATA(0x61);
  1242. LCD_WR_DATA(0x00);
  1243. LCD_WR_DATA(0x79);
  1244. LCD_WR_DATA(0x00);
  1245. LCD_WR_DATA(0x88);
  1246. LCD_WR_DATA(0x00);
  1247. LCD_WR_DATA(0x97);
  1248. LCD_WR_DATA(0x00);
  1249. LCD_WR_DATA(0xA6);
  1250. LCD_WR_DATA(0x00);
  1251. LCD_WR_DATA(0xB7);
  1252. LCD_WR_DATA(0x00);
  1253. LCD_WR_DATA(0xC2);
  1254. LCD_WR_DATA(0x00);
  1255. LCD_WR_DATA(0xC7);
  1256. LCD_WR_DATA(0x00);
  1257. LCD_WR_DATA(0xD1);
  1258. LCD_WR_DATA(0x00);
  1259. LCD_WR_DATA(0xD6);
  1260. LCD_WR_DATA(0x00);
  1261. LCD_WR_DATA(0xDD);
  1262. LCD_WR_DATA(0x00);
  1263. LCD_WR_DATA(0xF3);
  1264. LCD_WR_DATA(0x00);
  1265. LCD_WR_REG(0xE3);
  1266. LCD_WR_DATA(0x05);
  1267. LCD_WR_DATA(0x00);
  1268. LCD_WR_DATA(0xA);
  1269. LCD_WR_DATA(0x00);
  1270. LCD_WR_DATA(0x1C);
  1271. LCD_WR_DATA(0x00);
  1272. LCD_WR_DATA(0x33);
  1273. LCD_WR_DATA(0x00);
  1274. LCD_WR_DATA(0x44);
  1275. LCD_WR_DATA(0x00);
  1276. LCD_WR_DATA(0x50);
  1277. LCD_WR_DATA(0x00);
  1278. LCD_WR_DATA(0x62);
  1279. LCD_WR_DATA(0x00);
  1280. LCD_WR_DATA(0x78);
  1281. LCD_WR_DATA(0x00);
  1282. LCD_WR_DATA(0x88);
  1283. LCD_WR_DATA(0x00);
  1284. LCD_WR_DATA(0x97);
  1285. LCD_WR_DATA(0x00);
  1286. LCD_WR_DATA(0xA6);
  1287. LCD_WR_DATA(0x00);
  1288. LCD_WR_DATA(0xB7);
  1289. LCD_WR_DATA(0x00);
  1290. LCD_WR_DATA(0xC2);
  1291. LCD_WR_DATA(0x00);
  1292. LCD_WR_DATA(0xC7);
  1293. LCD_WR_DATA(0x00);
  1294. LCD_WR_DATA(0xD1);
  1295. LCD_WR_DATA(0x00);
  1296. LCD_WR_DATA(0xD5);
  1297. LCD_WR_DATA(0x00);
  1298. LCD_WR_DATA(0xDD);
  1299. LCD_WR_DATA(0x00);
  1300. LCD_WR_DATA(0xF3);
  1301. LCD_WR_DATA(0x00);
  1302. LCD_WR_REG(0xE4);
  1303. LCD_WR_DATA(0x01);
  1304. LCD_WR_DATA(0x00);
  1305. LCD_WR_DATA(0x01);
  1306. LCD_WR_DATA(0x00);
  1307. LCD_WR_DATA(0x02);
  1308. LCD_WR_DATA(0x00);
  1309. LCD_WR_DATA(0x2A);
  1310. LCD_WR_DATA(0x00);
  1311. LCD_WR_DATA(0x3C);
  1312. LCD_WR_DATA(0x00);
  1313. LCD_WR_DATA(0x4B);
  1314. LCD_WR_DATA(0x00);
  1315. LCD_WR_DATA(0x5D);
  1316. LCD_WR_DATA(0x00);
  1317. LCD_WR_DATA(0x74);
  1318. LCD_WR_DATA(0x00);
  1319. LCD_WR_DATA(0x84);
  1320. LCD_WR_DATA(0x00);
  1321. LCD_WR_DATA(0x93);
  1322. LCD_WR_DATA(0x00);
  1323. LCD_WR_DATA(0xA2);
  1324. LCD_WR_DATA(0x00);
  1325. LCD_WR_DATA(0xB3);
  1326. LCD_WR_DATA(0x00);
  1327. LCD_WR_DATA(0xBE);
  1328. LCD_WR_DATA(0x00);
  1329. LCD_WR_DATA(0xC4);
  1330. LCD_WR_DATA(0x00);
  1331. LCD_WR_DATA(0xCD);
  1332. LCD_WR_DATA(0x00);
  1333. LCD_WR_DATA(0xD3);
  1334. LCD_WR_DATA(0x00);
  1335. LCD_WR_DATA(0xDD);
  1336. LCD_WR_DATA(0x00);
  1337. LCD_WR_DATA(0xF3);
  1338. LCD_WR_DATA(0x00);
  1339. LCD_WR_REG(0xE5);
  1340. LCD_WR_DATA(0x00);
  1341. LCD_WR_DATA(0x00);
  1342. LCD_WR_DATA(0x00);
  1343. LCD_WR_DATA(0x00);
  1344. LCD_WR_DATA(0x02);
  1345. LCD_WR_DATA(0x00);
  1346. LCD_WR_DATA(0x29);
  1347. LCD_WR_DATA(0x00);
  1348. LCD_WR_DATA(0x3C);
  1349. LCD_WR_DATA(0x00);
  1350. LCD_WR_DATA(0x4B);
  1351. LCD_WR_DATA(0x00);
  1352. LCD_WR_DATA(0x5D);
  1353. LCD_WR_DATA(0x00);
  1354. LCD_WR_DATA(0x74);
  1355. LCD_WR_DATA(0x00);
  1356. LCD_WR_DATA(0x84);
  1357. LCD_WR_DATA(0x00);
  1358. LCD_WR_DATA(0x93);
  1359. LCD_WR_DATA(0x00);
  1360. LCD_WR_DATA(0xA2);
  1361. LCD_WR_DATA(0x00);
  1362. LCD_WR_DATA(0xB3);
  1363. LCD_WR_DATA(0x00);
  1364. LCD_WR_DATA(0xBE);
  1365. LCD_WR_DATA(0x00);
  1366. LCD_WR_DATA(0xC4);
  1367. LCD_WR_DATA(0x00);
  1368. LCD_WR_DATA(0xCD);
  1369. LCD_WR_DATA(0x00);
  1370. LCD_WR_DATA(0xD3);
  1371. LCD_WR_DATA(0x00);
  1372. LCD_WR_DATA(0xDC);
  1373. LCD_WR_DATA(0x00);
  1374. LCD_WR_DATA(0xF3);
  1375. LCD_WR_DATA(0x00);
  1376. LCD_WR_REG(0xE6);
  1377. LCD_WR_DATA(0x11);
  1378. LCD_WR_DATA(0x00);
  1379. LCD_WR_DATA(0x34);
  1380. LCD_WR_DATA(0x00);
  1381. LCD_WR_DATA(0x56);
  1382. LCD_WR_DATA(0x00);
  1383. LCD_WR_DATA(0x76);
  1384. LCD_WR_DATA(0x00);
  1385. LCD_WR_DATA(0x77);
  1386. LCD_WR_DATA(0x00);
  1387. LCD_WR_DATA(0x66);
  1388. LCD_WR_DATA(0x00);
  1389. LCD_WR_DATA(0x88);
  1390. LCD_WR_DATA(0x00);
  1391. LCD_WR_DATA(0x99);
  1392. LCD_WR_DATA(0x00);
  1393. LCD_WR_DATA(0xBB);
  1394. LCD_WR_DATA(0x00);
  1395. LCD_WR_DATA(0x99);
  1396. LCD_WR_DATA(0x00);
  1397. LCD_WR_DATA(0x66);
  1398. LCD_WR_DATA(0x00);
  1399. LCD_WR_DATA(0x55);
  1400. LCD_WR_DATA(0x00);
  1401. LCD_WR_DATA(0x55);
  1402. LCD_WR_DATA(0x00);
  1403. LCD_WR_DATA(0x45);
  1404. LCD_WR_DATA(0x00);
  1405. LCD_WR_DATA(0x43);
  1406. LCD_WR_DATA(0x00);
  1407. LCD_WR_DATA(0x44);
  1408. LCD_WR_DATA(0x00);
  1409. LCD_WR_REG(0xE7);
  1410. LCD_WR_DATA(0x32);
  1411. LCD_WR_DATA(0x00);
  1412. LCD_WR_DATA(0x55);
  1413. LCD_WR_DATA(0x00);
  1414. LCD_WR_DATA(0x76);
  1415. LCD_WR_DATA(0x00);
  1416. LCD_WR_DATA(0x66);
  1417. LCD_WR_DATA(0x00);
  1418. LCD_WR_DATA(0x67);
  1419. LCD_WR_DATA(0x00);
  1420. LCD_WR_DATA(0x67);
  1421. LCD_WR_DATA(0x00);
  1422. LCD_WR_DATA(0x87);
  1423. LCD_WR_DATA(0x00);
  1424. LCD_WR_DATA(0x99);
  1425. LCD_WR_DATA(0x00);
  1426. LCD_WR_DATA(0xBB);
  1427. LCD_WR_DATA(0x00);
  1428. LCD_WR_DATA(0x99);
  1429. LCD_WR_DATA(0x00);
  1430. LCD_WR_DATA(0x77);
  1431. LCD_WR_DATA(0x00);
  1432. LCD_WR_DATA(0x44);
  1433. LCD_WR_DATA(0x00);
  1434. LCD_WR_DATA(0x56);
  1435. LCD_WR_DATA(0x00);
  1436. LCD_WR_DATA(0x23);
  1437. LCD_WR_DATA(0x00);
  1438. LCD_WR_DATA(0x33);
  1439. LCD_WR_DATA(0x00);
  1440. LCD_WR_DATA(0x45);
  1441. LCD_WR_DATA(0x00);
  1442. LCD_WR_REG(0xE8);
  1443. LCD_WR_DATA(0x00);
  1444. LCD_WR_DATA(0x00);
  1445. LCD_WR_DATA(0x99);
  1446. LCD_WR_DATA(0x00);
  1447. LCD_WR_DATA(0x87);
  1448. LCD_WR_DATA(0x00);
  1449. LCD_WR_DATA(0x88);
  1450. LCD_WR_DATA(0x00);
  1451. LCD_WR_DATA(0x77);
  1452. LCD_WR_DATA(0x00);
  1453. LCD_WR_DATA(0x66);
  1454. LCD_WR_DATA(0x00);
  1455. LCD_WR_DATA(0x88);
  1456. LCD_WR_DATA(0x00);
  1457. LCD_WR_DATA(0xAA);
  1458. LCD_WR_DATA(0x00);
  1459. LCD_WR_DATA(0xBB);
  1460. LCD_WR_DATA(0x00);
  1461. LCD_WR_DATA(0x99);
  1462. LCD_WR_DATA(0x00);
  1463. LCD_WR_DATA(0x66);
  1464. LCD_WR_DATA(0x00);
  1465. LCD_WR_DATA(0x55);
  1466. LCD_WR_DATA(0x00);
  1467. LCD_WR_DATA(0x55);
  1468. LCD_WR_DATA(0x00);
  1469. LCD_WR_DATA(0x44);
  1470. LCD_WR_DATA(0x00);
  1471. LCD_WR_DATA(0x44);
  1472. LCD_WR_DATA(0x00);
  1473. LCD_WR_DATA(0x55);
  1474. LCD_WR_DATA(0x00);
  1475. LCD_WR_REG(0xE9);
  1476. LCD_WR_DATA(0xAA);
  1477. LCD_WR_DATA(0x00);
  1478. LCD_WR_DATA(0x00);
  1479. LCD_WR_DATA(0x00);
  1480. LCD_WR_REG(0x00);
  1481. LCD_WR_DATA(0xAA);
  1482. LCD_WR_REG(0xCF);
  1483. LCD_WR_DATA(0x00);
  1484. LCD_WR_DATA(0x00);
  1485. LCD_WR_DATA(0x00);
  1486. LCD_WR_DATA(0x00);
  1487. LCD_WR_DATA(0x00);
  1488. LCD_WR_DATA(0x00);
  1489. LCD_WR_DATA(0x00);
  1490. LCD_WR_DATA(0x00);
  1491. LCD_WR_DATA(0x00);
  1492. LCD_WR_DATA(0x00);
  1493. LCD_WR_DATA(0x00);
  1494. LCD_WR_DATA(0x00);
  1495. LCD_WR_DATA(0x00);
  1496. LCD_WR_DATA(0x00);
  1497. LCD_WR_DATA(0x00);
  1498. LCD_WR_DATA(0x00);
  1499. LCD_WR_DATA(0x00);
  1500. LCD_WR_REG(0xF0);
  1501. LCD_WR_DATA(0x00);
  1502. LCD_WR_DATA(0x50);
  1503. LCD_WR_DATA(0x00);
  1504. LCD_WR_DATA(0x00);
  1505. LCD_WR_DATA(0x00);
  1506. LCD_WR_REG(0xF3);
  1507. LCD_WR_DATA(0x00);
  1508. LCD_WR_REG(0xF9);
  1509. LCD_WR_DATA(0x06);
  1510. LCD_WR_DATA(0x10);
  1511. LCD_WR_DATA(0x29);
  1512. LCD_WR_DATA(0x00);
  1513. LCD_WR_REG(0x3A);
  1514. LCD_WR_DATA(0x55); // 66
  1515. LCD_WR_REG(0x11);
  1516. ms_delay(100);
  1517. LCD_WR_REG(0x29);
  1518. LCD_WR_REG(0x35);
  1519. LCD_WR_DATA(0x00);
  1520. LCD_WR_REG(0x51);
  1521. LCD_WR_DATA(0xFF);
  1522. LCD_WR_REG(0x53);
  1523. LCD_WR_DATA(0x2C);
  1524. LCD_WR_REG(0x55);
  1525. LCD_WR_DATA(0x82);
  1526. LCD_WR_REG(0x2c);
  1527. }
  1528. else if (lcddev.id == 0x5510)
  1529. {
  1530. LCD_WriteReg(0xF000, 0x55);
  1531. LCD_WriteReg(0xF001, 0xAA);
  1532. LCD_WriteReg(0xF002, 0x52);
  1533. LCD_WriteReg(0xF003, 0x08);
  1534. LCD_WriteReg(0xF004, 0x01);
  1535. // AVDD Set AVDD 5.2V
  1536. LCD_WriteReg(0xB000, 0x0D);
  1537. LCD_WriteReg(0xB001, 0x0D);
  1538. LCD_WriteReg(0xB002, 0x0D);
  1539. // AVDD ratio
  1540. LCD_WriteReg(0xB600, 0x34);
  1541. LCD_WriteReg(0xB601, 0x34);
  1542. LCD_WriteReg(0xB602, 0x34);
  1543. // AVEE -5.2V
  1544. LCD_WriteReg(0xB100, 0x0D);
  1545. LCD_WriteReg(0xB101, 0x0D);
  1546. LCD_WriteReg(0xB102, 0x0D);
  1547. // AVEE ratio
  1548. LCD_WriteReg(0xB700, 0x34);
  1549. LCD_WriteReg(0xB701, 0x34);
  1550. LCD_WriteReg(0xB702, 0x34);
  1551. // VCL -2.5V
  1552. LCD_WriteReg(0xB200, 0x00);
  1553. LCD_WriteReg(0xB201, 0x00);
  1554. LCD_WriteReg(0xB202, 0x00);
  1555. // VCL ratio
  1556. LCD_WriteReg(0xB800, 0x24);
  1557. LCD_WriteReg(0xB801, 0x24);
  1558. LCD_WriteReg(0xB802, 0x24);
  1559. // VGH 15V (Free pump)
  1560. LCD_WriteReg(0xBF00, 0x01);
  1561. LCD_WriteReg(0xB300, 0x0F);
  1562. LCD_WriteReg(0xB301, 0x0F);
  1563. LCD_WriteReg(0xB302, 0x0F);
  1564. // VGH ratio
  1565. LCD_WriteReg(0xB900, 0x34);
  1566. LCD_WriteReg(0xB901, 0x34);
  1567. LCD_WriteReg(0xB902, 0x34);
  1568. // VGL_REG -10V
  1569. LCD_WriteReg(0xB500, 0x08);
  1570. LCD_WriteReg(0xB501, 0x08);
  1571. LCD_WriteReg(0xB502, 0x08);
  1572. LCD_WriteReg(0xC200, 0x03);
  1573. // VGLX ratio
  1574. LCD_WriteReg(0xBA00, 0x24);
  1575. LCD_WriteReg(0xBA01, 0x24);
  1576. LCD_WriteReg(0xBA02, 0x24);
  1577. // VGMP/VGSP 4.5V/0V
  1578. LCD_WriteReg(0xBC00, 0x00);
  1579. LCD_WriteReg(0xBC01, 0x78);
  1580. LCD_WriteReg(0xBC02, 0x00);
  1581. // VGMN/VGSN -4.5V/0V
  1582. LCD_WriteReg(0xBD00, 0x00);
  1583. LCD_WriteReg(0xBD01, 0x78);
  1584. LCD_WriteReg(0xBD02, 0x00);
  1585. // VCOM
  1586. LCD_WriteReg(0xBE00, 0x00);
  1587. LCD_WriteReg(0xBE01, 0x64);
  1588. // Gamma Setting
  1589. LCD_WriteReg(0xD100, 0x00);
  1590. LCD_WriteReg(0xD101, 0x33);
  1591. LCD_WriteReg(0xD102, 0x00);
  1592. LCD_WriteReg(0xD103, 0x34);
  1593. LCD_WriteReg(0xD104, 0x00);
  1594. LCD_WriteReg(0xD105, 0x3A);
  1595. LCD_WriteReg(0xD106, 0x00);
  1596. LCD_WriteReg(0xD107, 0x4A);
  1597. LCD_WriteReg(0xD108, 0x00);
  1598. LCD_WriteReg(0xD109, 0x5C);
  1599. LCD_WriteReg(0xD10A, 0x00);
  1600. LCD_WriteReg(0xD10B, 0x81);
  1601. LCD_WriteReg(0xD10C, 0x00);
  1602. LCD_WriteReg(0xD10D, 0xA6);
  1603. LCD_WriteReg(0xD10E, 0x00);
  1604. LCD_WriteReg(0xD10F, 0xE5);
  1605. LCD_WriteReg(0xD110, 0x01);
  1606. LCD_WriteReg(0xD111, 0x13);
  1607. LCD_WriteReg(0xD112, 0x01);
  1608. LCD_WriteReg(0xD113, 0x54);
  1609. LCD_WriteReg(0xD114, 0x01);
  1610. LCD_WriteReg(0xD115, 0x82);
  1611. LCD_WriteReg(0xD116, 0x01);
  1612. LCD_WriteReg(0xD117, 0xCA);
  1613. LCD_WriteReg(0xD118, 0x02);
  1614. LCD_WriteReg(0xD119, 0x00);
  1615. LCD_WriteReg(0xD11A, 0x02);
  1616. LCD_WriteReg(0xD11B, 0x01);
  1617. LCD_WriteReg(0xD11C, 0x02);
  1618. LCD_WriteReg(0xD11D, 0x34);
  1619. LCD_WriteReg(0xD11E, 0x02);
  1620. LCD_WriteReg(0xD11F, 0x67);
  1621. LCD_WriteReg(0xD120, 0x02);
  1622. LCD_WriteReg(0xD121, 0x84);
  1623. LCD_WriteReg(0xD122, 0x02);
  1624. LCD_WriteReg(0xD123, 0xA4);
  1625. LCD_WriteReg(0xD124, 0x02);
  1626. LCD_WriteReg(0xD125, 0xB7);
  1627. LCD_WriteReg(0xD126, 0x02);
  1628. LCD_WriteReg(0xD127, 0xCF);
  1629. LCD_WriteReg(0xD128, 0x02);
  1630. LCD_WriteReg(0xD129, 0xDE);
  1631. LCD_WriteReg(0xD12A, 0x02);
  1632. LCD_WriteReg(0xD12B, 0xF2);
  1633. LCD_WriteReg(0xD12C, 0x02);
  1634. LCD_WriteReg(0xD12D, 0xFE);
  1635. LCD_WriteReg(0xD12E, 0x03);
  1636. LCD_WriteReg(0xD12F, 0x10);
  1637. LCD_WriteReg(0xD130, 0x03);
  1638. LCD_WriteReg(0xD131, 0x33);
  1639. LCD_WriteReg(0xD132, 0x03);
  1640. LCD_WriteReg(0xD133, 0x6D);
  1641. LCD_WriteReg(0xD200, 0x00);
  1642. LCD_WriteReg(0xD201, 0x33);
  1643. LCD_WriteReg(0xD202, 0x00);
  1644. LCD_WriteReg(0xD203, 0x34);
  1645. LCD_WriteReg(0xD204, 0x00);
  1646. LCD_WriteReg(0xD205, 0x3A);
  1647. LCD_WriteReg(0xD206, 0x00);
  1648. LCD_WriteReg(0xD207, 0x4A);
  1649. LCD_WriteReg(0xD208, 0x00);
  1650. LCD_WriteReg(0xD209, 0x5C);
  1651. LCD_WriteReg(0xD20A, 0x00);
  1652. LCD_WriteReg(0xD20B, 0x81);
  1653. LCD_WriteReg(0xD20C, 0x00);
  1654. LCD_WriteReg(0xD20D, 0xA6);
  1655. LCD_WriteReg(0xD20E, 0x00);
  1656. LCD_WriteReg(0xD20F, 0xE5);
  1657. LCD_WriteReg(0xD210, 0x01);
  1658. LCD_WriteReg(0xD211, 0x13);
  1659. LCD_WriteReg(0xD212, 0x01);
  1660. LCD_WriteReg(0xD213, 0x54);
  1661. LCD_WriteReg(0xD214, 0x01);
  1662. LCD_WriteReg(0xD215, 0x82);
  1663. LCD_WriteReg(0xD216, 0x01);
  1664. LCD_WriteReg(0xD217, 0xCA);
  1665. LCD_WriteReg(0xD218, 0x02);
  1666. LCD_WriteReg(0xD219, 0x00);
  1667. LCD_WriteReg(0xD21A, 0x02);
  1668. LCD_WriteReg(0xD21B, 0x01);
  1669. LCD_WriteReg(0xD21C, 0x02);
  1670. LCD_WriteReg(0xD21D, 0x34);
  1671. LCD_WriteReg(0xD21E, 0x02);
  1672. LCD_WriteReg(0xD21F, 0x67);
  1673. LCD_WriteReg(0xD220, 0x02);
  1674. LCD_WriteReg(0xD221, 0x84);
  1675. LCD_WriteReg(0xD222, 0x02);
  1676. LCD_WriteReg(0xD223, 0xA4);
  1677. LCD_WriteReg(0xD224, 0x02);
  1678. LCD_WriteReg(0xD225, 0xB7);
  1679. LCD_WriteReg(0xD226, 0x02);
  1680. LCD_WriteReg(0xD227, 0xCF);
  1681. LCD_WriteReg(0xD228, 0x02);
  1682. LCD_WriteReg(0xD229, 0xDE);
  1683. LCD_WriteReg(0xD22A, 0x02);
  1684. LCD_WriteReg(0xD22B, 0xF2);
  1685. LCD_WriteReg(0xD22C, 0x02);
  1686. LCD_WriteReg(0xD22D, 0xFE);
  1687. LCD_WriteReg(0xD22E, 0x03);
  1688. LCD_WriteReg(0xD22F, 0x10);
  1689. LCD_WriteReg(0xD230, 0x03);
  1690. LCD_WriteReg(0xD231, 0x33);
  1691. LCD_WriteReg(0xD232, 0x03);
  1692. LCD_WriteReg(0xD233, 0x6D);
  1693. LCD_WriteReg(0xD300, 0x00);
  1694. LCD_WriteReg(0xD301, 0x33);
  1695. LCD_WriteReg(0xD302, 0x00);
  1696. LCD_WriteReg(0xD303, 0x34);
  1697. LCD_WriteReg(0xD304, 0x00);
  1698. LCD_WriteReg(0xD305, 0x3A);
  1699. LCD_WriteReg(0xD306, 0x00);
  1700. LCD_WriteReg(0xD307, 0x4A);
  1701. LCD_WriteReg(0xD308, 0x00);
  1702. LCD_WriteReg(0xD309, 0x5C);
  1703. LCD_WriteReg(0xD30A, 0x00);
  1704. LCD_WriteReg(0xD30B, 0x81);
  1705. LCD_WriteReg(0xD30C, 0x00);
  1706. LCD_WriteReg(0xD30D, 0xA6);
  1707. LCD_WriteReg(0xD30E, 0x00);
  1708. LCD_WriteReg(0xD30F, 0xE5);
  1709. LCD_WriteReg(0xD310, 0x01);
  1710. LCD_WriteReg(0xD311, 0x13);
  1711. LCD_WriteReg(0xD312, 0x01);
  1712. LCD_WriteReg(0xD313, 0x54);
  1713. LCD_WriteReg(0xD314, 0x01);
  1714. LCD_WriteReg(0xD315, 0x82);
  1715. LCD_WriteReg(0xD316, 0x01);
  1716. LCD_WriteReg(0xD317, 0xCA);
  1717. LCD_WriteReg(0xD318, 0x02);
  1718. LCD_WriteReg(0xD319, 0x00);
  1719. LCD_WriteReg(0xD31A, 0x02);
  1720. LCD_WriteReg(0xD31B, 0x01);
  1721. LCD_WriteReg(0xD31C, 0x02);
  1722. LCD_WriteReg(0xD31D, 0x34);
  1723. LCD_WriteReg(0xD31E, 0x02);
  1724. LCD_WriteReg(0xD31F, 0x67);
  1725. LCD_WriteReg(0xD320, 0x02);
  1726. LCD_WriteReg(0xD321, 0x84);
  1727. LCD_WriteReg(0xD322, 0x02);
  1728. LCD_WriteReg(0xD323, 0xA4);
  1729. LCD_WriteReg(0xD324, 0x02);
  1730. LCD_WriteReg(0xD325, 0xB7);
  1731. LCD_WriteReg(0xD326, 0x02);
  1732. LCD_WriteReg(0xD327, 0xCF);
  1733. LCD_WriteReg(0xD328, 0x02);
  1734. LCD_WriteReg(0xD329, 0xDE);
  1735. LCD_WriteReg(0xD32A, 0x02);
  1736. LCD_WriteReg(0xD32B, 0xF2);
  1737. LCD_WriteReg(0xD32C, 0x02);
  1738. LCD_WriteReg(0xD32D, 0xFE);
  1739. LCD_WriteReg(0xD32E, 0x03);
  1740. LCD_WriteReg(0xD32F, 0x10);
  1741. LCD_WriteReg(0xD330, 0x03);
  1742. LCD_WriteReg(0xD331, 0x33);
  1743. LCD_WriteReg(0xD332, 0x03);
  1744. LCD_WriteReg(0xD333, 0x6D);
  1745. LCD_WriteReg(0xD400, 0x00);
  1746. LCD_WriteReg(0xD401, 0x33);
  1747. LCD_WriteReg(0xD402, 0x00);
  1748. LCD_WriteReg(0xD403, 0x34);
  1749. LCD_WriteReg(0xD404, 0x00);
  1750. LCD_WriteReg(0xD405, 0x3A);
  1751. LCD_WriteReg(0xD406, 0x00);
  1752. LCD_WriteReg(0xD407, 0x4A);
  1753. LCD_WriteReg(0xD408, 0x00);
  1754. LCD_WriteReg(0xD409, 0x5C);
  1755. LCD_WriteReg(0xD40A, 0x00);
  1756. LCD_WriteReg(0xD40B, 0x81);
  1757. LCD_WriteReg(0xD40C, 0x00);
  1758. LCD_WriteReg(0xD40D, 0xA6);
  1759. LCD_WriteReg(0xD40E, 0x00);
  1760. LCD_WriteReg(0xD40F, 0xE5);
  1761. LCD_WriteReg(0xD410, 0x01);
  1762. LCD_WriteReg(0xD411, 0x13);
  1763. LCD_WriteReg(0xD412, 0x01);
  1764. LCD_WriteReg(0xD413, 0x54);
  1765. LCD_WriteReg(0xD414, 0x01);
  1766. LCD_WriteReg(0xD415, 0x82);
  1767. LCD_WriteReg(0xD416, 0x01);
  1768. LCD_WriteReg(0xD417, 0xCA);
  1769. LCD_WriteReg(0xD418, 0x02);
  1770. LCD_WriteReg(0xD419, 0x00);
  1771. LCD_WriteReg(0xD41A, 0x02);
  1772. LCD_WriteReg(0xD41B, 0x01);
  1773. LCD_WriteReg(0xD41C, 0x02);
  1774. LCD_WriteReg(0xD41D, 0x34);
  1775. LCD_WriteReg(0xD41E, 0x02);
  1776. LCD_WriteReg(0xD41F, 0x67);
  1777. LCD_WriteReg(0xD420, 0x02);
  1778. LCD_WriteReg(0xD421, 0x84);
  1779. LCD_WriteReg(0xD422, 0x02);
  1780. LCD_WriteReg(0xD423, 0xA4);
  1781. LCD_WriteReg(0xD424, 0x02);
  1782. LCD_WriteReg(0xD425, 0xB7);
  1783. LCD_WriteReg(0xD426, 0x02);
  1784. LCD_WriteReg(0xD427, 0xCF);
  1785. LCD_WriteReg(0xD428, 0x02);
  1786. LCD_WriteReg(0xD429, 0xDE);
  1787. LCD_WriteReg(0xD42A, 0x02);
  1788. LCD_WriteReg(0xD42B, 0xF2);
  1789. LCD_WriteReg(0xD42C, 0x02);
  1790. LCD_WriteReg(0xD42D, 0xFE);
  1791. LCD_WriteReg(0xD42E, 0x03);
  1792. LCD_WriteReg(0xD42F, 0x10);
  1793. LCD_WriteReg(0xD430, 0x03);
  1794. LCD_WriteReg(0xD431, 0x33);
  1795. LCD_WriteReg(0xD432, 0x03);
  1796. LCD_WriteReg(0xD433, 0x6D);
  1797. LCD_WriteReg(0xD500, 0x00);
  1798. LCD_WriteReg(0xD501, 0x33);
  1799. LCD_WriteReg(0xD502, 0x00);
  1800. LCD_WriteReg(0xD503, 0x34);
  1801. LCD_WriteReg(0xD504, 0x00);
  1802. LCD_WriteReg(0xD505, 0x3A);
  1803. LCD_WriteReg(0xD506, 0x00);
  1804. LCD_WriteReg(0xD507, 0x4A);
  1805. LCD_WriteReg(0xD508, 0x00);
  1806. LCD_WriteReg(0xD509, 0x5C);
  1807. LCD_WriteReg(0xD50A, 0x00);
  1808. LCD_WriteReg(0xD50B, 0x81);
  1809. LCD_WriteReg(0xD50C, 0x00);
  1810. LCD_WriteReg(0xD50D, 0xA6);
  1811. LCD_WriteReg(0xD50E, 0x00);
  1812. LCD_WriteReg(0xD50F, 0xE5);
  1813. LCD_WriteReg(0xD510, 0x01);
  1814. LCD_WriteReg(0xD511, 0x13);
  1815. LCD_WriteReg(0xD512, 0x01);
  1816. LCD_WriteReg(0xD513, 0x54);
  1817. LCD_WriteReg(0xD514, 0x01);
  1818. LCD_WriteReg(0xD515, 0x82);
  1819. LCD_WriteReg(0xD516, 0x01);
  1820. LCD_WriteReg(0xD517, 0xCA);
  1821. LCD_WriteReg(0xD518, 0x02);
  1822. LCD_WriteReg(0xD519, 0x00);
  1823. LCD_WriteReg(0xD51A, 0x02);
  1824. LCD_WriteReg(0xD51B, 0x01);
  1825. LCD_WriteReg(0xD51C, 0x02);
  1826. LCD_WriteReg(0xD51D, 0x34);
  1827. LCD_WriteReg(0xD51E, 0x02);
  1828. LCD_WriteReg(0xD51F, 0x67);
  1829. LCD_WriteReg(0xD520, 0x02);
  1830. LCD_WriteReg(0xD521, 0x84);
  1831. LCD_WriteReg(0xD522, 0x02);
  1832. LCD_WriteReg(0xD523, 0xA4);
  1833. LCD_WriteReg(0xD524, 0x02);
  1834. LCD_WriteReg(0xD525, 0xB7);
  1835. LCD_WriteReg(0xD526, 0x02);
  1836. LCD_WriteReg(0xD527, 0xCF);
  1837. LCD_WriteReg(0xD528, 0x02);
  1838. LCD_WriteReg(0xD529, 0xDE);
  1839. LCD_WriteReg(0xD52A, 0x02);
  1840. LCD_WriteReg(0xD52B, 0xF2);
  1841. LCD_WriteReg(0xD52C, 0x02);
  1842. LCD_WriteReg(0xD52D, 0xFE);
  1843. LCD_WriteReg(0xD52E, 0x03);
  1844. LCD_WriteReg(0xD52F, 0x10);
  1845. LCD_WriteReg(0xD530, 0x03);
  1846. LCD_WriteReg(0xD531, 0x33);
  1847. LCD_WriteReg(0xD532, 0x03);
  1848. LCD_WriteReg(0xD533, 0x6D);
  1849. LCD_WriteReg(0xD600, 0x00);
  1850. LCD_WriteReg(0xD601, 0x33);
  1851. LCD_WriteReg(0xD602, 0x00);
  1852. LCD_WriteReg(0xD603, 0x34);
  1853. LCD_WriteReg(0xD604, 0x00);
  1854. LCD_WriteReg(0xD605, 0x3A);
  1855. LCD_WriteReg(0xD606, 0x00);
  1856. LCD_WriteReg(0xD607, 0x4A);
  1857. LCD_WriteReg(0xD608, 0x00);
  1858. LCD_WriteReg(0xD609, 0x5C);
  1859. LCD_WriteReg(0xD60A, 0x00);
  1860. LCD_WriteReg(0xD60B, 0x81);
  1861. LCD_WriteReg(0xD60C, 0x00);
  1862. LCD_WriteReg(0xD60D, 0xA6);
  1863. LCD_WriteReg(0xD60E, 0x00);
  1864. LCD_WriteReg(0xD60F, 0xE5);
  1865. LCD_WriteReg(0xD610, 0x01);
  1866. LCD_WriteReg(0xD611, 0x13);
  1867. LCD_WriteReg(0xD612, 0x01);
  1868. LCD_WriteReg(0xD613, 0x54);
  1869. LCD_WriteReg(0xD614, 0x01);
  1870. LCD_WriteReg(0xD615, 0x82);
  1871. LCD_WriteReg(0xD616, 0x01);
  1872. LCD_WriteReg(0xD617, 0xCA);
  1873. LCD_WriteReg(0xD618, 0x02);
  1874. LCD_WriteReg(0xD619, 0x00);
  1875. LCD_WriteReg(0xD61A, 0x02);
  1876. LCD_WriteReg(0xD61B, 0x01);
  1877. LCD_WriteReg(0xD61C, 0x02);
  1878. LCD_WriteReg(0xD61D, 0x34);
  1879. LCD_WriteReg(0xD61E, 0x02);
  1880. LCD_WriteReg(0xD61F, 0x67);
  1881. LCD_WriteReg(0xD620, 0x02);
  1882. LCD_WriteReg(0xD621, 0x84);
  1883. LCD_WriteReg(0xD622, 0x02);
  1884. LCD_WriteReg(0xD623, 0xA4);
  1885. LCD_WriteReg(0xD624, 0x02);
  1886. LCD_WriteReg(0xD625, 0xB7);
  1887. LCD_WriteReg(0xD626, 0x02);
  1888. LCD_WriteReg(0xD627, 0xCF);
  1889. LCD_WriteReg(0xD628, 0x02);
  1890. LCD_WriteReg(0xD629, 0xDE);
  1891. LCD_WriteReg(0xD62A, 0x02);
  1892. LCD_WriteReg(0xD62B, 0xF2);
  1893. LCD_WriteReg(0xD62C, 0x02);
  1894. LCD_WriteReg(0xD62D, 0xFE);
  1895. LCD_WriteReg(0xD62E, 0x03);
  1896. LCD_WriteReg(0xD62F, 0x10);
  1897. LCD_WriteReg(0xD630, 0x03);
  1898. LCD_WriteReg(0xD631, 0x33);
  1899. LCD_WriteReg(0xD632, 0x03);
  1900. LCD_WriteReg(0xD633, 0x6D);
  1901. // LV2 Page 0 enable
  1902. LCD_WriteReg(0xF000, 0x55);
  1903. LCD_WriteReg(0xF001, 0xAA);
  1904. LCD_WriteReg(0xF002, 0x52);
  1905. LCD_WriteReg(0xF003, 0x08);
  1906. LCD_WriteReg(0xF004, 0x00);
  1907. // Display control
  1908. LCD_WriteReg(0xB100, 0xCC);
  1909. LCD_WriteReg(0xB101, 0x00);
  1910. // Source hold time
  1911. LCD_WriteReg(0xB600, 0x05);
  1912. // Gate EQ control
  1913. LCD_WriteReg(0xB700, 0x70);
  1914. LCD_WriteReg(0xB701, 0x70);
  1915. // Source EQ control (Mode 2)
  1916. LCD_WriteReg(0xB800, 0x01);
  1917. LCD_WriteReg(0xB801, 0x03);
  1918. LCD_WriteReg(0xB802, 0x03);
  1919. LCD_WriteReg(0xB803, 0x03);
  1920. // Inversion mode (2-dot)
  1921. LCD_WriteReg(0xBC00, 0x02);
  1922. LCD_WriteReg(0xBC01, 0x00);
  1923. LCD_WriteReg(0xBC02, 0x00);
  1924. // Timing control 4H w/ 4-delay
  1925. LCD_WriteReg(0xC900, 0xD0);
  1926. LCD_WriteReg(0xC901, 0x02);
  1927. LCD_WriteReg(0xC902, 0x50);
  1928. LCD_WriteReg(0xC903, 0x50);
  1929. LCD_WriteReg(0xC904, 0x50);
  1930. LCD_WriteReg(0x3500, 0x00);
  1931. LCD_WriteReg(0x3A00, 0x55); // 16-bit/pixel
  1932. LCD_WR_REG(0x1100);
  1933. us_delay(120);
  1934. LCD_WR_REG(0x2900);
  1935. }
  1936. else if (lcddev.id == 0x9325) // 9325
  1937. {
  1938. LCD_WriteReg(0x00E5, 0x78F0);
  1939. LCD_WriteReg(0x0001, 0x0100);
  1940. LCD_WriteReg(0x0002, 0x0700);
  1941. LCD_WriteReg(0x0003, 0x1030);
  1942. LCD_WriteReg(0x0004, 0x0000);
  1943. LCD_WriteReg(0x0008, 0x0202);
  1944. LCD_WriteReg(0x0009, 0x0000);
  1945. LCD_WriteReg(0x000A, 0x0000);
  1946. LCD_WriteReg(0x000C, 0x0000);
  1947. LCD_WriteReg(0x000D, 0x0000);
  1948. LCD_WriteReg(0x000F, 0x0000);
  1949. // power on sequence VGHVGL
  1950. LCD_WriteReg(0x0010, 0x0000);
  1951. LCD_WriteReg(0x0011, 0x0007);
  1952. LCD_WriteReg(0x0012, 0x0000);
  1953. LCD_WriteReg(0x0013, 0x0000);
  1954. LCD_WriteReg(0x0007, 0x0000);
  1955. // vgh
  1956. LCD_WriteReg(0x0010, 0x1690);
  1957. LCD_WriteReg(0x0011, 0x0227);
  1958. // delayms(100);
  1959. // vregiout
  1960. LCD_WriteReg(0x0012, 0x009D); // 0x001b
  1961. // delayms(100);
  1962. // vom amplitude
  1963. LCD_WriteReg(0x0013, 0x1900);
  1964. // delayms(100);
  1965. // vom H
  1966. LCD_WriteReg(0x0029, 0x0025);
  1967. LCD_WriteReg(0x002B, 0x000D);
  1968. // gamma
  1969. LCD_WriteReg(0x0030, 0x0007);
  1970. LCD_WriteReg(0x0031, 0x0303);
  1971. LCD_WriteReg(0x0032, 0x0003); // 0006
  1972. LCD_WriteReg(0x0035, 0x0206);
  1973. LCD_WriteReg(0x0036, 0x0008);
  1974. LCD_WriteReg(0x0037, 0x0406);
  1975. LCD_WriteReg(0x0038, 0x0304); // 0200
  1976. LCD_WriteReg(0x0039, 0x0007);
  1977. LCD_WriteReg(0x003C, 0x0602); // 0504
  1978. LCD_WriteReg(0x003D, 0x0008);
  1979. // ram
  1980. LCD_WriteReg(0x0050, 0x0000);
  1981. LCD_WriteReg(0x0051, 0x00EF);
  1982. LCD_WriteReg(0x0052, 0x0000);
  1983. LCD_WriteReg(0x0053, 0x013F);
  1984. LCD_WriteReg(0x0060, 0xA700);
  1985. LCD_WriteReg(0x0061, 0x0001);
  1986. LCD_WriteReg(0x006A, 0x0000);
  1987. //
  1988. LCD_WriteReg(0x0080, 0x0000);
  1989. LCD_WriteReg(0x0081, 0x0000);
  1990. LCD_WriteReg(0x0082, 0x0000);
  1991. LCD_WriteReg(0x0083, 0x0000);
  1992. LCD_WriteReg(0x0084, 0x0000);
  1993. LCD_WriteReg(0x0085, 0x0000);
  1994. //
  1995. LCD_WriteReg(0x0090, 0x0010);
  1996. LCD_WriteReg(0x0092, 0x0600);
  1997. LCD_WriteReg(0x0007, 0x0133);
  1998. LCD_WriteReg(0x00, 0x0022); //
  1999. }
  2000. else if (lcddev.id == 0x9328) // ILI9328 OK
  2001. {
  2002. LCD_WriteReg(0x00EC, 0x108F); // internal timeing
  2003. LCD_WriteReg(0x00EF, 0x1234); // ADD
  2004. // LCD_WriteReg(0x00e7,0x0010);
  2005. // LCD_WriteReg(0x0000,0x0001);//开启内部时钟
  2006. LCD_WriteReg(0x0001, 0x0100);
  2007. LCD_WriteReg(0x0002, 0x0700); //电源开启
  2008. // LCD_WriteReg(0x0003,(1<<3)|(1<<4) ); //65K RGB
  2009. // DRIVE TABLE(寄存器 03H)
  2010. // BIT3=AM BIT4:5=ID0:1
  2011. // AM ID0 ID1 FUNCATION
  2012. // 0 0 0 R->L D->U
  2013. // 1 0 0 D->U R->L
  2014. // 0 1 0 L->R D->U
  2015. // 1 1 0 D->U L->R
  2016. // 0 0 1 R->L U->D
  2017. // 1 0 1 U->D R->L
  2018. // 0 1 1 L->R U->D 正常就用这个.
  2019. // 1 1 1 U->D L->R
  2020. LCD_WriteReg(0x0003, (1 << 12) | (3 << 4) | (0 << 3)); // 65K
  2021. LCD_WriteReg(0x0004, 0x0000);
  2022. LCD_WriteReg(0x0008, 0x0202);
  2023. LCD_WriteReg(0x0009, 0x0000);
  2024. LCD_WriteReg(0x000a, 0x0000); // display setting
  2025. LCD_WriteReg(0x000c, 0x0001); // display setting
  2026. LCD_WriteReg(0x000d, 0x0000); // 0f3c
  2027. LCD_WriteReg(0x000f, 0x0000);
  2028. //电源配置
  2029. LCD_WriteReg(0x0010, 0x0000);
  2030. LCD_WriteReg(0x0011, 0x0007);
  2031. LCD_WriteReg(0x0012, 0x0000);
  2032. LCD_WriteReg(0x0013, 0x0000);
  2033. LCD_WriteReg(0x0007, 0x0001);
  2034. ms_delay(50);
  2035. LCD_WriteReg(0x0010, 0x1490);
  2036. LCD_WriteReg(0x0011, 0x0227);
  2037. ms_delay(50);
  2038. LCD_WriteReg(0x0012, 0x008A);
  2039. ms_delay(50);
  2040. LCD_WriteReg(0x0013, 0x1a00);
  2041. LCD_WriteReg(0x0029, 0x0006);
  2042. LCD_WriteReg(0x002b, 0x000d);
  2043. ms_delay(50);
  2044. LCD_WriteReg(0x0020, 0x0000);
  2045. LCD_WriteReg(0x0021, 0x0000);
  2046. ms_delay(50);
  2047. //伽马校正
  2048. LCD_WriteReg(0x0030, 0x0000);
  2049. LCD_WriteReg(0x0031, 0x0604);
  2050. LCD_WriteReg(0x0032, 0x0305);
  2051. LCD_WriteReg(0x0035, 0x0000);
  2052. LCD_WriteReg(0x0036, 0x0C09);
  2053. LCD_WriteReg(0x0037, 0x0204);
  2054. LCD_WriteReg(0x0038, 0x0301);
  2055. LCD_WriteReg(0x0039, 0x0707);
  2056. LCD_WriteReg(0x003c, 0x0000);
  2057. LCD_WriteReg(0x003d, 0x0a0a);
  2058. ms_delay(50);
  2059. LCD_WriteReg(0x0050, 0x0000); //水平GRAM起始位置
  2060. LCD_WriteReg(0x0051, 0x00ef); //水平GRAM终止位置
  2061. LCD_WriteReg(0x0052, 0x0000); //垂直GRAM起始位置
  2062. LCD_WriteReg(0x0053, 0x013f); //垂直GRAM终止位置
  2063. LCD_WriteReg(0x0060, 0xa700);
  2064. LCD_WriteReg(0x0061, 0x0001);
  2065. LCD_WriteReg(0x006a, 0x0000);
  2066. LCD_WriteReg(0x0080, 0x0000);
  2067. LCD_WriteReg(0x0081, 0x0000);
  2068. LCD_WriteReg(0x0082, 0x0000);
  2069. LCD_WriteReg(0x0083, 0x0000);
  2070. LCD_WriteReg(0x0084, 0x0000);
  2071. LCD_WriteReg(0x0085, 0x0000);
  2072. LCD_WriteReg(0x0090, 0x0010);
  2073. LCD_WriteReg(0x0092, 0x0600);
  2074. //开启显示设置
  2075. LCD_WriteReg(0x0007, 0x0133);
  2076. }
  2077. else if (lcddev.id == 0x9320) //测试OK.
  2078. {
  2079. LCD_WriteReg(0x00, 0x0000);
  2080. LCD_WriteReg(0x01, 0x0100); // Driver Output Contral.
  2081. LCD_WriteReg(0x02, 0x0700); // LCD Driver Waveform Contral.
  2082. LCD_WriteReg(0x03, 0x1030); // Entry Mode Set.
  2083. // LCD_WriteReg(0x03,0x1018); //Entry Mode Set.
  2084. LCD_WriteReg(0x04, 0x0000); // Scalling Contral.
  2085. LCD_WriteReg(0x08, 0x0202); // Display Contral 2.(0x0207)
  2086. LCD_WriteReg(0x09, 0x0000); // Display Contral 3.(0x0000)
  2087. LCD_WriteReg(0x0a, 0x0000); // Frame Cycle Contal.(0x0000)
  2088. LCD_WriteReg(0x0c, (1 << 0)); // Extern Display Interface Contral 1.(0x0000)
  2089. LCD_WriteReg(0x0d, 0x0000); // Frame Maker Position.
  2090. LCD_WriteReg(0x0f, 0x0000); // Extern Display Interface Contral 2.
  2091. ms_delay(50);
  2092. LCD_WriteReg(0x07, 0x0101); // Display Contral.
  2093. ms_delay(50);
  2094. LCD_WriteReg(0x10, (1 << 12) | (0 << 8) | (1 << 7) | (1 << 6) | (0 << 4)); // Power Control 1.(0x16b0)
  2095. LCD_WriteReg(0x11, 0x0007); // Power Control 2.(0x0001)
  2096. LCD_WriteReg(0x12, (1 << 8) | (1 << 4) | (0 << 0)); // Power Control 3.(0x0138)
  2097. LCD_WriteReg(0x13, 0x0b00); // Power Control 4.
  2098. LCD_WriteReg(0x29, 0x0000); // Power Control 7.
  2099. LCD_WriteReg(0x2b, (1 << 14) | (1 << 4));
  2100. LCD_WriteReg(0x50, 0); // Set X Star
  2101. //水平GRAM终止位置Set X End.
  2102. LCD_WriteReg(0x51, 239); // Set Y Star
  2103. LCD_WriteReg(0x52, 0); // Set Y End.t.
  2104. LCD_WriteReg(0x53, 319); //
  2105. LCD_WriteReg(0x60, 0x2700); // Driver Output Control.
  2106. LCD_WriteReg(0x61, 0x0001); // Driver Output Control.
  2107. LCD_WriteReg(0x6a, 0x0000); // Vertical Srcoll Control.
  2108. LCD_WriteReg(0x80, 0x0000); // Display Position? Partial Display 1.
  2109. LCD_WriteReg(0x81, 0x0000); // RAM Address Start? Partial Display 1.
  2110. LCD_WriteReg(0x82, 0x0000); // RAM Address End-Partial Display 1.
  2111. LCD_WriteReg(0x83, 0x0000); // Displsy Position? Partial Display 2.
  2112. LCD_WriteReg(0x84, 0x0000); // RAM Address Start? Partial Display 2.
  2113. LCD_WriteReg(0x85, 0x0000); // RAM Address End? Partial Display 2.
  2114. LCD_WriteReg(0x90, (0 << 7) | (16 << 0)); // Frame Cycle Contral.(0x0013)
  2115. LCD_WriteReg(0x92, 0x0000); // Panel Interface Contral 2.(0x0000)
  2116. LCD_WriteReg(0x93, 0x0001); // Panel Interface Contral 3.
  2117. LCD_WriteReg(0x95, 0x0110); // Frame Cycle Contral.(0x0110)
  2118. LCD_WriteReg(0x97, (0 << 8)); //
  2119. LCD_WriteReg(0x98, 0x0000); // Frame Cycle Contral.
  2120. LCD_WriteReg(0x07, 0x0173); //(0x0173)
  2121. }
  2122. else if (lcddev.id == 0X9331) // OK |/|/|
  2123. {
  2124. LCD_WriteReg(0x00E7, 0x1014);
  2125. LCD_WriteReg(0x0001, 0x0100); // set SS and SM bit
  2126. LCD_WriteReg(0x0002, 0x0200); // set 1 line inversion
  2127. LCD_WriteReg(0x0003, (1 << 12) | (3 << 4) | (1 << 3)); // 65K
  2128. // LCD_WriteReg(0x0003, 0x1030); // set GRAM write direction and BGR=1.
  2129. LCD_WriteReg(0x0008, 0x0202); // set the back porch and front porch
  2130. LCD_WriteReg(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
  2131. LCD_WriteReg(0x000A, 0x0000); // FMARK function
  2132. LCD_WriteReg(0x000C, 0x0000); // RGB interface setting
  2133. LCD_WriteReg(0x000D, 0x0000); // Frame marker Position
  2134. LCD_WriteReg(0x000F, 0x0000); // RGB interface polarity
  2135. //*************Power On sequence ****************//
  2136. LCD_WriteReg(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
  2137. LCD_WriteReg(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
  2138. LCD_WriteReg(0x0012, 0x0000); // VREG1OUT voltage
  2139. LCD_WriteReg(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
  2140. ms_delay(200); // Dis-charge capacitor power voltage
  2141. LCD_WriteReg(0x0010, 0x1690); // SAP, BT[3:0], AP, DSTB, SLP, STB
  2142. LCD_WriteReg(0x0011, 0x0227); // DC1[2:0], DC0[2:0], VC[2:0]
  2143. ms_delay(50); // Delay 50ms
  2144. LCD_WriteReg(0x0012, 0x000C); // Internal reference voltage= Vci;
  2145. ms_delay(50); // Delay 50ms
  2146. LCD_WriteReg(0x0013, 0x0800); // Set VDV[4:0] for VCOM amplitude
  2147. LCD_WriteReg(0x0029, 0x0011); // Set VCM[5:0] for VCOMH
  2148. LCD_WriteReg(0x002B, 0x000B); // Set Frame Rate
  2149. ms_delay(50); // Delay 50ms
  2150. LCD_WriteReg(0x0020, 0x0000); // GRAM horizontal Address
  2151. LCD_WriteReg(0x0021, 0x013f); // GRAM Vertical Address
  2152. // ----------- Adjust the Gamma Curve ----------//
  2153. LCD_WriteReg(0x0030, 0x0000);
  2154. LCD_WriteReg(0x0031, 0x0106);
  2155. LCD_WriteReg(0x0032, 0x0000);
  2156. LCD_WriteReg(0x0035, 0x0204);
  2157. LCD_WriteReg(0x0036, 0x160A);
  2158. LCD_WriteReg(0x0037, 0x0707);
  2159. LCD_WriteReg(0x0038, 0x0106);
  2160. LCD_WriteReg(0x0039, 0x0707);
  2161. LCD_WriteReg(0x003C, 0x0402);
  2162. LCD_WriteReg(0x003D, 0x0C0F);
  2163. //------------------ Set GRAM area ---------------//
  2164. LCD_WriteReg(0x0050, 0x0000); // Horizontal GRAM Start Address
  2165. LCD_WriteReg(0x0051, 0x00EF); // Horizontal GRAM End Address
  2166. LCD_WriteReg(0x0052, 0x0000); // Vertical GRAM Start Address
  2167. LCD_WriteReg(0x0053, 0x013F); // Vertical GRAM Start Address
  2168. LCD_WriteReg(0x0060, 0x2700); // Gate Scan Line
  2169. LCD_WriteReg(0x0061, 0x0001); // NDL,VLE, REV
  2170. LCD_WriteReg(0x006A, 0x0000); // set scrolling line
  2171. //-------------- Partial Display Control ---------//
  2172. LCD_WriteReg(0x0080, 0x0000);
  2173. LCD_WriteReg(0x0081, 0x0000);
  2174. LCD_WriteReg(0x0082, 0x0000);
  2175. LCD_WriteReg(0x0083, 0x0000);
  2176. LCD_WriteReg(0x0084, 0x0000);
  2177. LCD_WriteReg(0x0085, 0x0000);
  2178. //-------------- Panel Control -------------------//
  2179. LCD_WriteReg(0x0090, 0x0010);
  2180. LCD_WriteReg(0x0092, 0x0600);
  2181. LCD_WriteReg(0x0007, 0x0133); // 262K color and display ON
  2182. }
  2183. else if (lcddev.id == 0x5408)
  2184. {
  2185. LCD_WriteReg(0x01, 0x0100);
  2186. LCD_WriteReg(0x02, 0x0700); // LCD Driving Waveform Contral
  2187. LCD_WriteReg(0x03, 0x1030); // Entry Mode设置
  2188. //指针从左至右自上而下的自动增模式
  2189. // Normal Mode(Window Mode disable)
  2190. // RGB格式
  2191. // 16位数据2次传输的8总线设置
  2192. LCD_WriteReg(0x04, 0x0000); // Scalling Control register
  2193. LCD_WriteReg(0x08, 0x0207); // Display Control 2
  2194. LCD_WriteReg(0x09, 0x0000); // Display Control 3
  2195. LCD_WriteReg(0x0A, 0x0000); // Frame Cycle Control
  2196. LCD_WriteReg(0x0C, 0x0000); // External Display Interface Control 1
  2197. LCD_WriteReg(0x0D, 0x0000); // Frame Maker Position
  2198. LCD_WriteReg(0x0F, 0x0000); // External Display Interface Control 2
  2199. ms_delay(20);
  2200. // TFT 液晶彩色图像显示方法14
  2201. LCD_WriteReg(0x10, 0x16B0); // 0x14B0 //Power Control 1
  2202. LCD_WriteReg(0x11, 0x0001); // 0x0007 //Power Control 2
  2203. LCD_WriteReg(0x17, 0x0001); // 0x0000 //Power Control 3
  2204. LCD_WriteReg(0x12, 0x0138); // 0x013B //Power Control 4
  2205. LCD_WriteReg(0x13, 0x0800); // 0x0800 //Power Control 5
  2206. LCD_WriteReg(0x29, 0x0009); // NVM read data 2
  2207. LCD_WriteReg(0x2a, 0x0009); // NVM read data 3
  2208. LCD_WriteReg(0xa4, 0x0000);
  2209. LCD_WriteReg(0x50, 0x0000); //设置操作窗口的X轴开始列
  2210. LCD_WriteReg(0x51, 0x00EF); //设置操作窗口的X轴结束列
  2211. LCD_WriteReg(0x52, 0x0000); //设置操作窗口的Y轴开始行
  2212. LCD_WriteReg(0x53, 0x013F); //设置操作窗口的Y轴结束行
  2213. LCD_WriteReg(0x60, 0x2700); // Driver Output Control
  2214. //设置屏幕的点数以及扫描的起始行
  2215. LCD_WriteReg(0x61, 0x0001); // Driver Output Control
  2216. LCD_WriteReg(0x6A, 0x0000); // Vertical Scroll Control
  2217. LCD_WriteReg(0x80, 0x0000); // Display Position – Partial Display 1
  2218. LCD_WriteReg(0x81, 0x0000); // RAM Address Start – Partial Display 1
  2219. LCD_WriteReg(0x82, 0x0000); // RAM address End - Partial Display 1
  2220. LCD_WriteReg(0x83, 0x0000); // Display Position – Partial Display 2
  2221. LCD_WriteReg(0x84, 0x0000); // RAM Address Start – Partial Display 2
  2222. LCD_WriteReg(0x85, 0x0000); // RAM address End – Partail Display2
  2223. LCD_WriteReg(0x90, 0x0013); // Frame Cycle Control
  2224. LCD_WriteReg(0x92, 0x0000); // Panel Interface Control 2
  2225. LCD_WriteReg(0x93, 0x0003); // Panel Interface control 3
  2226. LCD_WriteReg(0x95, 0x0110); // Frame Cycle Control
  2227. LCD_WriteReg(0x07, 0x0173);
  2228. ms_delay(50);
  2229. }
  2230. else if (lcddev.id == 0x1505) // OK
  2231. {
  2232. // second release on 3/5 ,luminance is acceptable,water wave appear during camera preview
  2233. LCD_WriteReg(0x0007, 0x0000);
  2234. ms_delay(50);
  2235. LCD_WriteReg(0x0012, 0x011C); // 0x011A why need to set several times?
  2236. LCD_WriteReg(0x00A4, 0x0001); // NVM
  2237. LCD_WriteReg(0x0008, 0x000F);
  2238. LCD_WriteReg(0x000A, 0x0008);
  2239. LCD_WriteReg(0x000D, 0x0008);
  2240. //伽马校正
  2241. LCD_WriteReg(0x0030, 0x0707);
  2242. LCD_WriteReg(0x0031, 0x0007); // 0x0707
  2243. LCD_WriteReg(0x0032, 0x0603);
  2244. LCD_WriteReg(0x0033, 0x0700);
  2245. LCD_WriteReg(0x0034, 0x0202);
  2246. LCD_WriteReg(0x0035, 0x0002); //?0x0606
  2247. LCD_WriteReg(0x0036, 0x1F0F);
  2248. LCD_WriteReg(0x0037, 0x0707); // 0x0f0f 0x0105
  2249. LCD_WriteReg(0x0038, 0x0000);
  2250. LCD_WriteReg(0x0039, 0x0000);
  2251. LCD_WriteReg(0x003A, 0x0707);
  2252. LCD_WriteReg(0x003B, 0x0000); // 0x0303
  2253. LCD_WriteReg(0x003C, 0x0007); //?0x0707
  2254. LCD_WriteReg(0x003D, 0x0000); // 0x1313//0x1f08
  2255. ms_delay(50);
  2256. LCD_WriteReg(0x0007, 0x0001);
  2257. LCD_WriteReg(0x0017, 0x0001); //开启电源
  2258. ms_delay(50);
  2259. //电源配置
  2260. LCD_WriteReg(0x0010, 0x17A0);
  2261. LCD_WriteReg(0x0011, 0x0217); // reference voltage VC[2:0] Vciout = 1.00*Vcivl
  2262. LCD_WriteReg(0x0012, 0x011E); // 0x011c //Vreg1out = Vcilvl*1.80 is it the same as Vgama1out ?
  2263. LCD_WriteReg(0x0013, 0x0F00); // VDV[4:0]-->VCOM Amplitude VcomL = VcomH - Vcom Ampl
  2264. LCD_WriteReg(0x002A, 0x0000);
  2265. LCD_WriteReg(0x0029, 0x000A); // 0x0001F Vcomh = VCM1[4:0]*Vreg1out gate source voltage??
  2266. LCD_WriteReg(0x0012, 0x013E); // 0x013C power supply on
  2267. // Coordinates Control//
  2268. LCD_WriteReg(0x0050, 0x0000); // 0x0e00
  2269. LCD_WriteReg(0x0051, 0x00EF);
  2270. LCD_WriteReg(0x0052, 0x0000);
  2271. LCD_WriteReg(0x0053, 0x013F);
  2272. // Pannel Image Control//
  2273. LCD_WriteReg(0x0060, 0x2700);
  2274. LCD_WriteReg(0x0061, 0x0001);
  2275. LCD_WriteReg(0x006A, 0x0000);
  2276. LCD_WriteReg(0x0080, 0x0000);
  2277. // Partial Image Control//
  2278. LCD_WriteReg(0x0081, 0x0000);
  2279. LCD_WriteReg(0x0082, 0x0000);
  2280. LCD_WriteReg(0x0083, 0x0000);
  2281. LCD_WriteReg(0x0084, 0x0000);
  2282. LCD_WriteReg(0x0085, 0x0000);
  2283. // Panel Interface Control//
  2284. LCD_WriteReg(0x0090, 0x0013); // 0x0010 frenqucy
  2285. LCD_WriteReg(0x0092, 0x0300);
  2286. LCD_WriteReg(0x0093, 0x0005);
  2287. LCD_WriteReg(0x0095, 0x0000);
  2288. LCD_WriteReg(0x0097, 0x0000);
  2289. LCD_WriteReg(0x0098, 0x0000);
  2290. LCD_WriteReg(0x0001, 0x0100);
  2291. LCD_WriteReg(0x0002, 0x0700);
  2292. LCD_WriteReg(0x0003, 0x1038); //扫描方向 上->下 左->右
  2293. LCD_WriteReg(0x0004, 0x0000);
  2294. LCD_WriteReg(0x000C, 0x0000);
  2295. LCD_WriteReg(0x000F, 0x0000);
  2296. LCD_WriteReg(0x0020, 0x0000);
  2297. LCD_WriteReg(0x0021, 0x0000);
  2298. LCD_WriteReg(0x0007, 0x0021);
  2299. ms_delay(20);
  2300. LCD_WriteReg(0x0007, 0x0061);
  2301. ms_delay(20);
  2302. LCD_WriteReg(0x0007, 0x0173);
  2303. ms_delay(20);
  2304. }
  2305. else if (lcddev.id == 0xB505)
  2306. {
  2307. LCD_WriteReg(0x0000, 0x0000);
  2308. LCD_WriteReg(0x0000, 0x0000);
  2309. LCD_WriteReg(0x0000, 0x0000);
  2310. LCD_WriteReg(0x0000, 0x0000);
  2311. LCD_WriteReg(0x00a4, 0x0001);
  2312. ms_delay(20);
  2313. LCD_WriteReg(0x0060, 0x2700);
  2314. LCD_WriteReg(0x0008, 0x0202);
  2315. LCD_WriteReg(0x0030, 0x0214);
  2316. LCD_WriteReg(0x0031, 0x3715);
  2317. LCD_WriteReg(0x0032, 0x0604);
  2318. LCD_WriteReg(0x0033, 0x0e16);
  2319. LCD_WriteReg(0x0034, 0x2211);
  2320. LCD_WriteReg(0x0035, 0x1500);
  2321. LCD_WriteReg(0x0036, 0x8507);
  2322. LCD_WriteReg(0x0037, 0x1407);
  2323. LCD_WriteReg(0x0038, 0x1403);
  2324. LCD_WriteReg(0x0039, 0x0020);
  2325. LCD_WriteReg(0x0090, 0x001a);
  2326. LCD_WriteReg(0x0010, 0x0000);
  2327. LCD_WriteReg(0x0011, 0x0007);
  2328. LCD_WriteReg(0x0012, 0x0000);
  2329. LCD_WriteReg(0x0013, 0x0000);
  2330. ms_delay(20);
  2331. LCD_WriteReg(0x0010, 0x0730);
  2332. LCD_WriteReg(0x0011, 0x0137);
  2333. ms_delay(20);
  2334. LCD_WriteReg(0x0012, 0x01b8);
  2335. ms_delay(20);
  2336. LCD_WriteReg(0x0013, 0x0f00);
  2337. LCD_WriteReg(0x002a, 0x0080);
  2338. LCD_WriteReg(0x0029, 0x0048);
  2339. ms_delay(20);
  2340. LCD_WriteReg(0x0001, 0x0100);
  2341. LCD_WriteReg(0x0002, 0x0700);
  2342. LCD_WriteReg(0x0003, 0x1038); //扫描方向 上->下 左->右
  2343. LCD_WriteReg(0x0008, 0x0202);
  2344. LCD_WriteReg(0x000a, 0x0000);
  2345. LCD_WriteReg(0x000c, 0x0000);
  2346. LCD_WriteReg(0x000d, 0x0000);
  2347. LCD_WriteReg(0x000e, 0x0030);
  2348. LCD_WriteReg(0x0050, 0x0000);
  2349. LCD_WriteReg(0x0051, 0x00ef);
  2350. LCD_WriteReg(0x0052, 0x0000);
  2351. LCD_WriteReg(0x0053, 0x013f);
  2352. LCD_WriteReg(0x0060, 0x2700);
  2353. LCD_WriteReg(0x0061, 0x0001);
  2354. LCD_WriteReg(0x006a, 0x0000);
  2355. // LCD_WriteReg(0x0080,0x0000);
  2356. // LCD_WriteReg(0x0081,0x0000);
  2357. LCD_WriteReg(0x0090, 0X0011);
  2358. LCD_WriteReg(0x0092, 0x0600);
  2359. LCD_WriteReg(0x0093, 0x0402);
  2360. LCD_WriteReg(0x0094, 0x0002);
  2361. ms_delay(20);
  2362. LCD_WriteReg(0x0007, 0x0001);
  2363. ms_delay(20);
  2364. LCD_WriteReg(0x0007, 0x0061);
  2365. LCD_WriteReg(0x0007, 0x0173);
  2366. LCD_WriteReg(0x0020, 0x0000);
  2367. LCD_WriteReg(0x0021, 0x0000);
  2368. LCD_WriteReg(0x00, 0x22);
  2369. }
  2370. else if (lcddev.id == 0xC505)
  2371. {
  2372. LCD_WriteReg(0x0000, 0x0000);
  2373. LCD_WriteReg(0x0000, 0x0000);
  2374. ms_delay(20);
  2375. LCD_WriteReg(0x0000, 0x0000);
  2376. LCD_WriteReg(0x0000, 0x0000);
  2377. LCD_WriteReg(0x0000, 0x0000);
  2378. LCD_WriteReg(0x0000, 0x0000);
  2379. LCD_WriteReg(0x00a4, 0x0001);
  2380. ms_delay(20);
  2381. LCD_WriteReg(0x0060, 0x2700);
  2382. LCD_WriteReg(0x0008, 0x0806);
  2383. LCD_WriteReg(0x0030, 0x0703); // gamma setting
  2384. LCD_WriteReg(0x0031, 0x0001);
  2385. LCD_WriteReg(0x0032, 0x0004);
  2386. LCD_WriteReg(0x0033, 0x0102);
  2387. LCD_WriteReg(0x0034, 0x0300);
  2388. LCD_WriteReg(0x0035, 0x0103);
  2389. LCD_WriteReg(0x0036, 0x001F);
  2390. LCD_WriteReg(0x0037, 0x0703);
  2391. LCD_WriteReg(0x0038, 0x0001);
  2392. LCD_WriteReg(0x0039, 0x0004);
  2393. LCD_WriteReg(0x0090, 0x0015); // 80Hz
  2394. LCD_WriteReg(0x0010, 0X0410); // BT,AP
  2395. LCD_WriteReg(0x0011, 0x0247); // DC1,DC0,VC
  2396. LCD_WriteReg(0x0012, 0x01BC);
  2397. LCD_WriteReg(0x0013, 0x0e00);
  2398. ms_delay(120);
  2399. LCD_WriteReg(0x0001, 0x0100);
  2400. LCD_WriteReg(0x0002, 0x0200);
  2401. LCD_WriteReg(0x0003, 0x1030);
  2402. LCD_WriteReg(0x000A, 0x0008);
  2403. LCD_WriteReg(0x000C, 0x0000);
  2404. LCD_WriteReg(0x000E, 0x0020);
  2405. LCD_WriteReg(0x000F, 0x0000);
  2406. LCD_WriteReg(0x0020, 0x0000); // H Start
  2407. LCD_WriteReg(0x0021, 0x0000); // V Start
  2408. LCD_WriteReg(0x002A, 0x003D); // vcom2
  2409. ms_delay(20);
  2410. LCD_WriteReg(0x0029, 0x002d);
  2411. LCD_WriteReg(0x0050, 0x0000);
  2412. LCD_WriteReg(0x0051, 0xD0EF);
  2413. LCD_WriteReg(0x0052, 0x0000);
  2414. LCD_WriteReg(0x0053, 0x013F);
  2415. LCD_WriteReg(0x0061, 0x0000);
  2416. LCD_WriteReg(0x006A, 0x0000);
  2417. LCD_WriteReg(0x0092, 0x0300);
  2418. LCD_WriteReg(0x0093, 0x0005);
  2419. LCD_WriteReg(0x0007, 0x0100);
  2420. }
  2421. else if (lcddev.id == 0x8989) // OK |/|/|
  2422. {
  2423. LCD_WriteReg(0x0000, 0x0001); //打开晶振
  2424. LCD_WriteReg(0x0003, 0xA8A4); // 0xA8A4
  2425. LCD_WriteReg(0x000C, 0x0000);
  2426. LCD_WriteReg(0x000D, 0x080C);
  2427. LCD_WriteReg(0x000E, 0x2B00);
  2428. LCD_WriteReg(0x001E, 0x00B0);
  2429. LCD_WriteReg(0x0001, 0x2B3F); //驱动输出控制320*240 0x6B3F
  2430. LCD_WriteReg(0x0002, 0x0600);
  2431. LCD_WriteReg(0x0010, 0x0000);
  2432. LCD_WriteReg(0x0011, 0x6078); //定义数据格式 16位色 横屏 0x6058
  2433. LCD_WriteReg(0x0005, 0x0000);
  2434. LCD_WriteReg(0x0006, 0x0000);
  2435. LCD_WriteReg(0x0016, 0xEF1C);
  2436. LCD_WriteReg(0x0017, 0x0003);
  2437. LCD_WriteReg(0x0007, 0x0233); // 0x0233
  2438. LCD_WriteReg(0x000B, 0x0000);
  2439. LCD_WriteReg(0x000F, 0x0000); //扫描开始地址
  2440. LCD_WriteReg(0x0041, 0x0000);
  2441. LCD_WriteReg(0x0042, 0x0000);
  2442. LCD_WriteReg(0x0048, 0x0000);
  2443. LCD_WriteReg(0x0049, 0x013F);
  2444. LCD_WriteReg(0x004A, 0x0000);
  2445. LCD_WriteReg(0x004B, 0x0000);
  2446. LCD_WriteReg(0x0044, 0xEF00);
  2447. LCD_WriteReg(0x0045, 0x0000);
  2448. LCD_WriteReg(0x0046, 0x013F);
  2449. LCD_WriteReg(0x0030, 0x0707);
  2450. LCD_WriteReg(0x0031, 0x0204);
  2451. LCD_WriteReg(0x0032, 0x0204);
  2452. LCD_WriteReg(0x0033, 0x0502);
  2453. LCD_WriteReg(0x0034, 0x0507);
  2454. LCD_WriteReg(0x0035, 0x0204);
  2455. LCD_WriteReg(0x0036, 0x0204);
  2456. LCD_WriteReg(0x0037, 0x0502);
  2457. LCD_WriteReg(0x003A, 0x0302);
  2458. LCD_WriteReg(0x003B, 0x0302);
  2459. LCD_WriteReg(0x0023, 0x0000);
  2460. LCD_WriteReg(0x0024, 0x0000);
  2461. LCD_WriteReg(0x0025, 0x8000);
  2462. LCD_WriteReg(0x004f, 0); //行首址0
  2463. LCD_WriteReg(0x004e, 0); //列首址0
  2464. }
  2465. else if (lcddev.id == 0x4531) // OK |/|/|
  2466. {
  2467. LCD_WriteReg(0X00, 0X0001);
  2468. ms_delay(10);
  2469. LCD_WriteReg(0X10, 0X1628);
  2470. LCD_WriteReg(0X12, 0X000e); // 0x0006
  2471. LCD_WriteReg(0X13, 0X0A39);
  2472. ms_delay(10);
  2473. LCD_WriteReg(0X11, 0X0040);
  2474. LCD_WriteReg(0X15, 0X0050);
  2475. ms_delay(10);
  2476. LCD_WriteReg(0X12, 0X001e); // 16
  2477. ms_delay(10);
  2478. LCD_WriteReg(0X10, 0X1620);
  2479. LCD_WriteReg(0X13, 0X2A39);
  2480. ms_delay(10);
  2481. LCD_WriteReg(0X01, 0X0100);
  2482. LCD_WriteReg(0X02, 0X0300);
  2483. LCD_WriteReg(0X03, 0X1038); //改变方向的
  2484. LCD_WriteReg(0X08, 0X0202);
  2485. LCD_WriteReg(0X0A, 0X0008);
  2486. LCD_WriteReg(0X30, 0X0000);
  2487. LCD_WriteReg(0X31, 0X0402);
  2488. LCD_WriteReg(0X32, 0X0106);
  2489. LCD_WriteReg(0X33, 0X0503);
  2490. LCD_WriteReg(0X34, 0X0104);
  2491. LCD_WriteReg(0X35, 0X0301);
  2492. LCD_WriteReg(0X36, 0X0707);
  2493. LCD_WriteReg(0X37, 0X0305);
  2494. LCD_WriteReg(0X38, 0X0208);
  2495. LCD_WriteReg(0X39, 0X0F0B);
  2496. LCD_WriteReg(0X41, 0X0002);
  2497. LCD_WriteReg(0X60, 0X2700);
  2498. LCD_WriteReg(0X61, 0X0001);
  2499. LCD_WriteReg(0X90, 0X0210);
  2500. LCD_WriteReg(0X92, 0X010A);
  2501. LCD_WriteReg(0X93, 0X0004);
  2502. LCD_WriteReg(0XA0, 0X0100);
  2503. LCD_WriteReg(0X07, 0X0001);
  2504. LCD_WriteReg(0X07, 0X0021);
  2505. LCD_WriteReg(0X07, 0X0023);
  2506. LCD_WriteReg(0X07, 0X0033);
  2507. LCD_WriteReg(0X07, 0X0133);
  2508. LCD_WriteReg(0XA0, 0X0000);
  2509. }
  2510. else if (lcddev.id == 0x4535)
  2511. {
  2512. LCD_WriteReg(0X15, 0X0030);
  2513. LCD_WriteReg(0X9A, 0X0010);
  2514. LCD_WriteReg(0X11, 0X0020);
  2515. LCD_WriteReg(0X10, 0X3428);
  2516. LCD_WriteReg(0X12, 0X0002); // 16
  2517. LCD_WriteReg(0X13, 0X1038);
  2518. ms_delay(40);
  2519. LCD_WriteReg(0X12, 0X0012); // 16
  2520. ms_delay(40);
  2521. LCD_WriteReg(0X10, 0X3420);
  2522. LCD_WriteReg(0X13, 0X3038);
  2523. ms_delay(70);
  2524. LCD_WriteReg(0X30, 0X0000);
  2525. LCD_WriteReg(0X31, 0X0402);
  2526. LCD_WriteReg(0X32, 0X0307);
  2527. LCD_WriteReg(0X33, 0X0304);
  2528. LCD_WriteReg(0X34, 0X0004);
  2529. LCD_WriteReg(0X35, 0X0401);
  2530. LCD_WriteReg(0X36, 0X0707);
  2531. LCD_WriteReg(0X37, 0X0305);
  2532. LCD_WriteReg(0X38, 0X0610);
  2533. LCD_WriteReg(0X39, 0X0610);
  2534. LCD_WriteReg(0X01, 0X0100);
  2535. LCD_WriteReg(0X02, 0X0300);
  2536. LCD_WriteReg(0X03, 0X1030); //改变方向的
  2537. LCD_WriteReg(0X08, 0X0808);
  2538. LCD_WriteReg(0X0A, 0X0008);
  2539. LCD_WriteReg(0X60, 0X2700);
  2540. LCD_WriteReg(0X61, 0X0001);
  2541. LCD_WriteReg(0X90, 0X013E);
  2542. LCD_WriteReg(0X92, 0X0100);
  2543. LCD_WriteReg(0X93, 0X0100);
  2544. LCD_WriteReg(0XA0, 0X3000);
  2545. LCD_WriteReg(0XA3, 0X0010);
  2546. LCD_WriteReg(0X07, 0X0001);
  2547. LCD_WriteReg(0X07, 0X0021);
  2548. LCD_WriteReg(0X07, 0X0023);
  2549. LCD_WriteReg(0X07, 0X0033);
  2550. LCD_WriteReg(0X07, 0X0133);
  2551. }
  2552. LCD_Display_Dir(0); //默认为竖屏
  2553. LCD_PWM_HIGH; //点亮背光
  2554. LCD_Clear(WHITE);
  2555. }
  2556. //清屏函数
  2557. // color:要清屏的填充色
  2558. void LCD_Clear(u16 color)
  2559. {
  2560. u32 index = 0;
  2561. u32 totalpoint = lcddev.width;
  2562. totalpoint *= lcddev.height; //得到总点数
  2563. if ((lcddev.id == 0X6804) && (lcddev.dir == 1)) // 6804横屏的时候特殊处理
  2564. {
  2565. lcddev.dir = 0;
  2566. lcddev.setxcmd = 0X2A;
  2567. lcddev.setycmd = 0X2B;
  2568. LCD_SetCursor(0x00, 0x0000); //设置光标位置
  2569. lcddev.dir = 1;
  2570. lcddev.setxcmd = 0X2B;
  2571. lcddev.setycmd = 0X2A;
  2572. }
  2573. else
  2574. LCD_SetCursor(0x00, 0x0000); //设置光标位置
  2575. LCD_WriteRAM_Prepare(); //开始写入GRAM
  2576. for (index = 0; index < totalpoint; index++)
  2577. {
  2578. LCD->LCD_RAM = color;
  2579. }
  2580. }
  2581. //在指定区域内填充单个颜色
  2582. //(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
  2583. // color:要填充的颜色
  2584. void LCD_Fill(u16 sx, u16 sy, u16 ex, u16 ey, u16 color)
  2585. {
  2586. u16 i, j;
  2587. u16 xlen = 0;
  2588. u16 temp;
  2589. if ((lcddev.id == 0X6804) && (lcddev.dir == 1)) // 6804横屏的时候特殊处理
  2590. {
  2591. temp = sx;
  2592. sx = sy;
  2593. sy = lcddev.width - ex - 1;
  2594. ex = ey;
  2595. ey = lcddev.width - temp - 1;
  2596. lcddev.dir = 0;
  2597. lcddev.setxcmd = 0X2A;
  2598. lcddev.setycmd = 0X2B;
  2599. LCD_Fill(sx, sy, ex, ey, color);
  2600. lcddev.dir = 1;
  2601. lcddev.setxcmd = 0X2B;
  2602. lcddev.setycmd = 0X2A;
  2603. }
  2604. else
  2605. {
  2606. xlen = ex - sx + 1;
  2607. for (i = sy; i <= ey; i++)
  2608. {
  2609. LCD_SetCursor(sx, i); //设置光标位置
  2610. LCD_WriteRAM_Prepare(); //开始写入GRAM
  2611. for (j = 0; j < xlen; j++)
  2612. LCD_WR_DATA(color); //设置光标位置
  2613. }
  2614. }
  2615. }
  2616. //在指定区域内填充指定颜色块
  2617. //(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
  2618. // color:要填充的颜色
  2619. void LCD_Color_Fill(u16 sx, u16 sy, u16 ex, u16 ey, u16 *color)
  2620. {
  2621. u16 height, width;
  2622. u16 i, j;
  2623. width = ex - sx + 1; //得到填充的宽度
  2624. height = ey - sy + 1; //高度
  2625. for (i = 0; i < height; i++)
  2626. {
  2627. LCD_SetCursor(sx, sy + i); //设置光标位置
  2628. LCD_WriteRAM_Prepare(); //开始写入GRAM
  2629. for (j = 0; j < width; j++)
  2630. LCD->LCD_RAM = color[i * height + j]; //写入数据
  2631. }
  2632. }
  2633. //画线
  2634. // x1,y1:起点坐标
  2635. // x2,y2:终点坐标
  2636. void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2)
  2637. {
  2638. u16 t;
  2639. int xerr = 0, yerr = 0, delta_x, delta_y, distance;
  2640. int incx, incy, uRow, uCol;
  2641. delta_x = x2 - x1; //计算坐标增量
  2642. delta_y = y2 - y1;
  2643. uRow = x1;
  2644. uCol = y1;
  2645. if (delta_x > 0)
  2646. incx = 1; //设置单步方向
  2647. else if (delta_x == 0)
  2648. incx = 0; //垂直线
  2649. else
  2650. {
  2651. incx = -1;
  2652. delta_x = -delta_x;
  2653. }
  2654. if (delta_y > 0)
  2655. incy = 1;
  2656. else if (delta_y == 0)
  2657. incy = 0; //水平线
  2658. else
  2659. {
  2660. incy = -1;
  2661. delta_y = -delta_y;
  2662. }
  2663. if (delta_x > delta_y)
  2664. distance = delta_x; //选取基本增量坐标轴
  2665. else
  2666. distance = delta_y;
  2667. for (t = 0; t <= distance + 1; t++) //画线输出
  2668. {
  2669. LCD_DrawPoint(uRow, uCol); //画点
  2670. xerr += delta_x;
  2671. yerr += delta_y;
  2672. if (xerr > distance)
  2673. {
  2674. xerr -= distance;
  2675. uRow += incx;
  2676. }
  2677. if (yerr > distance)
  2678. {
  2679. yerr -= distance;
  2680. uCol += incy;
  2681. }
  2682. }
  2683. }
  2684. //画矩形
  2685. //(x1,y1),(x2,y2):矩形的对角坐标
  2686. void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2)
  2687. {
  2688. LCD_DrawLine(x1, y1, x2, y1);
  2689. LCD_DrawLine(x1, y1, x1, y2);
  2690. LCD_DrawLine(x1, y2, x2, y2);
  2691. LCD_DrawLine(x2, y1, x2, y2);
  2692. }
  2693. //在指定位置画一个指定大小的圆
  2694. //(x,y):中心点
  2695. // r :半径
  2696. void Draw_Circle(u16 x0, u16 y0, u8 r)
  2697. {
  2698. int a, b;
  2699. int di;
  2700. a = 0;
  2701. b = r;
  2702. di = 3 - (r << 1); //判断下个点位置的标志
  2703. while (a <= b)
  2704. {
  2705. LCD_DrawPoint(x0 + a, y0 - b); // 5
  2706. LCD_DrawPoint(x0 + b, y0 - a); // 0
  2707. LCD_DrawPoint(x0 + b, y0 + a); // 4
  2708. LCD_DrawPoint(x0 + a, y0 + b); // 6
  2709. LCD_DrawPoint(x0 - a, y0 + b); // 1
  2710. LCD_DrawPoint(x0 - b, y0 + a);
  2711. LCD_DrawPoint(x0 - a, y0 - b); // 2
  2712. LCD_DrawPoint(x0 - b, y0 - a); // 7
  2713. a++;
  2714. //使用Bresenham算法画圆
  2715. if (di < 0)
  2716. di += 4 * a + 6;
  2717. else
  2718. {
  2719. di += 10 + 4 * (a - b);
  2720. b--;
  2721. }
  2722. }
  2723. }
  2724. //在指定位置显示一个字符
  2725. // x,y:起始坐标
  2726. // num:要显示的字符:" "--->"~"
  2727. // size:字体大小 12/16
  2728. // mode:叠加方式(1)还是非叠加方式(0)
  2729. void LCD_ShowChar(u16 x, u16 y, u8 num, u8 size, u8 mode)
  2730. {
  2731. u8 temp, t1, t;
  2732. u16 y0 = y;
  2733. u16 colortemp = POINT_COLOR;
  2734. //设置窗口
  2735. num = num - ' '; //得到偏移后的值
  2736. if (!mode) //非叠加方式
  2737. {
  2738. for (t = 0; t < size; t++)
  2739. {
  2740. if (size == 12)
  2741. temp = asc2_1206[num][t]; //调用1206字体
  2742. else
  2743. temp = asc2_1608[num][t]; //调用1608字体
  2744. for (t1 = 0; t1 < 8; t1++)
  2745. {
  2746. if (temp & 0x80)
  2747. POINT_COLOR = colortemp;
  2748. else
  2749. POINT_COLOR = BACK_COLOR;
  2750. LCD_DrawPoint(x, y);
  2751. temp <<= 1;
  2752. y++;
  2753. if (x >= lcddev.width)
  2754. {
  2755. POINT_COLOR = colortemp;
  2756. return;
  2757. } //超区域了
  2758. if ((y - y0) == size)
  2759. {
  2760. y = y0;
  2761. x++;
  2762. if (x >= lcddev.width)
  2763. {
  2764. POINT_COLOR = colortemp;
  2765. return;
  2766. } //超区域了
  2767. break;
  2768. }
  2769. }
  2770. }
  2771. }
  2772. else //叠加方式
  2773. {
  2774. for (t = 0; t < size; t++)
  2775. {
  2776. if (size == 12)
  2777. temp = asc2_1206[num][t]; //调用1206字体
  2778. else
  2779. temp = asc2_1608[num][t]; //调用1608字体
  2780. for (t1 = 0; t1 < 8; t1++)
  2781. {
  2782. if (temp & 0x80)
  2783. LCD_DrawPoint(x, y);
  2784. temp <<= 1;
  2785. y++;
  2786. if (x >= lcddev.height)
  2787. {
  2788. POINT_COLOR = colortemp;
  2789. return;
  2790. } //超区域了
  2791. if ((y - y0) == size)
  2792. {
  2793. y = y0;
  2794. x++;
  2795. if (x >= lcddev.width)
  2796. {
  2797. POINT_COLOR = colortemp;
  2798. return;
  2799. } //超区域了
  2800. break;
  2801. }
  2802. }
  2803. }
  2804. }
  2805. POINT_COLOR = colortemp;
  2806. }
  2807. // m^n函数
  2808. //返回值:m^n次方.
  2809. u32 LCD_Pow(u8 m, u8 n)
  2810. {
  2811. u32 result = 1;
  2812. while (n--)
  2813. result *= m;
  2814. return result;
  2815. }
  2816. //显示数字,高位为0,则不显示
  2817. // x,y :起点坐标
  2818. // len :数字的位数
  2819. // size:字体大小
  2820. // color:颜色
  2821. // num:数值(0~4294967295);
  2822. void LCD_ShowNum(u16 x, u16 y, u32 num, u8 len, u8 size)
  2823. {
  2824. u8 t, temp;
  2825. u8 enshow = 0;
  2826. for (t = 0; t < len; t++)
  2827. {
  2828. temp = (num / LCD_Pow(10, len - t - 1)) % 10;
  2829. if (enshow == 0 && t < (len - 1))
  2830. {
  2831. if (temp == 0)
  2832. {
  2833. LCD_ShowChar(x + (size / 2) * t, y, ' ', size, 0);
  2834. continue;
  2835. }
  2836. else
  2837. enshow = 1;
  2838. }
  2839. LCD_ShowChar(x + (size / 2) * t, y, temp + '0', size, 0);
  2840. }
  2841. }
  2842. //显示数字,高位为0,还是显示
  2843. // x,y:起点坐标
  2844. // num:数值(0~999999999);
  2845. // len:长度(即要显示的位数)
  2846. // size:字体大小
  2847. // mode:
  2848. //[7]:0,不填充;1,填充0.
  2849. //[6:1]:保留
  2850. //[0]:0,非叠加显示;1,叠加显示.
  2851. void LCD_ShowxNum(u16 x, u16 y, u32 num, u8 len, u8 size, u8 mode)
  2852. {
  2853. u8 t, temp;
  2854. u8 enshow = 0;
  2855. for (t = 0; t < len; t++)
  2856. {
  2857. temp = (num / LCD_Pow(10, len - t - 1)) % 10;
  2858. if (enshow == 0 && t < (len - 1))
  2859. {
  2860. if (temp == 0)
  2861. {
  2862. if (mode & 0X80)
  2863. LCD_ShowChar(x + (size / 2) * t, y, '0', size, mode & 0X01);
  2864. else
  2865. LCD_ShowChar(x + (size / 2) * t, y, ' ', size, mode & 0X01);
  2866. continue;
  2867. }
  2868. else
  2869. enshow = 1;
  2870. }
  2871. LCD_ShowChar(x + (size / 2) * t, y, temp + '0', size, mode & 0X01);
  2872. }
  2873. }
  2874. //显示字符串
  2875. // x,y:起点坐标
  2876. // width,height:区域大小
  2877. // size:字体大小
  2878. //*p:字符串起始地址
  2879. void LCD_ShowString(u16 x, u16 y, u16 width, u16 height, u8 size, u8 *p)
  2880. {
  2881. u8 x0 = x;
  2882. width += x;
  2883. height += y;
  2884. while ((*p <= '~') && (*p >= ' ')) //判断是不是非法字符!
  2885. {
  2886. if (x >= width)
  2887. {
  2888. x = x0;
  2889. y += size;
  2890. }
  2891. if (y >= height)
  2892. break; //退出
  2893. LCD_ShowChar(x, y, *p, size, 0);
  2894. x += size / 2;
  2895. p++;
  2896. }
  2897. }