找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6257|回复: 8
收起左侧

基于Atmega8的温度测控系统设计_电路图+程序+仿真+资料

[复制链接]
ID:159015 发表于 2017-2-18 09:27 | 显示全部楼层 |阅读模式
该设计为本人在校期间的综合设计项目,经过调试与测试。附件包含电路图、程序、仿真及相关资料。
1系统设计要求
用单片机开发一个温度测量控制系统,显示用16*2的液晶,实时显示测量温度,加热输出采用PWM控制,用发光二极管来模拟,能设置目标温度,能设置报警温度阈值,超过了进行报警,报警采用液晶屏幕显示。
2系统设计总体方案
本系统由单片机、按键、液晶显示和外围加热电路等部分组成,这里用发光二极管来模拟。对温度进行实时采集并通过程序设定最高温度、最低温度,采集到的实时温度通过串口向单片机进行传输,最后将测得的结果发送到液晶,实时显示测量温度。该系统对所测得的温度值进行分析,当温度高于或者低于设定的温度阈值时自动报警,并控制加热设备,以达到对温度智能控制,从而使环境温度维持在设定的有利温度范围内。

图片1.png
proteus仿真原理图:
0.png

pcb: PCB图.jpg

原理图:
原理图 .jpg

0.png

所有资料下载:
综合设计.rar (17.23 MB, 下载次数: 95)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:1 发表于 2017-2-18 16:43 | 显示全部楼层
下面是楼主的主程序:
  1. /*****************************************************
  2. This program was produced by the
  3. CodeWizardAVR V2.05.0 Professional
  4. Automatic Program Generator
  5. ?Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.

  6. Project :
  7. Version :
  8. Author  : NeVaDa
  9. Company :
  10. Comments:


  11. Chip type               : ATmega48
  12. AVR Core Clock frequency: 8.000000 MHz
  13. Memory model            : Small
  14. External RAM size       : 0
  15. Data Stack size         : 128
  16. *****************************************************/

  17. #include <mega48.h>

  18. #include <delay.h>

  19. // DS18b20 Temperature Sensor functions
  20. #include <ds18b20.h>

  21. // Alphanumeric LCD Module functions
  22. #include <alcd.h>

  23. #define ADC_VREF_TYPE 0x60

  24. #define Temp_Set_Key_Not_Pressed  PIND.6
  25. #define Alarm_Set_Key_Not_Pressed PIND.7

  26. // Read the 8 most significant bits
  27. // of the AD conversion result
  28. unsigned char read_adc(unsigned char adc_input)
  29. {
  30. ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
  31. // Delay needed for the stabilization of the ADC input voltage
  32. delay_us(10);
  33. // Start the AD conversion
  34. ADCSRA|=0x40;
  35. // Wait for the AD conversion to complete
  36. while ((ADCSRA & 0x10)==0);
  37. ADCSRA|=0x10;
  38. return ADCH;
  39. }

  40. // Declare your global variables here

  41. unsigned char Char_Array[3];
  42. unsigned char AD_Value=0;
  43. int  Temprature;
  44. float  Temp;
  45. unsigned char Temp_Set_Value=20;
  46. unsigned char Alarm_Set_Value=80;

  47. void HEX_To_AscII(int data,unsigned char *P)
  48. {
  49.   P[2]=(data/100)+0x30;
  50.   P[1]=((data%100)/10)+0x30;
  51.   P[0]=(data%10)+0x30;
  52. }

  53. void main(void)
  54. {
  55. // Declare your local variables here

  56. // Crystal Oscillator division factor: 1
  57. #pragma optsize-
  58. CLKPR=0x80;
  59. CLKPR=0x00;
  60. #ifdef _OPTIMIZE_SIZE_
  61. #pragma optsize+
  62. #endif

  63. // Input/Output Ports initialization
  64. // Port B initialization
  65. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=In
  66. // State7=T State6=T State5=T State4=T State3=T State2=1 State1=1 State0=T
  67. PORTB=0x06;
  68. DDRB=0x06;

  69. // Port C initialization
  70. // Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In
  71. // State6=T State5=1 State4=1 State3=1 State2=1 State1=1 State0=T
  72. PORTC=0x3E;
  73. DDRC=0x3E;

  74. // Port D initialization
  75. // Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=In Func1=In Func0=In
  76. // State7=P State6=P State5=T State4=T State3=1 State2=T State1=T State0=T
  77. PORTD=0xC8;
  78. DDRD=0x08;

  79. // Timer/Counter 0 initialization
  80. // Clock source: System Clock
  81. // Clock value: Timer 0 Stopped
  82. // Mode: Normal top=0xFF
  83. // OC0A output: Disconnected
  84. // OC0B output: Disconnected
  85. TCCR0A=0x00;
  86. TCCR0B=0x00;
  87. TCNT0=0x00;
  88. OCR0A=0x00;
  89. OCR0B=0x00;

  90. // Timer/Counter 1 initialization
  91. // Clock source: System Clock
  92. // Clock value: Timer1 Stopped
  93. // Mode: Normal top=0xFFFF
  94. // OC1A output: Discon.
  95. // OC1B output: Discon.
  96. // Noise Canceler: Off
  97. // Input Capture on Falling Edge
  98. // Timer1 Overflow Interrupt: Off
  99. // Input Capture Interrupt: Off
  100. // Compare A Match Interrupt: Off
  101. // Compare B Match Interrupt: Off
  102. TCCR1A=0x00;
  103. TCCR1B=0x00;
  104. TCNT1H=0x00;
  105. TCNT1L=0x00;
  106. ICR1H=0x00;
  107. ICR1L=0x00;
  108. OCR1AH=0x00;
  109. OCR1AL=0x00;
  110. OCR1BH=0x00;
  111. OCR1BL=0x00;

  112. // Timer/Counter 2 initialization
  113. // Clock source: System Clock
  114. // Clock value: 250.000 kHz
  115. // Mode: Fast PWM top=0xFF
  116. // OC2A output: Disconnected
  117. // OC2B output: Inverted PWM
  118. ASSR=0x00;
  119. TCCR2A=0x33;
  120. TCCR2B=0x03;
  121. TCNT2=0x00;
  122. OCR2A=0x00;
  123. OCR2B=0x00;

  124. // External Interrupt(s) initialization
  125. // INT0: Off
  126. // INT1: Off
  127. // Interrupt on any change on pins PCINT0-7: Off
  128. // Interrupt on any change on pins PCINT8-14: Off
  129. // Interrupt on any change on pins PCINT16-23: Off
  130. EICRA=0x00;
  131. EIMSK=0x00;
  132. PCICR=0x00;

  133. // Timer/Counter 0 Interrupt(s) initialization
  134. TIMSK0=0x00;

  135. // Timer/Counter 1 Interrupt(s) initialization
  136. TIMSK1=0x00;

  137. // Timer/Counter 2 Interrupt(s) initialization
  138. TIMSK2=0x00;

  139. // USART initialization
  140. // USART disabled
  141. UCSR0B=0x00;

  142. // Analog Comparator initialization
  143. // Analog Comparator: Off
  144. // Analog Comparator Input Capture by Timer/Counter 1: Off
  145. ACSR=0x80;
  146. ADCSRB=0x00;
  147. DIDR1=0x00;

  148. // ADC initialization
  149. // ADC Clock frequency: 250.000 kHz
  150. // ADC Voltage Reference: AVCC pin
  151. // ADC Auto Trigger Source: ADC Stopped
  152. // Only the 8 most significant bits of
  153. // the AD conversion result are used
  154. // Digital input buffers on ADC0: Off, ADC1: On, ADC2: On, ADC3: On
  155. // ADC4: On, ADC5: On
  156. DIDR0=0x01;
  157. ADMUX=ADC_VREF_TYPE & 0xff;
  158. ADCSRA=0x85;

  159. // SPI initialization
  160. // SPI disabled
  161. SPCR=0x00;

  162. // TWI initialization
  163. // TWI disabled
  164. TWCR=0x00;

  165. // 1 Wire Bus initialization
  166. // 1 Wire Data port: PORTB
  167. // 1 Wire Data bit: 0
  168. // Note: 1 Wire port settings must be specified in the
  169. // Project|Configure|C Compiler|Libraries|1 Wire IDE menu.
  170. //w1_init();


  171. // Alphanumeric LCD initialization
  172. // Connections specified in the
  173. // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
  174. // RS - PORTB Bit 1
  175. // RD - PORTB Bit 2
  176. // EN - PORTC Bit 1
  177. // D4 - PORTC Bit 2
  178. // D5 - PORTC Bit 3
  179. // D6 - PORTC Bit 4
  180. // D7 - PORTC Bit 5
  181. // Characters/line: 16
  182. lcd_init(16);

  183. lcd_gotoxy(0, 0);
  184. lcd_puts("NBUT");
  185. lcd_gotoxy(0, 1);
  186. if(ds18b20_init(0,-60,80,DS18B20_9BIT_RES))
  187.   lcd_puts("OK!");
  188. else
  189.   lcd_puts("FAULT!");
  190. delay_ms(1000);
  191. lcd_gotoxy(0, 0);
  192. lcd_puts("Temp:");
  193. lcd_gotoxy(0,1);
  194. lcd_puts("AD:");

  195. lcd_gotoxy(8, 1);
  196. lcd_puts("ALM:");
  197. HEX_To_AscII(Alarm_Set_Value,Char_Array);  
  198. lcd_putchar(Char_Array[1]);  
  199. lcd_putchar(Char_Array[0]);
  200. lcd_putchar('C');


  201. while (1)
  202.       {
  203.       // Place your code here
  204.          //温度读取
  205.          Temp=ds18b20_temperature(0);
  206.          
  207.          //加热处理
  208.         if((int)Temp>Temp_Set_Value)
  209.            OCR2B=0;
  210.          else
  211.            OCR2B=AD_Value;  
  212.            //OCR2B=255;  
  213.          
  214.          //报警处理
  215.          lcd_gotoxy(12, 0);
  216.          if(Temp>Alarm_Set_Value)
  217.            lcd_puts("ALM!");
  218.          else
  219.            lcd_puts("    ");
  220.          
  221.          
  222.          //温度显示   
  223.          Temprature=Temp*10;
  224.          //delay_ms(10);
  225.          lcd_gotoxy(5, 0);
  226.          if(Temprature<0)
  227.          {
  228.            Temprature=-Temprature;
  229.            lcd_putchar('-');
  230.          }
  231.          else  
  232.            lcd_putchar('+');
  233.            
  234.          HEX_To_AscII(Temprature,Char_Array);
  235.            
  236.          lcd_putchar(Char_Array[2]);
  237.          lcd_putchar(Char_Array[1]);
  238.          lcd_putchar('.');
  239.          lcd_putchar(Char_Array[0]);
  240.          lcd_putchar('C');
  241.          
  242.          //ad转换处理
  243.          AD_Value=read_adc(0);
  244.          Temprature=(AD_Value*10)/51;
  245.          HEX_To_AscII(Temprature,Char_Array);
  246.          lcd_gotoxy(3,1);
  247.          //lcd_putchar(Char_Array[2]);
  248.          lcd_putchar(Char_Array[1]);  
  249.          lcd_putchar('.');
  250.          lcd_putchar(Char_Array[0]);
  251.          lcd_putchar('V');  
  252.          
  253.          //温度设置按键处理
  254.          if(!Temp_Set_Key_Not_Pressed)
  255.          {
  256.            delay_ms(10);
  257.            if(!Temp_Set_Key_Not_Pressed)
  258.            {
  259.              Temp_Set_Value++;
  260.              if(Temp_Set_Value>20)
  261.                Temp_Set_Value=0;
  262.              lcd_gotoxy(5, 0);
  263.              HEX_To_AscII(Temp_Set_Value,Char_Array);  
  264.              lcd_putchar(Char_Array[1]);  
  265.              lcd_putchar(Char_Array[0]);
  266.              lcd_putchar('C');
  267.              lcd_puts("   ");
  268.              delay_ms(500);
  269.            }
  270.          }
  271.               
  272.          //温度报警设置按键处理
  273.          if(!Alarm_Set_Key_Not_Pressed)
  274.          {
  275.            delay_ms(10);
  276.            if(!Alarm_Set_Key_Not_Pressed)
  277.            {
  278.              Alarm_Set_Value++;
  279.              if(Alarm_Set_Value>20)
  280.                Alarm_Set_Value=0;
  281.              lcd_gotoxy(12, 1);
  282.              HEX_To_AscII(Alarm_Set_Value,Char_Array);  
  283.              lcd_putchar(Char_Array[1]);  
  284.              lcd_putchar(Char_Array[0]);
  285.              lcd_putchar('C');
  286.              delay_ms(500);
  287.            }
  288.          }
  289.       }
  290. }
复制代码
回复

使用道具 举报

ID:165840 发表于 2017-2-21 21:52 | 显示全部楼层
不错哦,能开源。值得学习。
回复

使用道具 举报

ID:334441 发表于 2018-9-12 11:32 | 显示全部楼层
怎么只有主程序的c文件
回复

使用道具 举报

ID:334441 发表于 2018-9-12 11:34 | 显示全部楼层
有没有其他的c文件和h文件
回复

使用道具 举报

ID:396939 发表于 2018-9-12 12:29 | 显示全部楼层
只有一个主程序吗
回复

使用道具 举报

ID:334441 发表于 2018-9-13 16:41 | 显示全部楼层
BaGas 发表于 2018-9-12 12:29
只有一个主程序吗

是的
回复

使用道具 举报

ID:358464 发表于 2018-9-21 12:31 | 显示全部楼层
感谢分享
回复

使用道具 举报

ID:358464 发表于 2018-9-21 12:32 | 显示全部楼层
pcb和原理图的文件没有啊?
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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