当前位置:   article > 正文

蓝桥杯-单片机基础20——第14届省赛真题代码详解_第十四届蓝桥杯单片机程序题简述

第十四届蓝桥杯单片机程序题简述

网上传言说14届最难,实际做下来感觉确实是这样的

本试题,需要将矩阵键盘短接,J3的555定时器输出口与P34短接

1.比赛题目

2.编程的大致思路

  • 首先,完成基础代码与数码管的不同窗口,定义大部分要用到的变量,并测试每个窗口是否显示正常
  • 然后,添加外设模块,并逐个测试模块在不同窗口下的显示效果
  • 接着,进行按键的定义和数值处理函数的优化,将逻辑功能整体实现清晰
  • 最后,对杂七杂八的led等部分进行设置,测试各个功能是否正常

3.编程心得

  1. 555定时器,除了要短接引脚,还要用RB3调节频率的数值
  2. 光敏电阻数字跳动太大:加1ms延时,加中断刷新,加最后一步等待应答,加临时变量判断数据正确再写入
  3. ds18b20,注意你采用的是不是三位数进行记录
  4. ds1302,最好用中断,每隔1s提取一遍时间到变量中,再用数码管显示
  5. 对于刷新频率为1s为单位的变量,可以直接读取ds1302的秒位,判断是否达到1s的整数倍
  6. 程序必须要有一个50us的中断处理,有了50us其他的刷新很好确定
  7. 对于led的操作。当led的变化有规律时——建立数组存放led的状态。当led没有规律时——一定要学会位运算,直接对变量value_led进行位操作,然后利用中断传入led处理函数
  8. 对于io编程模式,要注意对锁存器常关闭。同时采用先赋值P0端口,再打开锁存器方式,这样有效防止数据冲突。
  9. 所有的外设,除了555以外,都可以设置一个刷新的标志变量,可以提升系统运行效率

4.代码参考

4.1 头文件

onewire.h        ds1302.h        iic.h

和上一篇博客一样,和15届官方发的没有区别。为了节省篇幅这里不放出,可以参考上一篇文章,基本没有变动

basecode.h

  1. #ifndef __BASECODE_H__
  2. #define __BASECODE_H__
  3. void select_HC573 ( unsigned char channal );
  4. void state_SMG ( unsigned char pos_SMG , unsigned char value_SMG );
  5. void state_SMG_all ( unsigned char value_SMG_all );
  6. void state_relay ( unsigned char value_relay );
  7. void state_led ( unsigned char value_led );
  8. void init_sys ();
  9. void init_ds1302 ();
  10. void init_temperature ();
  11. #endif

4.2 底层文件

onewire.c        ds1302.c        iic.c        和常规一样,也和上一篇博客一样

