当前位置:   article > 正文

蓝桥杯-单片机组基础21——第15届省赛代码_十五届蓝桥杯单片机省赛答案

十五届蓝桥杯单片机省赛答案

目录

0.比赛题目回忆

1. 底层头文件

2.底层文件

3.主函数文件


做下来感觉,主观题第15届比14届稍微简单一些,但是出其不意考了DAC

本届客观题有点难,做选择感觉把握性不大,多选比较多

万幸比赛前一天做出了第14届的题,今年的题和去年的题比较接近(可参考本专栏上一篇文章)

如果有幸进入国赛,将继续更新国赛之路专栏

0.比赛题目回忆

(请以官方的文档为准,可能回忆有误):

配置为IO模式,矩阵键盘操作S4589,短接P34和SIGNAL,

除了ds1302的时间显示界面,其余界面数值高位为0时,直接熄灭

采集555定时计数器频率,与频率参数相加后成为最终频率值,并将其中500~pf之间的频率映射到1~5V的DAC输出。(pf为超限频率)

当频率超出pf时,led2间隔0.2s闪烁。当频率为负数时,led2常亮

共有6个数码管显示界面,分别为:

  1. F频率采集界面,F__频率数值。该状态下led1间隔0.2s闪烁。当采集到的频率为负时,显示LL
  2. P1超限频率pf设置界面,默认参数2000,按下S9减少1000,按下S8增加1000,范围为1000~9000
  3. P2频率参数设置界面,默认参数0,按下S9减少100,按下S8增加100,范围为-900~900。其中负数时要有符号显示,为0时只显示最后一位0和提示符P2,其他位熄灭
  4. 时间显示界面,显示格式:时时-分分-秒秒
  5. HF频率回显,显示采集到的最大频率数值
  6. HA时间回显,显示采集到最大频率时的时间,格式为:HA时时分分秒秒

按键切换逻辑为:

按下S4,切换逻辑为:1 - 23 - 4 - 56 -1

按下S5,切换逻辑为:2 - 3 或 5 - 6

比赛结束后复现代码如下:

1. 底层头文件

iic.h

  1. #ifndef __IIC_H__
  2. #define __IIC_H__
  3. void I2CStart(void);
  4. void I2CStop(void);
  5. void I2CSendByte(unsigned char byt);
  6. unsigned char I2CWaitAck(void);
  7. #endif

ds1302.h

  1. #ifndef __DS1302_H__
  2. #define __DS1302_H__
  3. void Write_Ds1302(unsigned char temp) ;
  4. void Write_Ds1302_Byte( unsigned char address,unsigned char dat ) ;
  5. unsigned char Read_Ds1302_Byte ( unsigned char address );
  6. #endif

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_led ( unsigned char value_led );
  7. void init_sys ();
  8. #endif

2.底层文件

iic.c

  1. /* # I2C代码片段说明
  2. 1. 本文件夹中提供的驱动代码供参赛选手完成程序设计参考。
  3. 2. 参赛选手可以自行编写相关代码或以该代码为基础,根据所选单片机类型、运行速度和试题
  4. 中对单片机时钟频率的要求,进行代码调试和修改。
  5. */
  6. #include <reg52.h>
  7. #include <intrins.h>
  8. sbit sda = P2^1;
  9. sbit scl = P2^0;
  10. #define DELAY_TIME 5
  11. //
  12. static void I2C_Delay(unsigned char n)
  13. {
  14. do
  15. {
  16. _nop_();_nop_();_nop_();_nop_();_nop_();
  17. _nop_();_nop_();_nop_();_nop_();_nop_();
  18. _nop_();_nop_();_nop_();_nop_();_nop_();
  19. }
  20. while(n--);
  21. }
  22. //
  23. void I2CStart(void)
  24. {
  25. sda = 1;
  26. scl = 1;
  27. I2C_Delay(DELAY_TIME);
  28. sda = 0;
  29. I2C_Delay(DELAY_TIME);
  30. scl = 0;
  31. }
  32. //
  33. void I2CStop(void)
  34. {
  35. sda = 0;
  36. scl = 1;
  37. I2C_Delay(DELAY_TIME);
  38. sda = 1;
  39. I2C_Delay(DELAY_TIME);
  40. }
  41. //
  42. void I2CSendByte(unsigned char byt)
  43. {
  44. unsigned char i;
  45. for(i=0; i<8; i++){
  46. scl = 0;
  47. I2C_Delay(DELAY_TIME);
  48. if(byt & 0x80){
  49. sda = 1;
  50. }
  51. else{
  52. sda = 0;
  53. }
  54. I2C_Delay(DELAY_TIME);
  55. scl = 1;
  56. byt <<= 1;
  57. I2C_Delay(DELAY_TIME);
  58. }
  59. scl = 0;
  60. }
  61. /*
  62. unsigned char I2CReceiveByte(void)
  63. {
  64. unsigned char da;
  65. unsigned char i;
  66. for(i=0;i<8;i++){
  67. scl = 1;
  68. I2C_Delay(DELAY_TIME);
  69. da <<= 1;
  70. if(sda)
  71. da |= 0x01;
  72. scl = 0;
  73. I2C_Delay(DELAY_TIME);
  74. }
  75. return da;
  76. }
  77. */
  78. unsigned char I2CWaitAck(void)
  79. {
  80. unsigned char ackbit;
  81. scl = 1;
  82. I2C_Delay(DELAY_TIME);
  83. ackbit = sda;
  84. scl = 0;
  85. I2C_Delay(DELAY_TIME);
  86. return ackbit;
  87. }
  88. /*/
  89. void I2CSendAck(unsigned char ackbit)
  90. {
  91. scl = 0;
  92. sda = ackbit;
  93. I2C_Delay(DELAY_TIME);
  94. scl = 1;
  95. I2C_Delay(DELAY_TIME);
  96. scl = 0;
  97. sda = 1;
  98. I2C_Delay(DELAY_TIME);
  99. }
  100. */

