標(biāo)題: 基于Atmega8的溫度測(cè)控系統(tǒng)設(shè)計(jì)_電路圖+程序+仿真+資料 [打印本頁(yè)]
作者: fjdksla 時(shí)間: 2017-2-18 09:27
標(biāo)題: 基于Atmega8的溫度測(cè)控系統(tǒng)設(shè)計(jì)_電路圖+程序+仿真+資料
該設(shè)計(jì)為本人在校期間的綜合設(shè)計(jì)項(xiàng)目,經(jīng)過調(diào)試與測(cè)試。附件包含電路圖、程序、仿真及相關(guān)資料。
1系統(tǒng)設(shè)計(jì)要求
用單片機(jī)開發(fā)一個(gè)溫度測(cè)量控制系統(tǒng),顯示用16*2的液晶,實(shí)時(shí)顯示測(cè)量溫度,加熱輸出采用PWM控制,用發(fā)光二極管來(lái)模擬,能設(shè)置目標(biāo)溫度,能設(shè)置報(bào)警溫度閾值,超過了進(jìn)行報(bào)警,報(bào)警采用液晶屏幕顯示。
2系統(tǒng)設(shè)計(jì)總體方案
本系統(tǒng)由單片機(jī)、按鍵、液晶顯示和外圍加熱電路等部分組成,這里用發(fā)光二極管來(lái)模擬。對(duì)溫度進(jìn)行實(shí)時(shí)采集并通過程序設(shè)定最高溫度、最低溫度,采集到的實(shí)時(shí)溫度通過串口向單片機(jī)進(jìn)行傳輸,最后將測(cè)得的結(jié)果發(fā)送到液晶,實(shí)時(shí)顯示測(cè)量溫度。該系統(tǒng)對(duì)所測(cè)得的溫度值進(jìn)行分析,當(dāng)溫度高于或者低于設(shè)定的溫度閾值時(shí)自動(dòng)報(bào)警,并控制加熱設(shè)備,以達(dá)到對(duì)溫度智能控制,從而使環(huán)境溫度維持在設(shè)定的有利溫度范圍內(nèi)。
圖片1.png (10.1 KB, 下載次數(shù): 114)
下載附件
2017-2-18 09:35 上傳
proteus仿真原理圖:
0.png (25.35 KB, 下載次數(shù): 113)
下載附件
2017-2-18 16:40 上傳
pcb:
PCB圖.jpg (41.25 KB, 下載次數(shù): 113)
下載附件
2017-2-18 16:40 上傳
原理圖:
原理圖 .jpg (61.65 KB, 下載次數(shù): 137)
下載附件
2017-2-18 16:40 上傳
0.png (63.25 KB, 下載次數(shù): 102)
下載附件
2017-2-18 16:41 上傳
所有資料下載:
綜合設(shè)計(jì).rar
(17.23 MB, 下載次數(shù): 98)
2017-2-18 09:26 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者: admin 時(shí)間: 2017-2-18 16:43
下面是樓主的主程序:
- /*****************************************************
- This program was produced by the
- CodeWizardAVR V2.05.0 Professional
- Automatic Program Generator
- ?Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
- Project :
- Version :
- Author : NeVaDa
- Company :
- Comments:
- Chip type : ATmega48
- AVR Core Clock frequency: 8.000000 MHz
- Memory model : Small
- External RAM size : 0
- Data Stack size : 128
- *****************************************************/
- #include <mega48.h>
- #include <delay.h>
- // DS18b20 Temperature Sensor functions
- #include <ds18b20.h>
- // Alphanumeric LCD Module functions
- #include <alcd.h>
- #define ADC_VREF_TYPE 0x60
- #define Temp_Set_Key_Not_Pressed PIND.6
- #define Alarm_Set_Key_Not_Pressed PIND.7
- // Read the 8 most significant bits
- // of the AD conversion result
- unsigned char read_adc(unsigned char adc_input)
- {
- ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
- // Delay needed for the stabilization of the ADC input voltage
- delay_us(10);
- // Start the AD conversion
- ADCSRA|=0x40;
- // Wait for the AD conversion to complete
- while ((ADCSRA & 0x10)==0);
- ADCSRA|=0x10;
- return ADCH;
- }
- // Declare your global variables here
- unsigned char Char_Array[3];
- unsigned char AD_Value=0;
- int Temprature;
- float Temp;
- unsigned char Temp_Set_Value=20;
- unsigned char Alarm_Set_Value=80;
- void HEX_To_AscII(int data,unsigned char *P)
- {
- P[2]=(data/100)+0x30;
- P[1]=((data%100)/10)+0x30;
- P[0]=(data%10)+0x30;
- }
- void main(void)
- {
- // Declare your local variables here
- // Crystal Oscillator division factor: 1
- #pragma optsize-
- CLKPR=0x80;
- CLKPR=0x00;
- #ifdef _OPTIMIZE_SIZE_
- #pragma optsize+
- #endif
- // Input/Output Ports initialization
- // Port B initialization
- // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=In
- // State7=T State6=T State5=T State4=T State3=T State2=1 State1=1 State0=T
- PORTB=0x06;
- DDRB=0x06;
- // Port C initialization
- // Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In
- // State6=T State5=1 State4=1 State3=1 State2=1 State1=1 State0=T
- PORTC=0x3E;
- DDRC=0x3E;
- // Port D initialization
- // Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=In Func1=In Func0=In
- // State7=P State6=P State5=T State4=T State3=1 State2=T State1=T State0=T
- PORTD=0xC8;
- DDRD=0x08;
- // Timer/Counter 0 initialization
- // Clock source: System Clock
- // Clock value: Timer 0 Stopped
- // Mode: Normal top=0xFF
- // OC0A output: Disconnected
- // OC0B output: Disconnected
- TCCR0A=0x00;
- TCCR0B=0x00;
- TCNT0=0x00;
- OCR0A=0x00;
- OCR0B=0x00;
- // Timer/Counter 1 initialization
- // Clock source: System Clock
- // Clock value: Timer1 Stopped
- // Mode: Normal top=0xFFFF
- // OC1A output: Discon.
- // OC1B output: Discon.
- // Noise Canceler: Off
- // Input Capture on Falling Edge
- // Timer1 Overflow Interrupt: Off
- // Input Capture Interrupt: Off
- // Compare A Match Interrupt: Off
- // Compare B Match Interrupt: Off
- TCCR1A=0x00;
- TCCR1B=0x00;
- TCNT1H=0x00;
- TCNT1L=0x00;
- ICR1H=0x00;
- ICR1L=0x00;
- OCR1AH=0x00;
- OCR1AL=0x00;
- OCR1BH=0x00;
- OCR1BL=0x00;
- // Timer/Counter 2 initialization
- // Clock source: System Clock
- // Clock value: 250.000 kHz
- // Mode: Fast PWM top=0xFF
- // OC2A output: Disconnected
- // OC2B output: Inverted PWM
- ASSR=0x00;
- TCCR2A=0x33;
- TCCR2B=0x03;
- TCNT2=0x00;
- OCR2A=0x00;
- OCR2B=0x00;
- // External Interrupt(s) initialization
- // INT0: Off
- // INT1: Off
- // Interrupt on any change on pins PCINT0-7: Off
- // Interrupt on any change on pins PCINT8-14: Off
- // Interrupt on any change on pins PCINT16-23: Off
- EICRA=0x00;
- EIMSK=0x00;
- PCICR=0x00;
- // Timer/Counter 0 Interrupt(s) initialization
- TIMSK0=0x00;
- // Timer/Counter 1 Interrupt(s) initialization
- TIMSK1=0x00;
- // Timer/Counter 2 Interrupt(s) initialization
- TIMSK2=0x00;
- // USART initialization
- // USART disabled
- UCSR0B=0x00;
- // Analog Comparator initialization
- // Analog Comparator: Off
- // Analog Comparator Input Capture by Timer/Counter 1: Off
- ACSR=0x80;
- ADCSRB=0x00;
- DIDR1=0x00;
- // ADC initialization
- // ADC Clock frequency: 250.000 kHz
- // ADC Voltage Reference: AVCC pin
- // ADC Auto Trigger Source: ADC Stopped
- // Only the 8 most significant bits of
- // the AD conversion result are used
- // Digital input buffers on ADC0: Off, ADC1: On, ADC2: On, ADC3: On
- // ADC4: On, ADC5: On
- DIDR0=0x01;
- ADMUX=ADC_VREF_TYPE & 0xff;
- ADCSRA=0x85;
- // SPI initialization
- // SPI disabled
- SPCR=0x00;
- // TWI initialization
- // TWI disabled
- TWCR=0x00;
- // 1 Wire Bus initialization
- // 1 Wire Data port: PORTB
- // 1 Wire Data bit: 0
- // Note: 1 Wire port settings must be specified in the
- // Project|Configure|C Compiler|Libraries|1 Wire IDE menu.
- //w1_init();
- // Alphanumeric LCD initialization
- // Connections specified in the
- // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
- // RS - PORTB Bit 1
- // RD - PORTB Bit 2
- // EN - PORTC Bit 1
- // D4 - PORTC Bit 2
- // D5 - PORTC Bit 3
- // D6 - PORTC Bit 4
- // D7 - PORTC Bit 5
- // Characters/line: 16
- lcd_init(16);
- lcd_gotoxy(0, 0);
- lcd_puts("NBUT");
- lcd_gotoxy(0, 1);
- if(ds18b20_init(0,-60,80,DS18B20_9BIT_RES))
- lcd_puts("OK!");
- else
- lcd_puts("FAULT!");
- delay_ms(1000);
- lcd_gotoxy(0, 0);
- lcd_puts("Temp:");
- lcd_gotoxy(0,1);
- lcd_puts("AD:");
- lcd_gotoxy(8, 1);
- lcd_puts("ALM:");
- HEX_To_AscII(Alarm_Set_Value,Char_Array);
- lcd_putchar(Char_Array[1]);
- lcd_putchar(Char_Array[0]);
- lcd_putchar('C');
- while (1)
- {
- // Place your code here
- //溫度讀取
- Temp=ds18b20_temperature(0);
-
- //加熱處理
- if((int)Temp>Temp_Set_Value)
- OCR2B=0;
- else
- OCR2B=AD_Value;
- //OCR2B=255;
-
- //報(bào)警處理
- lcd_gotoxy(12, 0);
- if(Temp>Alarm_Set_Value)
- lcd_puts("ALM!");
- else
- lcd_puts(" ");
-
-
- //溫度顯示
- Temprature=Temp*10;
- //delay_ms(10);
- lcd_gotoxy(5, 0);
- if(Temprature<0)
- {
- Temprature=-Temprature;
- lcd_putchar('-');
- }
- else
- lcd_putchar('+');
-
- HEX_To_AscII(Temprature,Char_Array);
-
- lcd_putchar(Char_Array[2]);
- lcd_putchar(Char_Array[1]);
- lcd_putchar('.');
- lcd_putchar(Char_Array[0]);
- lcd_putchar('C');
-
- //ad轉(zhuǎn)換處理
- AD_Value=read_adc(0);
- Temprature=(AD_Value*10)/51;
- HEX_To_AscII(Temprature,Char_Array);
- lcd_gotoxy(3,1);
- //lcd_putchar(Char_Array[2]);
- lcd_putchar(Char_Array[1]);
- lcd_putchar('.');
- lcd_putchar(Char_Array[0]);
- lcd_putchar('V');
-
- //溫度設(shè)置按鍵處理
- if(!Temp_Set_Key_Not_Pressed)
- {
- delay_ms(10);
- if(!Temp_Set_Key_Not_Pressed)
- {
- Temp_Set_Value++;
- if(Temp_Set_Value>20)
- Temp_Set_Value=0;
- lcd_gotoxy(5, 0);
- HEX_To_AscII(Temp_Set_Value,Char_Array);
- lcd_putchar(Char_Array[1]);
- lcd_putchar(Char_Array[0]);
- lcd_putchar('C');
- lcd_puts(" ");
- delay_ms(500);
- }
- }
-
- //溫度報(bào)警設(shè)置按鍵處理
- if(!Alarm_Set_Key_Not_Pressed)
- {
- delay_ms(10);
- if(!Alarm_Set_Key_Not_Pressed)
- {
- Alarm_Set_Value++;
- if(Alarm_Set_Value>20)
- Alarm_Set_Value=0;
- lcd_gotoxy(12, 1);
- HEX_To_AscII(Alarm_Set_Value,Char_Array);
- lcd_putchar(Char_Array[1]);
- lcd_putchar(Char_Array[0]);
- lcd_putchar('C');
- delay_ms(500);
- }
- }
- }
- }
復(fù)制代碼
作者: wang9117 時(shí)間: 2017-2-21 21:52
不錯(cuò)哦,能開源。值得學(xué)習(xí)。
作者: zzx19878 時(shí)間: 2018-9-12 11:32
怎么只有主程序的c文件
作者: zzx19878 時(shí)間: 2018-9-12 11:34
有沒有其他的c文件和h文件
作者: BaGas 時(shí)間: 2018-9-12 12:29
只有一個(gè)主程序嗎
作者: zzx19878 時(shí)間: 2018-9-13 16:41
是的
作者: 1216805172 時(shí)間: 2018-9-21 12:31
感謝分享
作者: 1216805172 時(shí)間: 2018-9-21 12:32
pcb和原理圖的文件沒有?
歡迎光臨 (http://www.torrancerestoration.com/bbs/) |
Powered by Discuz! X3.1 |