basecode.c

  1. #include <ds1302.h>
  2. #include <onewire.h>
  3. #include <reg52.h>
  4. #include <intrins.h>
  5. //锁存器通道选择函数
  6. void select_HC573 ( unsigned char channal )
  7. {
  8. switch ( channal )
  9. {
  10. case 4:
  11. P2 = ( P2 & 0x1f ) | 0x80;
  12. break;
  13. case 5:
  14. P2 = ( P2 & 0x1f ) | 0xa0;
  15. break;
  16. case 6:
  17. P2 = ( P2 & 0x1f ) | 0xc0;
  18. break;
  19. case 7:
  20. P2 = ( P2 & 0x1f ) | 0xe0;
  21. break;
  22. case 0:
  23. P2 = ( P2 & 0x1f ) | 0x00;
  24. break;
  25. }
  26. }
  27. //单位数码管显示函数
  28. void state_SMG ( unsigned char pos_SMG , unsigned char value_SMG )
  29. {
  30. select_HC573 ( 0 );
  31. P0 = 0x01 << pos_SMG;
  32. select_HC573( 6 );
  33. select_HC573 ( 0 );
  34. P0 = value_SMG;
  35. select_HC573( 7 );
  36. select_HC573 ( 0 );
  37. }
  38. //全位数码管静态显示
  39. void state_SMG_all ( unsigned char value_SMG_all )
  40. {
  41. select_HC573 ( 0 );
  42. P0 = 0xff;
  43. select_HC573( 6 );
  44. select_HC573 ( 0 );
  45. P0 = value_SMG_all;
  46. select_HC573( 7 );
  47. select_HC573 ( 0 );
  48. }
  49. //led灯光控制函数
  50. void state_led ( unsigned char value_led )
  51. {
  52. select_HC573 ( 0 );
  53. P0 = 0xff;
  54. select_HC573 ( 4 );
  55. P0 = value_led;
  56. select_HC573 ( 4 );
  57. select_HC573 ( 0 );
  58. }
  59. //初始化系统,关闭继电器和蜂鸣器
  60. void init_sys ()
  61. {
  62. select_HC573 ( 0 );
  63. P0 = 0xff;
  64. select_HC573 ( 4 );
  65. select_HC573 ( 0 );
  66. P0 = 0x00;
  67. select_HC573 ( 5 );
  68. select_HC573 ( 0 );
  69. }
  70. void init_temperature ()
  71. {
  72. unsigned char LSB,MSB;
  73. init_ds18b20();
  74. Write_DS18B20(0xcc);
  75. Write_DS18B20(0x44);
  76. do{
  77. init_ds18b20();
  78. Write_DS18B20(0xcc);
  79. Write_DS18B20(0xbe);
  80. LSB = Read_DS18B20();
  81. MSB = Read_DS18B20();
  82. MSB = ( MSB << 4 ) | ( LSB >> 4 );
  83. }while ( MSB == 85 );
  84. }

