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. LCD_WR_REG(0x3A); // define the format of RGB picture data
  285. LCD_WR_DATA8(0x05); // 16-bit/pixel
  286. LCD_WR_REG(0x36);
  287. if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x08);
  288. else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC8);
  289. else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x78);
  290. else LCD_WR_DATA8(0xA8);
  291. LCD_WR_REG(0x29); // Display On
  292. }
  293. /******************************************************************************
  294. Function description: LCD clear screen function
  295. Entry data: None
  296. Return value: None
  297. ******************************************************************************/
  298. void LCD_Clear(u16 Color)
  299. {
  300. u16 i,j;
  301. LCD_Address_Set(0,0,LCD_W-1,LCD_H-1);
  302. for(i=0;i<LCD_W;i++)
  303. {
  304. for (j=0;j<LCD_H;j++)
  305. {
  306. LCD_WR_DATA(Color);
  307. }
  308. }
  309. }
  310. /******************************************************************************
  311. Function description: LCD display Chinese characters
  312. Entry data: x, y starting coordinates
  313. index Chinese character number
  314. size font size
  315. Return value: None
  316. ******************************************************************************/
  317. void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size,u16 color)
  318. {
  319. u8 i,j;
  320. u8 *temp,size1;
  321. if(size==16){temp=Hzk16;}//选择字号
  322. if(size==32){temp=Hzk32;}
  323. LCD_Address_Set(x,y,x+size-1,y+size-1); //设置一个汉字的区域
  324. size1=size*size/8;//一个汉字所占的字节
  325. temp+=index*size1;//写入的起始位置
  326. for(j=0;j<size1;j++)
  327. {
  328. for(i=0;i<8;i++)
  329. {
  330. if((*temp&(1<<i))!=0)//从数据的低位开始读
  331. {
  332. LCD_WR_DATA(color);//点亮
  333. }
  334. else
  335. {
  336. LCD_WR_DATA(BACK_COLOR);//不点亮
  337. }
  338. }
  339. temp++;
  340. }
  341. }
  342. /******************************************************************************
  343. Function description: LCD draws point
  344. Entry data: x, y starting coordinates
  345. Return value: None
  346. ******************************************************************************/
  347. void LCD_DrawPoint(u16 x,u16 y,u16 color)
  348. {
  349. LCD_Address_Set(x,y,x,y);//设置光标位置
  350. LCD_WR_DATA(color);
  351. }
  352. /******************************************************************************
  353. Function description: LCD draws a large dot
  354. Entry data: x, y starting coordinates
  355. Return value: None
  356. ******************************************************************************/
  357. void LCD_DrawPoint_big(u16 x,u16 y,u16 color)
  358. {
  359. LCD_Fill(x-1,y-1,x+1,y+1,color);
  360. }
  361. /******************************************************************************
  362. Function description: fill color in the specified area
  363. Entry data: xsta, ysta starting coordinates
  364. xend, yend termination coordinates
  365. Return value: None
  366. ******************************************************************************/
  367. void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color)
  368. {
  369. u16 i,j;
  370. LCD_Address_Set(xsta,ysta,xend,yend); //设置光标位置
  371. for(i=ysta;i<=yend;i++)
  372. {
  373. for(j=xsta;j<=xend;j++)LCD_WR_DATA(color);//设置光标位置
  374. }
  375. }
  376. /******************************************************************************
  377. Function description: draw a line
  378. Entry data: x1, y1 starting coordinates
  379. x2, y2 terminating coordinates
  380. Return value: None
  381. ******************************************************************************/
  382. void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color)
  383. {
  384. u16 t;
  385. int xerr=0,yerr=0,delta_x,delta_y,distance;
  386. int incx,incy,uRow,uCol;
  387. delta_x=x2-x1; //计算坐标增量
  388. delta_y=y2-y1;
  389. uRow=x1;//画线起点坐标
  390. uCol=y1;
  391. if(delta_x>0)incx=1; //设置单步方向
  392. else if (delta_x==0)incx=0;//垂直线
  393. else {incx=-1;delta_x=-delta_x;}
  394. if(delta_y>0)incy=1;
  395. else if (delta_y==0)incy=0;//水平线
  396. else {incy=-1;delta_y=-delta_x;}
  397. if(delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴
  398. else distance=delta_y;
  399. for(t=0;t<distance+1;t++)
  400. {
  401. LCD_DrawPoint(uRow,uCol,color);//画点
  402. xerr+=delta_x;
  403. yerr+=delta_y;
  404. if(xerr>distance)
  405. {
  406. xerr-=distance;
  407. uRow+=incx;
  408. }
  409. if(yerr>distance)
  410. {
  411. yerr-=distance;
  412. uCol+=incy;
  413. }
  414. }
  415. }
  416. /******************************************************************************
  417. Function description: draw a rectangle
  418. Entry data: x1, y1 starting coordinates
  419. x2, y2 terminating coordinates
  420. Return value: None
  421. ******************************************************************************/
  422. void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color)
  423. {
  424. LCD_DrawLine(x1,y1,x2,y1,color);
  425. LCD_DrawLine(x1,y1,x1,y2,color);
  426. LCD_DrawLine(x1,y2,x2,y2,color);
  427. LCD_DrawLine(x2,y1,x2,y2,color);
  428. }
  429. /******************************************************************************
  430. Function description: draw circle
  431. Entry data: x0, y0 center coordinates
  432. r radius
  433. Return value: None
  434. ******************************************************************************/
  435. void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color)
  436. {
  437. int a,b;
  438. // int di;
  439. a=0;b=r;
  440. while(a<=b)
  441. {
  442. LCD_DrawPoint(x0-b,y0-a,color); //3
  443. LCD_DrawPoint(x0+b,y0-a,color); //0
  444. LCD_DrawPoint(x0-a,y0+b,color); //1
  445. LCD_DrawPoint(x0-a,y0-b,color); //2
  446. LCD_DrawPoint(x0+b,y0+a,color); //4
  447. LCD_DrawPoint(x0+a,y0-b,color); //5
  448. LCD_DrawPoint(x0+a,y0+b,color); //6
  449. LCD_DrawPoint(x0-b,y0+a,color); //7
  450. a++;
  451. if((a*a+b*b)>(r*r))//Determine whether the points to be drawn are too far away
  452. {
  453. b--;
  454. }
  455. }
  456. }
  457. /******************************************************************************
  458. Function description: display characters
  459. Entry data: x, y starting point coordinates
  460. num characters to display
  461. mode 1 superimposed mode 0 non-superimposed mode
  462. Return value: None
  463. ******************************************************************************/
  464. void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode,u16 color)
  465. {
  466. u8 temp;
  467. u8 pos,t;
  468. u16 x0=x;
  469. if(x>LCD_W-16||y>LCD_H-16)return; //Settings window
  470. num=num-' ';//Get offset value
  471. LCD_Address_Set(x,y,x+8-1,y+16-1); //Set cursor position
  472. if(!mode) //Non-overlapping
  473. {
  474. for(pos=0;pos<16;pos++)
  475. {
  476. temp=asc2_1608[(u16)num*16+pos]; //Call 1608 font
  477. for(t=0;t<8;t++)
  478. {
  479. if(temp&0x01)LCD_WR_DATA(color);
  480. else LCD_WR_DATA(BACK_COLOR);
  481. temp>>=1;
  482. x++;
  483. }
  484. x=x0;
  485. y++;
  486. }
  487. }else//overlapping mode
  488. {
  489. for(pos=0;pos<16;pos++)
  490. {
  491. temp=asc2_1608[(u16)num*16+pos]; //Call 1608 font
  492. for(t=0;t<8;t++)
  493. {
  494. if(temp&0x01)LCD_DrawPoint(x+t,y+pos,color);//Draw a dot
  495. temp>>=1;
  496. }
  497. }
  498. }
  499. }
  500. /******************************************************************************
  501. Function description: display string
  502. Entry data: x, y starting point coordinates
  503. *p string start address
  504. Return value: None
  505. ******************************************************************************/
  506. void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color)
  507. {
  508. while(*p!='\0')
  509. {
  510. if(x>LCD_W-16){x=0;y+=16;}
  511. if(y>LCD_H-16){y=x=0;LCD_Clear(RED);}
  512. LCD_ShowChar(x,y,*p,0,color);
  513. x+=8;
  514. p++;
  515. }
  516. }
  517. /******************************************************************************
  518. Function description: display numbers
  519. Entry data: base m, n exponent
  520. Return value: None
  521. ******************************************************************************/
  522. u32 mypow(u8 m,u8 n)
  523. {
  524. u32 result=1;
  525. while(n--)result*=m;
  526. return result;
  527. }
  528. /******************************************************************************
  529. Function description: display numbers
  530. Entry data: x, y starting point coordinates
  531. num number to display
  532. len number of digits to display
  533. Return value: None
  534. ******************************************************************************/
  535. void LCD_ShowNum(u16 x,u16 y,u16 num,u8 len,u16 color)
  536. {
  537. u8 t,temp;
  538. u8 enshow=0;
  539. for(t=0;t<len;t++)
  540. {
  541. temp=(num/mypow(10,len-t-1))%10;
  542. if(enshow==0&&t<(len-1))
  543. {
  544. if(temp==0)
  545. {
  546. LCD_ShowChar(x+8*t,y,' ',0,color);
  547. continue;
  548. }else enshow=1;
  549. }
  550. LCD_ShowChar(x+8*t,y,temp+48,0,color);
  551. }
  552. }
  553. /******************************************************************************
  554. Function description: display decimal
  555. Entry data: x, y starting point coordinates
  556. num decimal to display
  557. len number of digits to display
  558. Return value: None
  559. ******************************************************************************/
  560. void LCD_ShowNum1(u16 x,u16 y,float num,u8 len,u16 color)
  561. {
  562. u8 t,temp;
  563. // u8 enshow=0;
  564. u16 num1;
  565. num1=num*100;
  566. for(t=0;t<len;t++)
  567. {
  568. temp=(num1/mypow(10,len-t-1))%10;
  569. if(t==(len-2))
  570. {
  571. LCD_ShowChar(x+8*(len-2),y,'.',0,color);
  572. t++;
  573. len+=1;
  574. }
  575. LCD_ShowChar(x+8*t,y,temp+48,0,color);
  576. }
  577. }
  578. /******************************************************************************
  579. Function description: display 160x40 16bit (RGB565) picture
  580. Entry data: x, y starting point coordinates
  581. Return value: None
  582. ******************************************************************************/
  583. void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2)
  584. {
  585. int i;
  586. LCD_Address_Set(x1,y1,x2,y2);
  587. for(i=0;i<12800;i++)
  588. {
  589. // LCD_WR_DATA8(image[i*2+1]);
  590. //LCD_WR_DATA8(image[i]);
  591. }
  592. }
  593. void LCD_ShowLogo(void)
  594. {
  595. int i;
  596. LCD_Address_Set(0,0,159,75);
  597. for(i=0;i<25600;i++)
  598. {
  599. LCD_WR_DATA8(logo_bmp[i]);
  600. }
  601. }