lcd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. #include "lcd/lcd.h"
  2. #include "lcd/oledfont.h"
  3. #include "lcd/bmp.h"
  4. u16 BACK_COLOR; //Background color
  5. /******************************************************************************
  6. Function description: LCD serial data write function
  7. Entry data: serial data to be written to dat
  8. Return value: None
  9. ******************************************************************************/
  10. void LCD_Writ_Bus(u8 dat)
  11. {
  12. #if SPI0_CFG == 1
  13. OLED_CS_Clr();
  14. while(RESET == spi_i2s_flag_get(SPI0, SPI_FLAG_TBE));
  15. spi_i2s_data_transmit(SPI0, dat);
  16. while(RESET == spi_i2s_flag_get(SPI0, SPI_FLAG_RBNE));
  17. spi_i2s_data_receive(SPI0);
  18. OLED_CS_Set();
  19. #elif SPI0_CFG == 2
  20. spi_dma_enable(SPI0, SPI_DMA_TRANSMIT);
  21. #else
  22. u8 i;
  23. OLED_CS_Clr();
  24. for(i=0;i<8;i++)
  25. {
  26. OLED_SCLK_Clr();
  27. if(dat&0x80)
  28. OLED_SDIN_Set();
  29. else
  30. OLED_SDIN_Clr();
  31. OLED_SCLK_Set();
  32. dat<<=1;
  33. }
  34. OLED_CS_Set();
  35. #endif
  36. }
  37. /******************************************************************************
  38. Function description: LCD write data
  39. Entry data: data written by dat
  40. Return value: None
  41. ******************************************************************************/
  42. void LCD_WR_DATA8(u8 dat)
  43. {
  44. OLED_DC_Set();//Write data
  45. LCD_Writ_Bus(dat);
  46. }
  47. /******************************************************************************
  48. Function description: LCD write data
  49. Entry data: data written by dat
  50. Return value: None
  51. ******************************************************************************/
  52. void LCD_WR_DATA(u16 dat)
  53. {
  54. OLED_DC_Set();//Write data
  55. LCD_Writ_Bus(dat>>8);
  56. LCD_Writ_Bus(dat);
  57. }
  58. /******************************************************************************
  59. Function description: LCD write command
  60. Entry data: command written by dat
  61. Return value: None
  62. ******************************************************************************/
  63. void LCD_WR_REG(u8 dat)
  64. {
  65. OLED_DC_Clr();//Write command
  66. LCD_Writ_Bus(dat);
  67. }
  68. /******************************************************************************
  69. Function description: Set start and end addresses
  70. Entry data: x1, x2 set the start and end addresses of the column
  71. y1, y2 set the start and end addresses of the line
  72. Return value: None
  73. ******************************************************************************/
  74. void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2)
  75. {
  76. if(USE_HORIZONTAL==0)
  77. {
  78. LCD_WR_REG(0x2a);//Column address settings
  79. LCD_WR_DATA(x1+26);
  80. LCD_WR_DATA(x2+26);
  81. LCD_WR_REG(0x2b);//Row address setting
  82. LCD_WR_DATA(y1+1);
  83. LCD_WR_DATA(y2+1);
  84. LCD_WR_REG(0x2c);//Memory write
  85. }
  86. else if(USE_HORIZONTAL==1)
  87. {
  88. LCD_WR_REG(0x2a);//Column address settings
  89. LCD_WR_DATA(x1+26);
  90. LCD_WR_DATA(x2+26);
  91. LCD_WR_REG(0x2b);//Row address setting
  92. LCD_WR_DATA(y1+1);
  93. LCD_WR_DATA(y2+1);
  94. LCD_WR_REG(0x2c);//Memory write
  95. }
  96. else if(USE_HORIZONTAL==2)
  97. {
  98. LCD_WR_REG(0x2a);//Column address settings
  99. LCD_WR_DATA(x1+1);
  100. LCD_WR_DATA(x2+1);
  101. LCD_WR_REG(0x2b);//Row address setting
  102. LCD_WR_DATA(y1+26);
  103. LCD_WR_DATA(y2+26);
  104. LCD_WR_REG(0x2c);//Memory write
  105. }
  106. else
  107. {
  108. LCD_WR_REG(0x2a);//Column address settings
  109. LCD_WR_DATA(x1+1);
  110. LCD_WR_DATA(x2+1);
  111. LCD_WR_REG(0x2b);//Row address setting
  112. LCD_WR_DATA(y1+26);
  113. LCD_WR_DATA(y2+26);
  114. LCD_WR_REG(0x2c);//Memory write
  115. }
  116. }
  117. #if SPI0_CFG == 2
  118. /*!
  119. \brief configure the DMA peripheral
  120. \param[in] none
  121. \param[out] none
  122. \retval none
  123. */
  124. void dma_config(void)
  125. {
  126. dma_parameter_struct dma_init_struct;
  127. /* SPI0 transmit dma config:DMA0,DMA_CH2 */
  128. dma_deinit(DMA0, DMA_CH2);
  129. dma_struct_para_init(&dma_init_struct);
  130. dma_init_struct.periph_addr = (uint32_t)&SPI_DATA(SPI0);
  131. dma_init_struct.memory_addr = (uint32_t)image;
  132. dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL;
  133. dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT;
  134. dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT;
  135. dma_init_struct.priority = DMA_PRIORITY_LOW;
  136. dma_init_struct.number = FRAME_SIZE;
  137. dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
  138. dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
  139. dma_init(DMA0, DMA_CH2, &dma_init_struct);
  140. /* configure DMA mode */
  141. dma_circulation_disable(DMA0, DMA_CH2);
  142. dma_memory_to_memory_disable(DMA0, DMA_CH2);
  143. }
  144. #endif
  145. #if SPI0_CFG == 1
  146. /*!
  147. \brief configure the SPI peripheral
  148. \param[in] none
  149. \param[out] none
  150. \retval none
  151. */
  152. void spi_config(void)
  153. {
  154. spi_parameter_struct spi_init_struct;
  155. /* deinitilize SPI and the parameters */
  156. OLED_CS_Set();
  157. spi_struct_para_init(&spi_init_struct);
  158. /* SPI0 parameter config */
  159. spi_init_struct.trans_mode = SPI_TRANSMODE_FULLDUPLEX;
  160. spi_init_struct.device_mode = SPI_MASTER;
  161. spi_init_struct.frame_size = SPI_FRAMESIZE_8BIT;
  162. spi_init_struct.clock_polarity_phase = SPI_CK_PL_HIGH_PH_2EDGE;
  163. spi_init_struct.nss = SPI_NSS_SOFT;
  164. spi_init_struct.prescale = SPI_PSC_8;
  165. spi_init_struct.endian = SPI_ENDIAN_MSB;
  166. spi_init(SPI0, &spi_init_struct);
  167. spi_crc_polynomial_set(SPI0,7);
  168. spi_enable(SPI0);
  169. }
  170. #endif
  171. /******************************************************************************
  172. Function description: LCD initialization function
  173. Entry data: None
  174. Return value: None
  175. ******************************************************************************/
  176. void Lcd_Init(void)
  177. {
  178. rcu_periph_clock_enable(RCU_GPIOA);
  179. rcu_periph_clock_enable(RCU_GPIOB);
  180. #if SPI0_CFG == 1
  181. rcu_periph_clock_enable(RCU_AF);
  182. rcu_periph_clock_enable(RCU_SPI0);
  183. /* SPI0 GPIO config: NSS/PA4, SCK/PA5, MOSI/PA7 */
  184. gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_5 |GPIO_PIN_6| GPIO_PIN_7);
  185. gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
  186. spi_config();
  187. #elif SPI0_CFG == 2
  188. rcu_periph_clock_enable(RCU_DMA0);
  189. rcu_periph_clock_enable(RCU_SPI0);
  190. /* SPI0 GPIO config: NSS/PA4, SCK/PA5, MOSI/PA7 */
  191. gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7);
  192. /* SPI0 GPIO config: MISO/PA6 */
  193. gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
  194. //dma_config();
  195. dma_channel_enable(DMA0,DMA_CH2);
  196. #elif SPI0_CFG == 3
  197. gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_5 | GPIO_PIN_7);
  198. gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
  199. gpio_bit_reset(GPIOA, GPIO_PIN_5 | GPIO_PIN_7);
  200. gpio_bit_reset(GPIOB, GPIO_PIN_2);
  201. #endif
  202. gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0 | GPIO_PIN_1);
  203. gpio_bit_reset(GPIOB, GPIO_PIN_0 | GPIO_PIN_1);
  204. OLED_RST_Clr();
  205. delay_1ms(200);
  206. OLED_RST_Set();
  207. delay_1ms(20);
  208. OLED_BLK_Set();
  209. LCD_WR_REG(0x11); // turn off sleep mode
  210. delay_1ms(100);
  211. LCD_WR_REG(0x21); // display inversion mode
  212. LCD_WR_REG(0xB1); // Set the frame frequency of the full colors normal mode
  213. // Frame rate=fosc/((RTNA x 2 + 40) x (LINE + FPA + BPA +2))
  214. // fosc = 850kHz
  215. LCD_WR_DATA8(0x05); // RTNA
  216. LCD_WR_DATA8(0x3A); // FPA
  217. LCD_WR_DATA8(0x3A); // BPA
  218. LCD_WR_REG(0xB2); // Set the frame frequency of the Idle mode
  219. // Frame rate=fosc/((RTNB x 2 + 40) x (LINE + FPB + BPB +2))
  220. // fosc = 850kHz
  221. LCD_WR_DATA8(0x05); // RTNB
  222. LCD_WR_DATA8(0x3A); // FPB
  223. LCD_WR_DATA8(0x3A); // BPB
  224. LCD_WR_REG(0xB3); // Set the frame frequency of the Partial mode/ full colors
  225. LCD_WR_DATA8(0x05);
  226. LCD_WR_DATA8(0x3A);
  227. LCD_WR_DATA8(0x3A);
  228. LCD_WR_DATA8(0x05);
  229. LCD_WR_DATA8(0x3A);
  230. LCD_WR_DATA8(0x3A);
  231. LCD_WR_REG(0xB4);
  232. LCD_WR_DATA8(0x03);
  233. LCD_WR_REG(0xC0);
  234. LCD_WR_DATA8(0x62);
  235. LCD_WR_DATA8(0x02);
  236. LCD_WR_DATA8(0x04);
  237. LCD_WR_REG(0xC1);
  238. LCD_WR_DATA8(0xC0);
  239. LCD_WR_REG(0xC2);
  240. LCD_WR_DATA8(0x0D);
  241. LCD_WR_DATA8(0x00);
  242. LCD_WR_REG(0xC3);
  243. LCD_WR_DATA8(0x8D);
  244. LCD_WR_DATA8(0x6A);
  245. LCD_WR_REG(0xC4);
  246. LCD_WR_DATA8(0x8D);
  247. LCD_WR_DATA8(0xEE);
  248. LCD_WR_REG(0xC5); /*VCOM*/
  249. LCD_WR_DATA8(0x0E);
  250. LCD_WR_REG(0xE0);
  251. LCD_WR_DATA8(0x10);
  252. LCD_WR_DATA8(0x0E);
  253. LCD_WR_DATA8(0x02);
  254. LCD_WR_DATA8(0x03);
  255. LCD_WR_DATA8(0x0E);
  256. LCD_WR_DATA8(0x07);
  257. LCD_WR_DATA8(0x02);
  258. LCD_WR_DATA8(0x07);
  259. LCD_WR_DATA8(0x0A);
  260. LCD_WR_DATA8(0x12);
  261. LCD_WR_DATA8(0x27);
  262. LCD_WR_DATA8(0x37);
  263. LCD_WR_DATA8(0x00);
  264. LCD_WR_DATA8(0x0D);
  265. LCD_WR_DATA8(0x0E);
  266. LCD_WR_DATA8(0x10);
  267. LCD_WR_REG(0xE1);
  268. LCD_WR_DATA8(0x10);
  269. LCD_WR_DATA8(0x0E);
  270. LCD_WR_DATA8(0x03);
  271. LCD_WR_DATA8(0x03);
  272. LCD_WR_DATA8(0x0F);
  273. LCD_WR_DATA8(0x06);
  274. LCD_WR_DATA8(0x02);
  275. LCD_WR_DATA8(0x08);
  276. LCD_WR_DATA8(0x0A);
  277. LCD_WR_DATA8(0x13);
  278. LCD_WR_DATA8(0x26);
  279. LCD_WR_DATA8(0x36);
  280. LCD_WR_DATA8(0x00);
  281. LCD_WR_DATA8(0x0D);
  282. LCD_WR_DATA8(0x0E);
  283. LCD_WR_DATA8(0x10);
  284. /* DLX powersave settings */
  285. LCD_WR_REG(0XFC); // Enable Gate power save mode
  286. LCD_WR_DATA8(0XC0); // 0XFC[7:6]=GCV_Enable[1:0]=10'b→ Gate Pump Clock Frequency disable
  287. // 0XFC[3:2]=CLK_Variable[1:0]=11'b→ Save Power Ability is Large
  288. LCD_WR_REG(0x3A); // define the format of RGB picture data
  289. LCD_WR_DATA8(0x05); // 16-bit/pixel
  290. //
  291. LCD_WR_REG(0x36);
  292. if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x08);
  293. else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC8);
  294. else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x78);
  295. else LCD_WR_DATA8(0xA8);
  296. LCD_WR_REG(0x29); // Display On
  297. }
  298. /******************************************************************************
  299. Function description: LCD clear screen function
  300. Entry data: None
  301. Return value: None
  302. ******************************************************************************/
  303. void LCD_Clear(u16 Color)
  304. {
  305. u16 i,j;
  306. LCD_Address_Set(0,0,LCD_W-1,LCD_H-1);
  307. for(i=0;i<LCD_W;i++)
  308. {
  309. for (j=0;j<LCD_H;j++)
  310. {
  311. LCD_WR_DATA(Color);
  312. }
  313. }
  314. }
  315. #if 0
  316. /******************************************************************************
  317. Function description: LCD display Chinese characters
  318. Entry data: x, y starting coordinates
  319. index Chinese character number
  320. size font size
  321. Return value: None
  322. ******************************************************************************/
  323. void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size,u16 color)
  324. {
  325. u8 i,j;
  326. u8 *temp,size1;
  327. if(size==16){temp=Hzk16;}//选择字号
  328. if(size==32){temp=Hzk32;}
  329. LCD_Address_Set(x,y,x+size-1,y+size-1); //设置一个汉字的区域
  330. size1=size*size/8;//一个汉字所占的字节
  331. temp+=index*size1;//写入的起始位置
  332. for(j=0;j<size1;j++)
  333. {
  334. for(i=0;i<8;i++)
  335. {
  336. if((*temp&(1<<i))!=0)//从数据的低位开始读
  337. {
  338. LCD_WR_DATA(color);//点亮
  339. }
  340. else
  341. {
  342. LCD_WR_DATA(BACK_COLOR);//不点亮
  343. }
  344. }
  345. temp++;
  346. }
  347. }
  348. #endif
  349. /******************************************************************************
  350. Function description: LCD draws point
  351. Entry data: x, y starting coordinates
  352. Return value: None
  353. ******************************************************************************/
  354. void LCD_DrawPoint(u16 x,u16 y,u16 color)
  355. {
  356. LCD_Address_Set(x,y,x,y);//设置光标位置
  357. LCD_WR_DATA(color);
  358. }
  359. /******************************************************************************
  360. Function description: LCD draws a large dot
  361. Entry data: x, y starting coordinates
  362. Return value: None
  363. ******************************************************************************/
  364. void LCD_DrawPoint_big(u16 x,u16 y,u16 color)
  365. {
  366. LCD_Fill(x-1,y-1,x+1,y+1,color);
  367. }
  368. /******************************************************************************
  369. Function description: fill color in the specified area
  370. Entry data: xsta, ysta starting coordinates
  371. xend, yend termination coordinates
  372. Return value: None
  373. ******************************************************************************/
  374. void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color)
  375. {
  376. u16 i,j;
  377. LCD_Address_Set(xsta,ysta,xend,yend); //设置光标位置
  378. for(i=ysta;i<=yend;i++)
  379. {
  380. for(j=xsta;j<=xend;j++)LCD_WR_DATA(color);//设置光标位置
  381. }
  382. }
  383. /******************************************************************************
  384. Function description: draw a line
  385. Entry data: x1, y1 starting coordinates
  386. x2, y2 terminating coordinates
  387. Return value: None
  388. ******************************************************************************/
  389. void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color)
  390. {
  391. u16 t;
  392. int xerr=0,yerr=0,delta_x,delta_y,distance;
  393. int incx,incy,uRow,uCol;
  394. delta_x=x2-x1; //计算坐标增量
  395. delta_y=y2-y1;
  396. uRow=x1;//画线起点坐标
  397. uCol=y1;
  398. if(delta_x>0)incx=1; //设置单步方向
  399. else if (delta_x==0)incx=0;//垂直线
  400. else {incx=-1;delta_x=-delta_x;}
  401. if(delta_y>0)incy=1;
  402. else if (delta_y==0)incy=0;//水平线
  403. else {incy=-1;delta_y=-delta_x;}
  404. if(delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴
  405. else distance=delta_y;
  406. for(t=0;t<distance+1;t++)
  407. {
  408. LCD_DrawPoint(uRow,uCol,color);//画点
  409. xerr+=delta_x;
  410. yerr+=delta_y;
  411. if(xerr>distance)
  412. {
  413. xerr-=distance;
  414. uRow+=incx;
  415. }
  416. if(yerr>distance)
  417. {
  418. yerr-=distance;
  419. uCol+=incy;
  420. }
  421. }
  422. }
  423. /******************************************************************************
  424. Function description: draw a rectangle
  425. Entry data: x1, y1 starting coordinates
  426. x2, y2 terminating coordinates
  427. Return value: None
  428. ******************************************************************************/
  429. void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color)
  430. {
  431. LCD_DrawLine(x1,y1,x2,y1,color);
  432. LCD_DrawLine(x1,y1,x1,y2,color);
  433. LCD_DrawLine(x1,y2,x2,y2,color);
  434. LCD_DrawLine(x2,y1,x2,y2,color);
  435. }
  436. /******************************************************************************
  437. Function description: draw circle
  438. Entry data: x0, y0 center coordinates
  439. r radius
  440. Return value: None
  441. ******************************************************************************/
  442. void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color)
  443. {
  444. int a,b;
  445. // int di;
  446. a=0;b=r;
  447. while(a<=b)
  448. {
  449. LCD_DrawPoint(x0-b,y0-a,color); //3
  450. LCD_DrawPoint(x0+b,y0-a,color); //0
  451. LCD_DrawPoint(x0-a,y0+b,color); //1
  452. LCD_DrawPoint(x0-a,y0-b,color); //2
  453. LCD_DrawPoint(x0+b,y0+a,color); //4
  454. LCD_DrawPoint(x0+a,y0-b,color); //5
  455. LCD_DrawPoint(x0+a,y0+b,color); //6
  456. LCD_DrawPoint(x0-b,y0+a,color); //7
  457. a++;
  458. if((a*a+b*b)>(r*r))//Determine whether the points to be drawn are too far away
  459. {
  460. b--;
  461. }
  462. }
  463. }
  464. /******************************************************************************
  465. Function description: display characters
  466. Entry data: x, y starting point coordinates
  467. num characters to display
  468. mode 1 superimposed mode 0 non-superimposed mode
  469. Return value: None
  470. ******************************************************************************/
  471. void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode,u16 color)
  472. {
  473. u8 temp;
  474. u8 pos,t;
  475. u16 x0=x;
  476. if(x>LCD_W-16||y>LCD_H-16)return; //Settings window
  477. num=num-' ';//Get offset value
  478. LCD_Address_Set(x,y,x+8-1,y+16-1); //Set cursor position
  479. if(!mode) //Non-overlapping
  480. {
  481. for(pos=0;pos<16;pos++)
  482. {
  483. temp=asc2_1608[(u16)num*16+pos]; //Call 1608 font
  484. for(t=0;t<8;t++)
  485. {
  486. if(temp&0x01)LCD_WR_DATA(color);
  487. else LCD_WR_DATA(BACK_COLOR);
  488. temp>>=1;
  489. x++;
  490. }
  491. x=x0;
  492. y++;
  493. }
  494. }else//overlapping mode
  495. {
  496. for(pos=0;pos<16;pos++)
  497. {
  498. temp=asc2_1608[(u16)num*16+pos]; //Call 1608 font
  499. for(t=0;t<8;t++)
  500. {
  501. if(temp&0x01)LCD_DrawPoint(x+t,y+pos,color);//Draw a dot
  502. temp>>=1;
  503. }
  504. }
  505. }
  506. }
  507. /******************************************************************************
  508. Function description: display string
  509. Entry data: x, y starting point coordinates
  510. *p string start address
  511. Return value: None
  512. ******************************************************************************/
  513. void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color)
  514. {
  515. while(*p!='\0')
  516. {
  517. if(x>LCD_W-16){x=0;y+=16;}
  518. if(y>LCD_H-16){y=x=0;LCD_Clear(RED);}
  519. LCD_ShowChar(x,y,*p,0,color);
  520. x+=8;
  521. p++;
  522. }
  523. }
  524. /******************************************************************************
  525. Function description: display numbers
  526. Entry data: base m, n exponent
  527. Return value: None
  528. ******************************************************************************/
  529. u32 mypow(u8 m,u8 n)
  530. {
  531. u32 result=1;
  532. while(n--)result*=m;
  533. return result;
  534. }
  535. /******************************************************************************
  536. Function description: display numbers
  537. Entry data: x, y starting point coordinates
  538. num number to display
  539. len number of digits to display
  540. Return value: None
  541. ******************************************************************************/
  542. void LCD_ShowNum(u16 x,u16 y,u16 num,u8 len,u16 color)
  543. {
  544. u8 t,temp;
  545. u8 enshow=0;
  546. for(t=0;t<len;t++)
  547. {
  548. temp=(num/mypow(10,len-t-1))%10;
  549. if(enshow==0&&t<(len-1))
  550. {
  551. if(temp==0)
  552. {
  553. LCD_ShowChar(x+8*t,y,' ',0,color);
  554. continue;
  555. }else enshow=1;
  556. }
  557. LCD_ShowChar(x+8*t,y,temp+48,0,color);
  558. }
  559. }
  560. /******************************************************************************
  561. Function description: display decimal
  562. Entry data: x, y starting point coordinates
  563. num decimal to display
  564. len number of digits to display
  565. Return value: None
  566. ******************************************************************************/
  567. void LCD_ShowNum1(u16 x,u16 y,float num,u8 len,u16 color)
  568. {
  569. u8 t,temp;
  570. // u8 enshow=0;
  571. u16 num1;
  572. num1=num*100;
  573. for(t=0;t<len;t++)
  574. {
  575. temp=(num1/mypow(10,len-t-1))%10;
  576. if(t==(len-2))
  577. {
  578. LCD_ShowChar(x+8*(len-2),y,'.',0,color);
  579. t++;
  580. len+=1;
  581. }
  582. LCD_ShowChar(x+8*t,y,temp+48,0,color);
  583. }
  584. }
  585. /******************************************************************************
  586. Function description: display 160x40 16bit (RGB565) picture
  587. Entry data: x, y starting point coordinates
  588. Return value: None
  589. ******************************************************************************/
  590. void LCD_ShowPicture(const char *img, u16 x1,u16 y1,u16 x2,u16 y2)
  591. {
  592. int i;
  593. u32 size = 2 * (1 + x2 - x1) * (1 + y2 - y1);
  594. LCD_Address_Set(x1,y1,x2,y2);
  595. for(i=0;i<size;i++)
  596. {
  597. // LCD_WR_DATA8(image[i*2+1]);
  598. LCD_WR_DATA8(img[i]);
  599. }
  600. }