4.3主函数文件

  1. #include <reg52.h>
  2. #include <intrins.h>
  3. #include "onewire.h"
  4. #include "iic.h"
  5. #include "ds1302.h"
  6. #include "basecode.h"
  7. sfr P4 = 0xc0;
  8. sfr AUXR = 0x8e;
  9. sbit C1 = P4^4;
  10. sbit C2 = P4^2;
  11. sbit H1 = P3^3;
  12. sbit H2 = P3^2;
  13. unsigned char code duanma[20] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
  14. 0x88,0x83,0xc6,0xc0,0x86,0x8e,0xbf,0x7f,0x89,0x8c};
  15. unsigned char code duanma_dot[16]={ 0x40 , 0x79 , 0x24 , 0x30 , 0x19 , 0x12 , 0x02 , 0x78 ,0x00 , 0x10 };
  16. unsigned char code Write_address [7] = { 0x80 , 0x82 , 0x84 , 0x86 , 0x88 , 0x8a , 0x8c};
  17. unsigned char code Read_address [7] = { 0x81 , 0x83 , 0x85 , 0x87 , 0x89 , 0x8b , 0x8d };
  18. //2022year 3month 31day 5 23 59 50
  19. unsigned char date_ds1302 [7] = { 0x50 , 0x50 , 0x23 , 0x31 , 0x03 , 0x05 , 0x22 };
  20. unsigned int humidity = 0;
  21. unsigned char value_led = 0xff;
  22. unsigned char trg_count = 0;
  23. unsigned char trg_time_hour = 0x00;
  24. unsigned char trg_time_min = 0x00;
  25. unsigned char trg_time_second = 0x00;
  26. unsigned int max_temperature = 0;
  27. unsigned int average_temperature = 0;
  28. unsigned int old_temperature = 0;
  29. unsigned int max_humidity = 0;
  30. unsigned int average_humidity = 0;
  31. unsigned int old_humidity = 0;
  32. unsigned char SMG_flag = 1;
  33. void flash_SMG ();
  34. void rd1running ();
  35. void flash_date ();
  36. void valuerunning ();
  37. void keyrunning ();
  38. void Delay1ms() //@12.000MHz
  39. {
  40. unsigned char i, j;
  41. i = 12;
  42. j = 169;
  43. do
  44. {
  45. while (--j);
  46. } while (--i);
  47. }
  48. bit flash_rd1 = 0;
  49. unsigned char rd1_value = 0;
  50. void rd1running()
  51. {
  52. unsigned char tmp = 0;
  53. if ( flash_rd1 == 1 )
  54. {
  55. I2CStart();
  56. I2CSendByte(0x90);
  57. I2CWaitAck();
  58. I2CSendByte(0x01);
  59. I2CWaitAck();
  60. I2CStop();
  61. Delay1ms();
  62. I2CStart();
  63. I2CSendByte(0x91);
  64. I2CWaitAck();
  65. tmp = I2CReceiveByte();
  66. I2CWaitAck();
  67. I2CSendAck(1);
  68. I2CStop();
  69. flash_rd1 = 0;
  70. }
  71. if ( tmp<220 && tmp>0 )
  72. {
  73. rd1_value = tmp;
  74. }
  75. }
  76. void Delay700ms() //@12.000MHz
  77. {
  78. unsigned char i, j, k;
  79. _nop_();
  80. _nop_();
  81. i = 32;
  82. j = 236;
  83. k = 16;
  84. do
  85. {
  86. do
  87. {
  88. while (--k);
  89. } while (--j);
  90. rd1running ();
  91. flash_date ();
  92. valuerunning ();
  93. keyrunning ();
  94. } while (--i);
  95. }
  96. bit flash_ds18b20 = 0;
  97. unsigned int temperature = 0;
  98. unsigned int set_temperature = 300;
  99. void flash_temperature ()
  100. {
  101. if ( flash_ds18b20 == 1 )
  102. {
  103. unsigned char LSB,MSB;
  104. old_temperature = temperature;
  105. init_ds18b20();
  106. Write_DS18B20(0xcc);
  107. Write_DS18B20(0x44);
  108. Delay700ms();
  109. init_ds18b20();
  110. Write_DS18B20(0xcc);
  111. Write_DS18B20(0xbe);
  112. LSB = Read_DS18B20();
  113. MSB = Read_DS18B20();
  114. temperature = MSB;
  115. temperature = ( temperature << 8 ) | LSB;
  116. temperature = (temperature >> 4)*10 + (LSB & 0x0f)*0.625;
  117. flash_ds18b20 = 0;
  118. }
  119. }
  120. void init_ds1302 ()
  121. {
  122. unsigned char i;
  123. Write_Ds1302_Byte ( 0x8e , 0x00 );
  124. for ( i=0 ; i<7 ; i++ )
  125. {
  126. Write_Ds1302_Byte ( Write_address[i] , date_ds1302[i] );
  127. }
  128. Write_Ds1302_Byte ( 0x8e , 0x80 );
  129. }
  130. bit flash_ds1302 = 0;
  131. void flash_date()
  132. {
  133. if ( flash_ds1302 == 1 )
  134. {
  135. unsigned char i;
  136. for ( i=0 ; i<7 ; i++ )
  137. {
  138. date_ds1302[i] = Read_Ds1302_Byte ( Read_address[i] );
  139. }
  140. flash_ds1302 = 0;
  141. }
  142. }
  143. //==============================================================================
  144. void init_timer01 ()
  145. {
  146. AUXR &= 0xBF; //定时器时钟12T模式
  147. TMOD = 0x06; //设置定时器模式
  148. TL1 = 0xCE; //设置定时初值
  149. TH1 = 0xFF; //设置定时初值
  150. TF1 = 0; //清除TF1标志
  151. TR1 = 1; //定时器1开始计时
  152. TL0 = 0xFF; //设置定时初值
  153. TH0 = 0xFF; //设置定时初值
  154. TF0 = 0; //清除TF0标志
  155. TR0 = 1; //定时器0开始计时
  156. EA = 1;
  157. ET0 = 1;
  158. ET1 = 1;
  159. }
  160. unsigned int count_timer0 = 0;
  161. void timer0_service () interrupt 1
  162. {
  163. count_timer0 ++;
  164. }
  165. //=============================================================================
  166. bit flag_100ms = 0;
  167. unsigned int count_fre = 0;
  168. unsigned char count_50us = 0;
  169. unsigned char count_5ms = 0;
  170. unsigned char flash_count = 0;//数码管刷新位
  171. unsigned char date_hour;
  172. unsigned char date_min;
  173. unsigned char date_second;
  174. void timer1_service () interrupt 3
  175. {
  176. if ( ++count_50us == 200 )
  177. {
  178. flash_rd1 = 1;
  179. count_50us = 0;
  180. }
  181. if ( count_50us % 40 == 0 )
  182. {
  183. if ( SMG_flag == 1 )//窗口1
  184. {
  185. if ( ++flash_count == 9 )
  186. {
  187. flash_count = 0;
  188. }
  189. }
  190. else if ( SMG_flag == 2 )//窗口2
  191. {
  192. if ( ++flash_count > 7 )
  193. {
  194. flash_count = 0;
  195. }
  196. }
  197. else if ( SMG_flag == 3 )//窗口3
  198. {
  199. if ( ++flash_count > 7 )
  200. {
  201. flash_count = 0;
  202. }
  203. }
  204. else if ( SMG_flag == 4 )//窗口4
  205. {
  206. if ( ++flash_count == 9 )
  207. {
  208. flash_count = 0;
  209. }
  210. }
  211. else if ( SMG_flag == 5 )//窗口5
  212. {
  213. if ( ++flash_count > 3 )
  214. {
  215. flash_count = 0;
  216. }
  217. }
  218. else if ( SMG_flag == 6 )//窗口6
  219. {
  220. if ( ++flash_count > 6 )
  221. {
  222. flash_count = 0;
  223. }
  224. }
  225. flash_SMG (); //刷新数码管一位
  226. }
  227. if ( count_50us % 100 == 0 )
  228. {
  229. count_5ms++;
  230. if ( count_5ms == 200 )
  231. {
  232. count_5ms = 0;
  233. count_fre = count_timer0;
  234. count_timer0 = 0;
  235. date_hour = date_ds1302[2]; //时间提取出来显示,数码管才不会闪烁
  236. date_min = date_ds1302[1];
  237. date_second = date_ds1302[0];
  238. }
  239. if ( count_5ms % 20 == 0 )
  240. {
  241. flag_100ms = ~flag_100ms;
  242. }
  243. }
  244. if ( count_50us % 50 == 0 )
  245. {
  246. flash_ds18b20 = 1;
  247. state_led ( value_led );
  248. }
  249. if ( count_50us % 40 == 0 )
  250. {
  251. flash_ds1302 = 1;
  252. }
  253. }
  254. bit rd1_3s = 0;
  255. unsigned char save_SMG_flag = 1;
  256. void valuerunning ()
  257. {
  258. if ( count_fre >= 200 && count_fre <= 2000 )
  259. {
  260. value_led |= 0x10;
  261. old_humidity = humidity;
  262. humidity = count_fre /22.5*10;
  263. if ( max_humidity < humidity )
  264. {
  265. max_humidity = humidity;
  266. }
  267. average_humidity = (average_humidity + humidity)/2;
  268. }
  269. else
  270. {
  271. humidity = 0;
  272. value_led &= 0xef;
  273. }
  274. if ( temperature != 0 )
  275. {
  276. if ( max_temperature < temperature && temperature < 999 )
  277. {
  278. max_temperature = temperature;
  279. }
  280. average_temperature = (average_temperature + temperature)/2;
  281. }
  282. if ( rd1_value < 90 && rd1_3s == 0 )
  283. {
  284. trg_count ++;
  285. trg_time_hour = date_ds1302[2];
  286. trg_time_min = date_ds1302[1];
  287. trg_time_second = date_ds1302[0];
  288. save_SMG_flag = SMG_flag;
  289. }
  290. if ( trg_count != 0 )
  291. {
  292. if ( date_ds1302[0] - trg_time_second <= 0x03 )
  293. {
  294. rd1_3s = 1;
  295. SMG_flag = 6;
  296. }
  297. else
  298. {
  299. if ( rd1_3s == 1 )
  300. {
  301. SMG_flag = save_SMG_flag;
  302. }
  303. rd1_3s = 0;
  304. }
  305. }
  306. if ( SMG_flag == 1 )
  307. {
  308. value_led = ( value_led | 0x07 ) & 0xfe;
  309. }
  310. else if ( SMG_flag == 2 || SMG_flag == 3 || SMG_flag == 4 )
  311. {
  312. value_led = ( value_led | 0x07 ) & 0xfd;
  313. }
  314. else if ( SMG_flag == 6 )
  315. {
  316. value_led = ( value_led | 0x07 ) & 0xfb;
  317. }
  318. else
  319. {
  320. value_led = ( value_led | 0x07 ) ;
  321. }
  322. if ( temperature > set_temperature )
  323. {
  324. if ( flag_100ms == 0 )
  325. {
  326. value_led &= 0xf7;
  327. }
  328. else
  329. {
  330. value_led |= 0x08;
  331. }
  332. }
  333. else
  334. {
  335. value_led |= 0x08;
  336. }
  337. if ( trg_count >1 && temperature > old_temperature && humidity > old_humidity )
  338. {
  339. value_led &= 0xbf;
  340. }
  341. else
  342. {
  343. value_led |= 0x40;
  344. }
  345. }
  346. void Delay4ms() //@12.000MHz
  347. {
  348. unsigned char i, j;
  349. i = 47;
  350. j = 174;
  351. do
  352. {
  353. while (--j);
  354. } while (--i);
  355. }
  356. bit key9_2s = 0;
  357. bit flag_clear = 0;
  358. unsigned char key9_time = 0x00;
  359. void keyrunning ()
  360. {
  361. C1 = 0;
  362. C2 = H1 = H2 = 1;
  363. if ( H1 == 0 )
  364. {
  365. Delay4ms();
  366. if ( H1 == 0 )//S4
  367. {
  368. switch ( SMG_flag )
  369. {
  370. case 1:
  371. SMG_flag = 2;
  372. break;
  373. case 2:case 3:case 4:
  374. SMG_flag = 5;
  375. break;
  376. case 5:
  377. SMG_flag = 1;
  378. break;
  379. }
  380. while ( H1 == 0 );
  381. }
  382. }
  383. else if ( H2 == 0 )
  384. {
  385. Delay4ms();
  386. if ( H2 == 0 )//S5
  387. {
  388. if ( SMG_flag != 1 )
  389. {
  390. switch ( SMG_flag )
  391. {
  392. case 2:
  393. SMG_flag = 3;
  394. break;
  395. case 3:
  396. SMG_flag = 4;
  397. break;
  398. case 4:
  399. SMG_flag = 2;
  400. break;
  401. }
  402. }
  403. while ( H2 == 0 );
  404. }
  405. }
  406. C2 = 0;
  407. C1 = H1 = H2 = 1;
  408. if ( H1 == 0 )
  409. {
  410. Delay4ms();
  411. if ( H1 == 0 )//S8
  412. {
  413. if ( SMG_flag == 5 )
  414. {
  415. set_temperature += 10;
  416. if ( set_temperature == 1000 )
  417. {
  418. set_temperature = 990;
  419. }
  420. }
  421. while ( H1 == 0 );
  422. }
  423. }
  424. else if ( H2 == 0 )
  425. {
  426. Delay4ms();
  427. if ( H2 == 0 )//S9
  428. {
  429. if ( SMG_flag == 5 )
  430. {
  431. set_temperature -= 10;
  432. if ( set_temperature > 990 )
  433. {
  434. set_temperature = 0;
  435. }
  436. }
  437. while ( H2 == 0 )
  438. {
  439. if ( SMG_flag == 4 && key9_2s == 0 )
  440. {
  441. key9_2s = 1;
  442. key9_time = date_ds1302[0];
  443. }
  444. if ( date_ds1302[0] - key9_time > 0x02 )
  445. {
  446. key9_2s = 0;
  447. flag_clear = 1;
  448. break;
  449. }
  450. }
  451. while ( H2 == 0 );
  452. if ( flag_clear == 1 )
  453. {
  454. trg_count = 0;
  455. trg_time_hour = 0;
  456. trg_time_min = 0;
  457. trg_time_second = 0;
  458. flag_clear = 0;
  459. }
  460. }
  461. }
  462. }
  463. void flash_SMG ()
  464. {
  465. state_SMG_all ( 0xff );
  466. if ( SMG_flag == 1 )
  467. {
  468. switch ( flash_count )
  469. {
  470. case 0 :
  471. state_SMG ( 0 , duanma[date_hour/16] );
  472. break;
  473. case 1 :
  474. state_SMG ( 1 , duanma[date_hour%16] );
  475. break;
  476. case 2 :
  477. state_SMG ( 2 , duanma[16] );
  478. break;
  479. case 3 :
  480. state_SMG ( 3 , duanma[date_min/16] );
  481. break;
  482. case 4 :
  483. state_SMG ( 4 , duanma[date_min%16] );
  484. break;
  485. case 5 :
  486. state_SMG ( 5 , duanma[16] );
  487. break;
  488. case 6 :
  489. state_SMG ( 6 , duanma[date_second/16] );
  490. break;
  491. case 7 :
  492. state_SMG ( 7 , duanma[date_second%16] );
  493. break;
  494. case 8 :
  495. state_SMG_all ( 0xff );
  496. break;
  497. }
  498. }
  499. else if ( SMG_flag == 2 )
  500. {
  501. if ( trg_count == 0 )
  502. {
  503. state_SMG ( 0 , duanma[12] );
  504. }
  505. else
  506. {
  507. switch ( flash_count )
  508. {
  509. case 0 :
  510. state_SMG ( 0 , duanma[12] );
  511. break;
  512. case 1 :
  513. state_SMG ( 2 , duanma[max_temperature/100] );
  514. break;
  515. case 2 :
  516. state_SMG ( 3 , duanma[max_temperature/10%10] );
  517. break;
  518. case 3 :
  519. state_SMG ( 4 , duanma[16] );
  520. break;
  521. case 4 :
  522. state_SMG ( 5 , duanma[average_temperature/100] );
  523. break;
  524. case 5 :
  525. state_SMG ( 6 , duanma_dot[average_temperature/10%10] );
  526. break;
  527. case 6 :
  528. state_SMG ( 7 , duanma[average_temperature%10] );
  529. break;
  530. case 7 :
  531. state_SMG_all ( 0xff );
  532. break;
  533. }
  534. }
  535. }
  536. else if ( SMG_flag == 3 )
  537. {
  538. if ( trg_count == 0 )
  539. {
  540. state_SMG ( 0 , duanma[18] );
  541. }
  542. else
  543. {
  544. switch ( flash_count )
  545. {
  546. case 0 :
  547. state_SMG ( 0 , duanma[18] );
  548. break;
  549. case 1 :
  550. state_SMG ( 2 , duanma[max_humidity/100] );
  551. break;
  552. case 2 :
  553. state_SMG ( 3 , duanma[max_humidity/10%10] );
  554. break;
  555. case 3 :
  556. state_SMG ( 4 , duanma[16] );
  557. break;
  558. case 4 :
  559. state_SMG ( 5 , duanma[average_humidity/100] );
  560. break;
  561. case 5 :
  562. state_SMG ( 6 , duanma_dot[average_humidity/10%10] );
  563. break;
  564. case 6 :
  565. state_SMG ( 7 , duanma[average_humidity%10] );
  566. break;
  567. case 7 :
  568. state_SMG_all ( 0xff );
  569. break;
  570. }
  571. }
  572. }
  573. else if ( SMG_flag == 4 )
  574. {
  575. switch ( flash_count )
  576. {
  577. case 0 :
  578. state_SMG ( 0 , duanma[15] );
  579. break;
  580. case 1 :
  581. state_SMG ( 1 , duanma[trg_count/10] );
  582. break;
  583. case 2 :
  584. state_SMG ( 2 , duanma[trg_count%10] );
  585. break;
  586. case 3 :
  587. if ( trg_count != 0 )
  588. {
  589. state_SMG ( 3, duanma[trg_time_hour/16] );
  590. }
  591. else
  592. {
  593. state_SMG ( 3, 0xff );
  594. }
  595. break;
  596. case 4 :
  597. if ( trg_count != 0 )
  598. {
  599. state_SMG ( 4 , duanma[trg_time_hour%16] );
  600. }
  601. else
  602. {
  603. state_SMG ( 4, 0xff );
  604. }
  605. break;
  606. case 5 :
  607. if ( trg_count != 0 )
  608. {
  609. state_SMG ( 5 , duanma[16] );
  610. }
  611. else
  612. {
  613. state_SMG ( 5, 0xff );
  614. }
  615. break;
  616. case 6 :
  617. if ( trg_count != 0 )
  618. {
  619. state_SMG ( 6 , duanma[trg_time_min/16] );
  620. }
  621. else
  622. {
  623. state_SMG ( 6, 0xff );
  624. }
  625. break;
  626. case 7 :
  627. if ( trg_count != 0 )
  628. {
  629. state_SMG ( 7 , duanma[trg_time_min%16] );
  630. }
  631. else
  632. {
  633. state_SMG ( 7, 0xff );
  634. }
  635. break;
  636. case 8 :
  637. // state_SMG_all ( 0xff );
  638. break;
  639. }
  640. }
  641. else if ( SMG_flag == 5 )
  642. {
  643. switch ( flash_count )
  644. {
  645. case 0 :
  646. state_SMG ( 0 , duanma[15] );
  647. break;
  648. case 1 :
  649. state_SMG ( 6 , duanma[set_temperature/100] );
  650. break;
  651. case 2 :
  652. state_SMG ( 7 , duanma[set_temperature/10%10] );
  653. break;
  654. case 3 :
  655. state_SMG_all ( 0xff );
  656. break;
  657. }
  658. }
  659. else if ( SMG_flag == 6 )
  660. {
  661. switch ( flash_count )
  662. {
  663. case 0 :
  664. state_SMG ( 0 , duanma[14] );
  665. break;
  666. case 1 :
  667. if ( temperature == 0 )
  668. {
  669. state_SMG ( 3 , duanma[10] );
  670. }
  671. else
  672. {
  673. state_SMG ( 3 , duanma[temperature/100] );
  674. }
  675. break;
  676. case 2 :
  677. state_SMG ( 4 , duanma[temperature/10%10] );
  678. break;
  679. case 3 :
  680. state_SMG ( 5 , duanma[16] );
  681. break;
  682. case 4 :
  683. if ( humidity == 0 )
  684. {
  685. state_SMG ( 6 , duanma[10] );
  686. }
  687. else
  688. {
  689. state_SMG ( 6 , duanma[humidity/100] );
  690. }
  691. break;
  692. case 5 :
  693. if ( humidity == 0 )
  694. {
  695. state_SMG ( 7 , duanma[10] );
  696. }
  697. else
  698. {
  699. state_SMG ( 7 , duanma[humidity/10%10] );
  700. }
  701. break;
  702. case 6 :
  703. state_SMG_all ( 0xff );
  704. break;
  705. }
  706. }
  707. }
  708. void main ()
  709. {
  710. init_sys();
  711. init_timer01 ();
  712. init_ds1302 ();
  713. init_temperature ();
  714. state_led ( 0xff );
  715. while ( 1 )
  716. {
  717. keyrunning ();
  718. rd1running ();
  719. flash_date ();
  720. valuerunning ();
  721. flash_temperature ();
  722. }
  723. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/706078
推荐阅读
相关标签
  

闽ICP备14008679号