ds1302.c

  1. /* # DS1302代码片段说明
  2. 1. 本文件夹中提供的驱动代码供参赛选手完成程序设计参考。
  3. 2. 参赛选手可以自行编写相关代码或以该代码为基础,根据所选单片机类型、运行速度和试题
  4. 中对单片机时钟频率的要求,进行代码调试和修改。
  5. */
  6. //
  7. #include <reg52.h>
  8. #include <intrins.h>
  9. sbit SCK = P1^7;
  10. sbit SDA = P2^3;
  11. sbit RST = P1^3;
  12. void Write_Ds1302(unsigned char temp)
  13. {
  14. unsigned char i;
  15. for (i=0;i<8;i++)
  16. {
  17. SCK = 0;
  18. SDA = temp&0x01;
  19. temp>>=1;
  20. SCK=1;
  21. }
  22. }
  23. //
  24. void Write_Ds1302_Byte( unsigned char address,unsigned char dat )
  25. {
  26. RST=0; _nop_();
  27. SCK=0; _nop_();
  28. RST=1; _nop_();
  29. Write_Ds1302(address);
  30. Write_Ds1302(dat);
  31. RST=0;
  32. }
  33. //
  34. unsigned char Read_Ds1302_Byte ( unsigned char address )
  35. {
  36. unsigned char i,temp=0x00;
  37. RST=0; _nop_();
  38. SCK=0; _nop_();
  39. RST=1; _nop_();
  40. Write_Ds1302(address);
  41. for (i=0;i<8;i++)
  42. {
  43. SCK=0;
  44. temp>>=1;
  45. if(SDA)
  46. temp|=0x80;
  47. SCK=1;
  48. }
  49. RST=0; _nop_();
  50. SCK=0; _nop_();
  51. SCK=1; _nop_();
  52. SDA=0; _nop_();
  53. SDA=1; _nop_();
  54. return (temp);
  55. }

basecode.c

  1. #include <reg52.h>
  2. #include <intrins.h>
  3. void select_HC573 ( unsigned char channal )
  4. {
  5. switch ( channal )
  6. {
  7. case 4:
  8. P2 = ( P2 & 0x1f ) | 0x80;
  9. break;
  10. case 5:
  11. P2 = ( P2 & 0x1f ) | 0xa0;
  12. break;
  13. case 6:
  14. P2 = ( P2 & 0x1f ) | 0xc0;
  15. break;
  16. case 7:
  17. P2 = ( P2 & 0x1f ) | 0xe0;
  18. break;
  19. case 0:
  20. P2 = ( P2 & 0x1f ) | 0x00;
  21. break;
  22. }
  23. }
  24. void state_SMG ( unsigned char pos_SMG , unsigned char value_SMG )
  25. {
  26. select_HC573 ( 0 );
  27. P0 = 0x01 << pos_SMG;
  28. select_HC573( 6 );
  29. select_HC573 ( 0 );
  30. P0 = value_SMG;
  31. select_HC573( 7 );
  32. select_HC573 ( 0 );
  33. }
  34. void state_SMG_all ( unsigned char value_SMG_all )
  35. {
  36. select_HC573 ( 0 );
  37. P0 = 0xff;
  38. select_HC573( 6 );
  39. select_HC573 ( 0 );
  40. P0 = value_SMG_all;
  41. select_HC573( 7 );
  42. select_HC573 ( 0 );
  43. }
  44. void state_led ( unsigned char value_led )
  45. {
  46. select_HC573 ( 0 );
  47. P0 = 0xff;
  48. select_HC573 ( 4 );
  49. P0 = value_led;
  50. select_HC573 ( 4 );
  51. select_HC573 ( 0 );
  52. }
  53. void init_sys ()
  54. {
  55. select_HC573 ( 0 );
  56. P0 = 0xff;
  57. select_HC573 ( 4 );
  58. select_HC573 ( 0 );
  59. P0 = 0x00;
  60. select_HC573 ( 5 );
  61. select_HC573 ( 0 );
  62. }

3.主函数文件

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

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

闽ICP备14008679号