找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3235|回复: 0
收起左侧

数字温度计单片机课程设计

[复制链接]
ID:267967 发表于 2017-12-27 20:13 | 显示全部楼层 |阅读模式
0.png
单片机源程序如下:
  1. #include <AT89X52.h>
  2. #include "DS18B20.h"
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. #define SET P3_1
  6. #define DEC P3_2
  7. #define ADD P3_3
  8. #define        BEEP P3_7
  9. bit shanshuo_st;
  10. bit beep_st;
  11. sbit DIAN=P2^7;
  12. uchar x=0;
  13. signed char m;
  14. uchar n;
  15. uchar set_st=0;
  16. signed char shangxian=38;
  17. signed char        xiaxian=15;
  18. uchar code
  19. LEDDate[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
  20. void Delay (uint num)
  21. {
  22. while(--num);
  23. }
  24. void InitTimer(void)
  25. {
  26. TMOD=0x1;
  27. TH0=0x4c;
  28. TL0=0x00;
  29. }
  30. void timer0(void) interrupt 1
  31. {
  32. TH0=0x4c;
  33. TL0=0x00;
  34. x++;
  35. }
  36. void int0(void) interrupt 0
  37. {
  38. EX0=0;
  39. if (DEC        ==0&&set_st==1)
  40. {
  41. shangxian--;
  42. if(shangxian<xiaxian)shangxian=xiaxian;
  43. }
  44. else if(DEC==0&&set_st==2)  
  45. {
  46. xiaxian--;
  47. if (xiaxian<0)xiaxian==0;
  48. }
  49. }
  50. void int1(void) interrupt 2
  51. {         
  52. EX1=0;
  53. if(ADD==0&&set_st==1)
  54. {
  55. shangxian++;
  56. if(shangxian>99)shangxian=99;
  57. }
  58. else if(ADD==0&&set_st==2)
  59. {
  60. xiaxian++;
  61. if (xiaxian>shangxian)xiaxian=shangxian;
  62. }
  63. }
  64. void check_wendu(void)
  65. {
  66. uint a,b,c;
  67. c=ReadTemperature()-5;
  68. a=c/100;
  69. b=c/10-a*10;
  70. m=c/10;
  71. if(m<0){m=0;n=0;}
  72. if(m>99){m=99;n=9;}
  73. }
  74. Disp_init()
  75. {
  76. P2=0xbf;
  77. P1=0xfe;
  78. Delay(200);
  79. P2=0xbf;
  80. P1=0xfd;
  81. Delay(200);
  82. P2=0xbf;
  83. P1=0xfb;
  84. Delay(200);
  85. P2=0xbf;
  86. P1=0xf7;
  87. Delay(200);
  88. P1=0xff;
  89. }
  90. Disp_Temperature()
  91. {
  92. P2=0xc6;
  93. P1=0xf7;
  94. Delay(300);
  95. P2=LEDDate[n];
  96. P1=0xfb;
  97. Delay(300);
  98. P2=LEDDate[m/10];
  99. DIAN=0;
  100. P1=0xfd;
  101. Delay(300);
  102. P2=LEDDate[m/10];
  103. P1=0xfe;
  104. Delay(300);
  105. P1=0xff;
  106. }
  107. Disp_alarm(uchar baojing)
  108. {
  109. P2=0xc6;
  110. P1=0xf7;
  111. Delay(200);
  112. P2=LEDDate[baojing%10];
  113. P1=0xfb;
  114. Delay(200);
  115. if(set_st==1)P2=0x89;
  116. else if        (set_st==2)P2=0xc7;
  117. P1=0xfe;
  118. Delay(200);
  119. P1=0xff;
  120. }
  121. void Alarm()
  122. {
  123. if(x>=10){beep_st=~beep_st;x=0;}
  124. if((m>=shangxian&&beep_st==1)||(m<xiaxian&&beep_st==1))BEEP=0;
  125. else BEEP=1;
  126. }
  127. void main (void)
  128. {
  129. uint z;
  130. InitTimer();
  131. EA=1;
  132. TR0=1;
  133. ET0=1;
  134. IT0=1;
  135. IT1=1;
  136. check_wendu();
  137. check_wendu();
  138. for(z=0;z<300;z++)
  139. {
  140. Disp_init();
  141. }
  142. while(1)
  143. {
  144. if(SET==0)
  145. {
  146. Delay(2000);
  147. do{;}while(SET==0);
  148. set_st++;x=0;shanshuo_st=1;
  149. if (set_st>2)set_st=0;
  150. }
  151. if(set_st==0)
  152. {
  153. EX0=0;
  154. EX1=0;
  155. check_wendu();
  156. Disp_Temperature();
  157. Alarm();
  158. ……………………

  159. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
单片机课程设计(1).zip (71.91 KB, 下载次数: 17)


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表