HT16C22.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. #include "HT16C22.h"
  2. #include "math.h"
  3. // #define cs _pa1 //ht1621
  4. // #define wr _pa2
  5. // #define dat _pa3
  6. #define BIAS 0x29 // 0x29//0x50// 1/3 bias 4 com-原28
  7. #define SYSEN 0x01 // 0X02//Turn on system oscillator振荡
  8. #define LCDON 0x03 // 0x06//Turn on LCD bias generator偏压发生器
  9. #define LCDOFF 0x02 // 0x04//Turn off LCD bias generator
  10. #define RC256 0x18
  11. // 增加变量定义,add by qys
  12. void IIC_delay(void)
  13. {
  14. u8 i = 400; // 这里可以优化速度 ,经测试最低到5还能写入
  15. while (i)
  16. {
  17. i--;
  18. }
  19. }
  20. void Delay_Ms()
  21. {
  22. u16 i, j;
  23. for (i = 0; i < 500; i++)
  24. for (j = 0; j < 700; j++)
  25. ;
  26. }
  27. void Delay_SS()
  28. {
  29. u16 i, j;
  30. for (i = 0; i < 2000; i++)
  31. for (j = 0; j < 1000; j++)
  32. ;
  33. }
  34. u8 OD_Value, OE_Value, OF_Value, IO_Value, II_Value, IE_Value, IS_Value;
  35. static uint16_t ram[4] = {0X00000000,0X00000000,0X00000000,0X00000000};
  36. uint16_t ram1 = 0X00000000;
  37. uint16_t ram2 = 0X00000000;
  38. uint16_t ram3 = 0X00000000;
  39. uint16_t ram4 = 0X00000000;
  40. /*uint8_t LcdDisplayData[4][22] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  41. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  42. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  43. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
  44. uint8_t LcdDisplayData[4][22] = {{0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
  45. {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
  46. {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
  47. {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}
  48. };*/
  49. void DELAY(unsigned short i)
  50. {
  51. unsigned short j;
  52. for (j = 0; j < i; j++)
  53. Delay_Ms(10); // Delay i*10mS
  54. }
  55. void delay(uint8_t nun)
  56. {
  57. uint8_t i;
  58. for (i = 0; i < nun; i++)
  59. {
  60. __nop();
  61. }
  62. }
  63. void sendbit_high(uint8_t data, uint8_t cnt) // 传地址,高六位
  64. {
  65. uint8_t i;
  66. for (i = 0; i < cnt; i++)
  67. {
  68. CLR_LCD_WR();
  69. if ((data & 0x80) == 0)
  70. CLR_LCD_DATA();
  71. else
  72. SET_LCD_DATA();
  73. IIC_delay();
  74. //__nop();
  75. // delay(10); // 防止tCLK太短
  76. SET_LCD_WR();
  77. data <<= 1;
  78. }
  79. }
  80. void sendbit_low(uint8_t data, uint8_t cnt) // 传送数据,低四位
  81. {
  82. uint8_t i;
  83. for (i = 0; i < cnt; i++)
  84. {
  85. CLR_LCD_WR();
  86. if ((data & 0x01) == 0)
  87. CLR_LCD_DATA();
  88. else
  89. SET_LCD_DATA();
  90. IIC_delay();
  91. //__nop();
  92. // delay(10); // 防止tCLK太短
  93. SET_LCD_WR();
  94. data >>= 1;
  95. }
  96. }
  97. void sendcmd(uint8_t command) // 写命令
  98. {
  99. CLR_LCD_CS();
  100. sendbit_high(0x80, 3);
  101. sendbit_high(command, 8);
  102. sendbit_high(0x0, 1);
  103. SET_LCD_CS();
  104. }
  105. void write_1621(uint8_t addr, uint8_t data) // 写地址和数据
  106. {
  107. CLR_LCD_CS();
  108. sendbit_high(0xa0, 3);
  109. sendbit_high(addr << 2, 6);
  110. sendbit_low(data, 4);
  111. SET_LCD_CS();
  112. }
  113. void LCD_init(void)
  114. {
  115. char i;
  116. sendcmd(RC256);
  117. sendcmd(BIAS);
  118. sendcmd(SYSEN);
  119. sendcmd(LCDON);
  120. for (i = 0; i < 12; i++) // all the lights bright
  121. {
  122. write_1621(i, 0x00);
  123. // delay(5);
  124. }
  125. }
  126. /************************LCDkai****************************/
  127. //////////////////////////////////////////////////////////////////////////
  128. // 函数名 : IIC_Init
  129. // 功能 : 初始化i2c
  130. // 参数 : void
  131. // 作者 : wit_yuan
  132. // 时间 : 2014-11-07
  133. ////////////////////////////////////////////////////////////////////////////
  134. void IIC_Init(void)
  135. {
  136. /* enable the User key clock */
  137. rcu_periph_clock_enable(RCU_GPIOA);
  138. rcu_periph_clock_enable(RCU_GPIOB);
  139. rcu_periph_clock_enable(RCU_AF);
  140. gpio_pin_remap_config(GPIO_SWJ_NONJTRST_REMAP, ENABLE);
  141. gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP, ENABLE);
  142. gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4);
  143. gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
  144. gpio_bit_set(GPIOB, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4);
  145. SET_LCD_BL_LIGHT();
  146. // gpio_bit_set(GPIOC, GPIO_PIN_12);
  147. /*GPIO_InitTypeDef GPIO_InitStructure;
  148. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  149. GPIO_StructInit(&GPIO_InitStructure);
  150. GPIO_InitStructure.GPIO_PIN = GPIO_PIN_6 | GPIO_PIN_7;
  151. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  152. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  153. GPIO_Init(GPIOB, &GPIO_InitStructure);
  154. GPIO_SetBits(GPIOB, GPIO_PIN_6|GPIO_PIN_7);*/
  155. }
  156. void LCDProcess()
  157. {
  158. ram[0]=ram1;
  159. ram[1]=ram2;
  160. ram[2]=ram3;
  161. ram[3]=ram4;
  162. char i, j;
  163. uint8_t data = 0;
  164. for (j = 0; j < 12; j++) // all the lights bright
  165. {
  166. for (i = 0; i < 4; i++)
  167. {
  168. if (((ram[i]>>j )&0x01)== 0x01)
  169. {
  170. if (i == 0)
  171. {
  172. data = data | 0x01;
  173. }
  174. else if (i == 1)
  175. {
  176. data = data | 0x02;
  177. }
  178. else if (i == 2)
  179. {
  180. data = data | 0x04;
  181. }
  182. else if (i == 3)
  183. {
  184. data = data | 0x08;
  185. }
  186. else
  187. {
  188. }
  189. }
  190. }
  191. write_1621(j, data);
  192. data = 0;
  193. // delay(5);
  194. }
  195. }
  196. /**
  197. * @brief ht16c22初始化
  198. * @param 无
  199. * @retval 无
  200. */
  201. void ht16c22_init(void)
  202. {
  203. int i = 0;
  204. IIC_Init();
  205. LCD_init();
  206. //Display_temp(123,1);
  207. //DH_ON;
  208. //Display_num(2, 2);
  209. //Display_num(3, 1);
  210. }
  211. /**
  212. * @brief 给ht16c22的addr 写dat
  213. * @param addr:地址,dat:数据
  214. * @retval 无
  215. */
  216. void ht16c22_display(uint8_t add,uint8_t ram_num,uint16_t ram_temp)
  217. {
  218. ram[0]=ram1;
  219. ram[1]=ram2;
  220. ram[2]=ram3;
  221. ram[3]=ram4;
  222. char i, j;
  223. uint8_t data = 0;
  224. for (i = 0; i < 4; i++)
  225. {
  226. if (((ram[i]>>add )&0x01)== 0x01)
  227. {
  228. if (i == 0)
  229. {
  230. data = data | 0x01;
  231. }
  232. else if (i == 1)
  233. {
  234. data = data | 0x02;
  235. }
  236. else if (i == 2)
  237. {
  238. data = data | 0x04;
  239. }
  240. else if (i == 3)
  241. {
  242. data = data | 0x08;
  243. }
  244. else
  245. {
  246. }
  247. }
  248. write_1621(add, data);
  249. // delay(5);
  250. }
  251. }
  252. /**
  253. * @brief 清空液晶屏显示的内容
  254. * @param 无
  255. * @retval 无
  256. */
  257. void ht16c22_clear(void)
  258. {
  259. char i;
  260. for (i = 0; i < 12; i++) // all the lights bright
  261. {
  262. write_1621(i, 0x00);
  263. // delay(5);
  264. }
  265. ram1 = 0X00000000;
  266. ram2 = 0X00000000;
  267. ram3 = 0X00000000;
  268. ram4 = 0X00000000;
  269. }
  270. /**
  271. * @brief 液晶屏第wei位数码管,显示Open_animation[num]数据
  272. * @param wei:液晶屏位 num:Open_animation数组的数据
  273. * @retval 无
  274. */
  275. char Open_animation[] = {0, 0, 0x04, 0x24, 0xA4, 0xA6, 0xA7, 0xB7, 0xF7};
  276. static void Display_animation(u8 wei, u8 num)
  277. {
  278. }
  279. /**
  280. * @brief 开机动画
  281. * @param 无
  282. * @retval 无
  283. */
  284. void Animation(void)
  285. {
  286. }
  287. /**
  288. * @brief 字母显示,第wei位,显示Letters[num]“ABCDEF”
  289. * @param wei:位号 num:字母
  290. * @retval 无
  291. */
  292. char Letters[] = {0x77, 0xE6, 0xF0, 0xA7, 0xF4, 0x74, 0xD6, 0x04, 0, 0xff}; // abcdefs- 空白 全填满
  293. void Dis_letter(u8 wei, u8 num)
  294. {
  295. }
  296. /**
  297. * @brief 液晶屏第wei位数码管,显示LCD_Table[num]数据,该数值存放“1.2.3.4..........”
  298. * @param wei:液晶屏位 num:LCD_Table数组的数据
  299. * @retval 无
  300. */
  301. char LCD_Table[] = {0xF3, 0x03, 0xB5, 0x97, 0x47, 0xD6, 0xF6, 0x13, 0xF7, 0xD7, 0xF0};
  302. void Display_num(u8 wei, u8 num)
  303. {
  304. if (wei == 1)
  305. {
  306. switch (num)
  307. {
  308. case 0:
  309. ram4 |= 0x0004;
  310. ram4 |= 0x0800;
  311. ram3 &= ~ 0x0004;
  312. ram3 |= 0x0800;
  313. ram2 |= 0x0004;
  314. ram2 |= 0x0800;
  315. ram1 |= 0x0800;
  316. break;
  317. case 1:
  318. ram4 &= ~ 0x0004;
  319. ram4 &= ~0x0800;
  320. ram3 &= ~ 0x0004;
  321. ram3 |= 0x0800;
  322. ram2 &= ~0x0004;
  323. ram2 |= 0x0800;
  324. ram1 &= ~ 0x0800;
  325. break;
  326. case 2:
  327. ram4 &= ~ 0x0004;
  328. ram4 |= 0x0800;
  329. ram3 |= 0x0004;
  330. ram3 |= 0x0800;
  331. ram2|= 0x0004;
  332. ram2 &= ~0x0800;
  333. ram1 |= 0x0800;
  334. break;
  335. case 3:
  336. ram4 &= ~0x0004;
  337. ram4 |= 0x0800;
  338. ram3 |= 0x0004;
  339. ram3 |= 0x0800;
  340. ram2 &= ~ 0x0004;
  341. ram2 |= 0x0800;
  342. ram1 |= 0x0800;
  343. break;
  344. case 4:
  345. ram4|=0x0004;
  346. ram4 &= ~ 0x0800;
  347. ram3 |= 0x0004;
  348. ram3 |= 0x0800;
  349. ram2 &= ~ 0x0004;
  350. ram2 |=0x0800;
  351. ram1 &= ~ 0x0800;
  352. break;
  353. case 5:
  354. ram4 |= 0x0004;
  355. ram4 |= 0x0800;
  356. ram3 |=0x0004;
  357. ram3 &= ~0x0800;
  358. ram2 &= ~0x0004;
  359. ram2 |=0x0800;
  360. ram1 |=0x0800;
  361. break;
  362. case 6:
  363. ram4 |= 0x0004;
  364. ram4 |= 0x0800;
  365. ram3 |=0x0004;
  366. ram3 &= ~ 0x0800;
  367. ram2 |= 0x0004;
  368. ram2 |= 0x0800;
  369. ram1 |= 0x0800;
  370. break;
  371. case 7:
  372. ram4 &= ~ 0x0004;
  373. ram4 |=0x0800;
  374. ram3 &= ~ 0x0004;
  375. ram3 |=0x0800;
  376. ram2 &= ~ 0x0004;
  377. ram2|=0x0800;
  378. ram1 &= ~ 0x0800;
  379. break;
  380. case 8:
  381. ram4 |= 0x0004;
  382. ram4 |= 0x0800;
  383. ram3 |= 0x0004;
  384. ram3 |= 0x0800;
  385. ram2 |= 0x0004;
  386. ram2 |= 0x0800;
  387. ram1 |= 0x0800;
  388. break;
  389. case 9:
  390. ram4 |= 0x0004;
  391. ram4 |= 0x0800;
  392. ram3 |= 0x0004;
  393. ram3 |= 0x0800;
  394. ram2 &= ~ 0x0004;
  395. ram2 |=0x0800;
  396. ram1 |= 0x0800;
  397. /* case 10:
  398. ram4 |= 0x0001;
  399. ram4 |= 0x0200;
  400. ram3 &= ~0x0001;
  401. ram3 |= 0x0200;
  402. ram2 &= ~0x0001;
  403. ram2 |= 0x0800;
  404. ram1 |= 0x0001;*/
  405. break;
  406. default:
  407. break;
  408. }
  409. }
  410. else if (wei == 2)
  411. {
  412. switch (num)
  413. {
  414. case 0:
  415. ram4 |= 0x0400;
  416. ram4 |= 0x0200;
  417. ram3 &= ~ 0x0400;
  418. ram3|= 0x0200;
  419. ram2 |= 0x0400;
  420. ram2 |= 0x0200;
  421. ram1 |= 0x0200;
  422. break;
  423. case 1:
  424. ram4 &= ~0x0400;
  425. ram4 &= ~0x0200;
  426. ram3 &=~0x0400;
  427. ram3|= 0x0200;
  428. ram2 &=~ 0x0400;
  429. ram2 |=0x0200;
  430. ram1 &= ~ 0x0200;
  431. break;
  432. case 2:
  433. ram4 &= ~ 0x0400;
  434. ram4|=0x0200;
  435. ram3 |= 0x0400;
  436. ram3 |= 0x0200;
  437. ram2 |=0x0400;
  438. ram2 &= ~ 0x0200;
  439. ram1 |= 0x0200;
  440. break;
  441. case 3:
  442. ram4 &= ~0x0400;
  443. ram4 |= 0x0200;
  444. ram3 |= 0x0400;
  445. ram3 |= 0x0200;
  446. ram2 &= ~ 0x0400;
  447. ram2 |= 0x0200;
  448. ram1 |= 0x0200;
  449. break;
  450. case 4:
  451. ram4|=0x0400;
  452. ram4 &= ~ 0x0200;
  453. ram3 |= 0x0400;
  454. ram3 |= 0x0200;
  455. ram2 &= ~ 0x0400;
  456. ram2 |=0x0200;
  457. ram1 &= ~ 0x0200;
  458. break;
  459. case 5:
  460. ram4 |= 0x0400;
  461. ram4 |= 0x0200;
  462. ram3 |=0x0400;
  463. ram3 &= ~0x0200;
  464. ram2 &= ~0x0400;
  465. ram2 |=0x0200;
  466. ram1 |=0x0200;
  467. break;
  468. case 6:
  469. ram4 |= 0x0400;
  470. ram4 |= 0x0200;
  471. ram3 |=0x0400;
  472. ram3 &= ~ 0x0200;
  473. ram2 |= 0x0400;
  474. ram2 |= 0x0200;
  475. ram1 |= 0x0200;
  476. break;
  477. case 7:
  478. ram4 &= ~ 0x0400;
  479. ram4 |=0x0200;
  480. ram3 &= ~ 0x0400;
  481. ram3 |=0x0200;
  482. ram2 &= ~ 0x0400;
  483. ram2|=0x0200;
  484. ram1 &= ~ 0x0200;
  485. break;
  486. case 8:
  487. ram4 |= 0x0400;
  488. ram4 |= 0x0200;
  489. ram3 |= 0x0400;
  490. ram3 |= 0x0200;
  491. ram2 |= 0x0400;
  492. ram2 |= 0x0200;
  493. ram1 |= 0x0200;
  494. break;
  495. case 9:
  496. ram4 |= 0x0400;
  497. ram4 |= 0x0200;
  498. ram3 |= 0x0400;
  499. ram3 |= 0x0200;
  500. ram2 &= ~ 0x0400;
  501. ram2 |=0x0200;
  502. ram1 |= 0x0200;
  503. break;
  504. default:
  505. break;
  506. }
  507. }
  508. else if (wei == 3)
  509. {
  510. switch (num)
  511. {
  512. case 0:
  513. ram4 |= 0x0080;
  514. ram4 |= 0x0040;
  515. ram3 &= ~ 0x0080;
  516. ram3|= 0x0040;
  517. ram2 |= 0x0080;
  518. ram2 |= 0x0040;
  519. ram1 |= 0x0040;
  520. break;
  521. case 1:
  522. ram4 &= ~0x0080;
  523. ram4 &= ~0x0040;
  524. ram3 &=~0x0080;
  525. ram3|= 0x0040;
  526. ram2 &=~ 0x0080;
  527. ram2 |=0x0040;
  528. ram1 &= ~ 0x0040;
  529. break;
  530. case 2:
  531. ram4 &= ~ 0x0080;
  532. ram4|=0x0040;
  533. ram3 |= 0x0080;
  534. ram3 |= 0x0040;
  535. ram2 |=0x0080;
  536. ram2 &= ~ 0x0040;
  537. ram1 |= 0x0040;
  538. break;
  539. case 3:
  540. ram4 &= ~0x0080;
  541. ram4 |= 0x0040;
  542. ram3 |= 0x0080;
  543. ram3 |= 0x0040;
  544. ram2 &= ~ 0x0080;
  545. ram2 |= 0x0040;
  546. ram1 |= 0x0040;
  547. break;
  548. case 4:
  549. ram4|=0x0080;
  550. ram4 &= ~ 0x0040;
  551. ram3 |= 0x0080;
  552. ram3 |= 0x0040;
  553. ram2 &= ~ 0x0080;
  554. ram2 |=0x0040;
  555. ram1 &= ~ 0x0040;
  556. break;
  557. case 5:
  558. ram4 |= 0x0080;
  559. ram4 |= 0x0040;
  560. ram3 |=0x0080;
  561. ram3 &= ~0x0040;
  562. ram2 &= ~0x0080;
  563. ram2 |=0x0040;
  564. ram1 |=0x0040;
  565. break;
  566. case 6:
  567. ram4 |= 0x0080;
  568. ram4 |= 0x0040;
  569. ram3 |=0x0080;
  570. ram3 &= ~ 0x0040;
  571. ram2 |= 0x0080;
  572. ram2 |= 0x0040;
  573. ram1 |= 0x0040;
  574. break;
  575. case 7:
  576. ram4 &= ~ 0x0080;
  577. ram4 |=0x0040;
  578. ram3 &= ~ 0x0080;
  579. ram3 |=0x0040;
  580. ram2 &= ~ 0x0080;
  581. ram2|=0x0040;
  582. ram1 &= ~ 0x0040;
  583. break;
  584. case 8:
  585. ram4 |= 0x0080;
  586. ram4 |= 0x0040;
  587. ram3 |= 0x0080;
  588. ram3 |= 0x0040;
  589. ram2 |= 0x0080;
  590. ram2 |= 0x0040;
  591. ram1 |= 0x0040;
  592. break;
  593. case 9:
  594. ram4 |= 0x0080;
  595. ram4 |= 0x0040;
  596. ram3 |= 0x0080;
  597. ram3 |= 0x0040;
  598. ram2 &= ~ 0x0080;
  599. ram2 |=0x0040;
  600. ram1 |= 0x0040;
  601. break;
  602. default:
  603. break;
  604. }
  605. }
  606. LCDProcess();
  607. }
  608. /**
  609. * @brief 多个位显示LCD_Table[num]数据,该数值存放“1.2.3.4..........”
  610. * @param num:LCD_Table数组的数据
  611. * @retval 无
  612. */
  613. // 做了最后位四舍五入 以及 百位为0 不显示的操作
  614. void Display_Multidigit(u16 num) // 显示多位数,不能超过四位
  615. {
  616. u8 ge,shi,bai;
  617. num = (u16)( ((float) num/10) +0.5);
  618. num = num *10;
  619. bai = num%1000/100;
  620. shi = num%100/10;
  621. ge = num%10;
  622. if(bai == 0)
  623. {
  624. //Dis_letter(1,8);
  625. }
  626. else
  627. {
  628. Display_num(1, bai);
  629. }
  630. Display_num(2, shi);
  631. Display_num(3, ge);
  632. }
  633. // 显示实时 正温度 不四舍五入
  634. void Display_R_Multidigit(int16_t num)
  635. {
  636. u8 ge,shi,bai;
  637. //求绝对值变为正的
  638. num = abs(num);
  639. bai = num%1000/100;
  640. shi = num%100/10;
  641. ge = num%10;
  642. if(bai == 0)
  643. {
  644. Dis_letter(1,8);
  645. }
  646. else
  647. {
  648. Display_num(1, bai);
  649. }
  650. Display_num(2, shi);
  651. Display_num(3, ge);
  652. }
  653. void Display_F_Multidigit(int16_t num) // 显示负温度 不四舍五入
  654. {
  655. }
  656. // 显示温度界面 摄氏度
  657. /*
  658. type 0 表示设置温度 四舍五入
  659. 1 表示实时温度 无四舍五入 有正 有负
  660. */
  661. void Display_temp(int16_t temp, uint8_t type) // 温度显示
  662. {
  663. if(type == 0)
  664. {
  665. Display_Multidigit((uint16_t)temp);
  666. DH_ON;
  667. }
  668. //实时温度
  669. else if(type == 1)
  670. {
  671. if(temp >= 0)
  672. {
  673. Display_R_Multidigit((uint16_t)temp);
  674. DH_ON;
  675. }
  676. else
  677. //小于0
  678. {
  679. Display_F_Multidigit(temp);
  680. //小数点关闭
  681. DH_OFF;
  682. }
  683. }
  684. //摄氏度 C
  685. // DU_ON;
  686. // Display_num(4, 10);
  687. }
  688. /*
  689. *没在用
  690. */
  691. // 显示温度界面 华氏度 //没在用
  692. // 输入为 *10 的温度
  693. void Display_H_temp(int16_t temp) // 温度显示
  694. {
  695. }
  696. /* @brief 湿度显示界面
  697. * @param hum:湿度
  698. * @retval 无
  699. */
  700. void Dis_hum(u8 hum)
  701. {
  702. }