当前位置:   article > 正文

蓝桥杯单片机省赛题目《全集》之第十二届省赛第一场_蓝桥杯第十二届eda真题

蓝桥杯第十二届eda真题

师从小蜜蜂,简单易懂,很容易看懂,可以交流提意见。

这道题难度正常,感觉今年的题难度大概就都会这样了,不会再难了

这里的读取eeprom内容,我任务第一次读取的时候,可能会出现随机的内容,所以可以对第一次读取的内容进行个修整,到规范的内容。

 

 

 

  1. #include "reg52.h"
  2. #include "onewire.h"
  3. #include "iic.h"
  4. sfr P4 = 0xC0;
  5. sbit r1=P3^0;
  6. sbit r2=P3^1;
  7. sbit r3=P3^2;
  8. sbit r4=P3^3;
  9. sbit c1=P4^4;
  10. sbit c2=P4^2;
  11. sbit c3=P3^5;
  12. sbit c4=P3^4;
  13. typedef unsigned char u8;
  14. typedef unsigned int u16;
  15. u8 code duanma[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
  16. u8 code duanma1[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
  17. u8 mode=1;
  18. void display_choose();
  19. void delay(u8 t)
  20. {while(t--);}
  21. void delay1(u8 t)
  22. {while(t--);display_choose();}
  23. void hc573(u8 n)
  24. {
  25. switch(n)
  26. {
  27. case 4:P2=(P2&0x1f)|0x80;break;
  28. case 5:P2=(P2&0x1f)|0xa0;break;
  29. case 6:P2=(P2&0x1f)|0xc0;break;
  30. case 7:P2=(P2&0x1f)|0xe0;break;
  31. case 0:P2=(P2&0x1f)|0x00;break;
  32. }
  33. }
  34. void first()
  35. {
  36. hc573(4);
  37. P0=0xff;
  38. hc573(5);
  39. P0=0x00;
  40. hc573(6);
  41. P0=0x00;
  42. hc573(7);
  43. P0=0xff;
  44. }
  45. u16 temp=2000;
  46. void read_wendu()
  47. {
  48. u8 L,M;
  49. init_ds18b20();
  50. Write_DS18B20(0xcc);
  51. Write_DS18B20(0x44);
  52. delay(1000);
  53. init_ds18b20();
  54. Write_DS18B20(0xcc);
  55. Write_DS18B20(0xbe);
  56. L=Read_DS18B20();
  57. M=Read_DS18B20();
  58. temp=(M<<8)|L;
  59. if((temp&0xf800)==0x0000)//*
  60. {
  61. //temp=(temp>>4)+(L&0x0f)*0.0625;//整型这样做会丢失小数
  62. temp = (temp>>4) * 100;
  63. temp = temp + (L & 0x0f) * 6.25;
  64. }
  65. //temp=100*temp;
  66. }
  67. u16 ain3=0;
  68. /*
  69. void pcf_adc()
  70. {
  71. IIC_Start();
  72. IIC_SendByte(0x90);
  73. IIC_WaitAck();
  74. IIC_SendByye(0x03);
  75. IIC_WaitAck();
  76. IIC_Stop();
  77. IIC_Start();
  78. IIC_SendByte(0x91);
  79. IIC_WaitAck();
  80. ain3=IIC_RecByte();
  81. IIC_SendAck(1);
  82. IIC_Stop();
  83. ain3=ain3*(500/256);
  84. }*/
  85. void pcf_dac(u8 dat)
  86. {
  87. IIC_Start();
  88. IIC_SendByte(0x90);
  89. IIC_WaitAck();
  90. IIC_SendByte(0x40);
  91. IIC_WaitAck();
  92. IIC_SendByte(dat);
  93. IIC_WaitAck();
  94. IIC_Stop();
  95. }
  96. void display(u8 pos,u8 dat)
  97. {
  98. hc573(7);///xiaoyin
  99. P0=0xff;///
  100. hc573(6);
  101. P0=0x01<<pos;
  102. hc573(7);
  103. P0=dat;
  104. }
  105. u8 display_stat=1;
  106. void displayoff()
  107. {
  108. hc573(6);
  109. P0=0x00;
  110. hc573(7);
  111. P0=0xff;
  112. }
  113. void display_1()
  114. {
  115. P0=0xff;
  116. display(7,duanma[temp%10]);
  117. delay(500);
  118. display(6,duanma[(temp%100)/10]);
  119. delay(500);
  120. display(5,duanma1[(temp%1000)/100]);
  121. delay(500);
  122. display(4,duanma[(temp%10000)/1000]);
  123. delay(500);
  124. display(3,0xff);
  125. delay(500);
  126. display(2,0xff);
  127. delay(500);
  128. display(1,0xff);
  129. delay(500);
  130. display(0,0xc6);
  131. delay(500);
  132. displayoff();
  133. }
  134. u16 set=25;
  135. void display_2()
  136. {
  137. P0=0xff;
  138. display(7,duanma[set%10]);
  139. delay(500);
  140. display(6,duanma[(set%100)/10]);
  141. delay(500);
  142. display(5,0xff);
  143. delay(500);
  144. display(4,0xff);
  145. delay(500);
  146. display(3,0xff);
  147. delay(500);
  148. display(2,0xff);
  149. delay(500);
  150. display(1,0xff);
  151. delay(500);
  152. display(0,0x8e);
  153. delay(500);
  154. displayoff();
  155. }
  156. void display_3()
  157. {
  158. P0=0xff;
  159. display(7,duanma[ain3%10]);
  160. delay(500);
  161. display(6,duanma[(ain3%100)/10]);
  162. delay(500);
  163. display(5,duanma1[(ain3%1000)/100]);
  164. delay(500);
  165. display(4,0xff);
  166. delay(500);
  167. display(3,0xff);
  168. delay(500);
  169. display(2,0xff);
  170. delay(500);
  171. display(1,0xff);
  172. delay(500);
  173. display(0,0x88);
  174. delay(500);
  175. displayoff();
  176. }
  177. u8 led_stat=0xff;
  178. void led()
  179. {
  180. P0=0xff;
  181. hc573(4);
  182. if(mode==1){led_stat=led_stat&0xfe;}
  183. else{led_stat=led_stat|0x01;}
  184. if(display_stat==1){led_stat=led_stat&0xfd;}
  185. else{led_stat=led_stat|0x02;}
  186. if(display_stat==2){led_stat=led_stat&0xfb;}
  187. else{led_stat=led_stat|0x04;}
  188. if(display_stat==3){led_stat=led_stat&0xf7;}
  189. else{led_stat=led_stat|0x08;}
  190. P0=led_stat;
  191. hc573(0);
  192. }
  193. void display_choose()
  194. {
  195. if(display_stat==1){display_1();}
  196. else if(display_stat==2){display_2();}
  197. else if(display_stat==3){display_3();}
  198. led();
  199. }
  200. void scan()
  201. {
  202. r4=0;//s4
  203. r1=r2=r3=1;
  204. if(c1==0)
  205. {
  206. delay(100);
  207. if(c1==0)
  208. {
  209. display_stat=display_stat+1;
  210. if(display_stat==4){display_stat=1;}
  211. }
  212. while(c1==0)
  213. {
  214. display_choose();
  215. }
  216. }
  217. if(c2==0)//s8
  218. {
  219. delay(100);
  220. if(c2==0)
  221. {if(display_stat==2){
  222. if(set>=10)
  223. {set=set-1;}
  224. else if(set<10)
  225. {set=0;}
  226. }
  227. }
  228. while(c2==0)
  229. {
  230. display_choose();
  231. }
  232. }
  233. r3=0;//s4
  234. r1=r2=r4=1;
  235. if(c1==0)//s5
  236. {
  237. delay(100);
  238. if(c1==0)
  239. {
  240. mode=~mode;
  241. }
  242. while(c1==0)
  243. {
  244. display_choose();
  245. }
  246. }
  247. if(c2==0)//s9
  248. {
  249. delay(100);
  250. if(c2==0)
  251. { if(display_stat==2){
  252. set=set+1;}
  253. }
  254. while(c2==0)
  255. {display_choose();}
  256. }
  257. }
  258. void mode_choose()
  259. {
  260. if(mode==1)
  261. {
  262. if(temp<(set*100))
  263. {ain3=0;}
  264. else{ain3=500;}
  265. }
  266. else
  267. {
  268. if (temp <= 2000)
  269. {
  270. ain3 = 100;
  271. }
  272. else if ((temp < 4000) & (temp > 2000))
  273. {
  274. ain3 = ((temp - 2000) * (3 / 20) + 100);//整型这样算会丢失小数
  275. ain3 = ((temp - 2000) * 3) / 20 + 100;
  276. }
  277. else{ain3=400;}
  278. }
  279. }
  280. u8 cnt = 0;
  281. void main()
  282. {
  283. first();
  284. while(1)
  285. {
  286. cnt++;
  287. if (cnt % 5 == 0)
  288. //pcf_adc();
  289. {
  290. read_wendu();
  291. }
  292. if (cnt % 4 == 0)
  293. {
  294. pcf_dac(ain3 * (255 / 500));
  295. }
  296. scan();
  297. mode_choose();
  298. display_choose();
  299. }
  300. }

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

闽ICP备14008679号