氣流量控制系統(tǒng)方案_第1頁(yè)
氣流量控制系統(tǒng)方案_第2頁(yè)
氣流量控制系統(tǒng)方案_第3頁(yè)
氣流量控制系統(tǒng)方案_第4頁(yè)
氣流量控制系統(tǒng)方案_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、/*xtal=8AVR162011-5-11MS*huang*#include<iom16.h>#include<intrinsics.h>#defineucharunsignedchar#defineuintunsignedint#defineCPL_BIT(x,y)(xA=(1<<y)_flashucharSEG710=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;_flashucharSEG49=0x77,0x7C,0x39,0x5e,0x79,0x71,0x6f,0x74,0x40;_flashu

2、charACT4=0xef,0xdf,0xbf,0x7f;uintt1=1234,cnt2=11,cnt3=22,cnt4=33,cnt5=44,cnt6=0,cnt7=0,cnt8=0,cnt9=0;uintt1_1,cnt1_2,cnt1_3,cnt1_4,cnt2_1,cnt2_2,cnt2_3,cnt2_4;ucharstart_flag,start_flag1;uchari;longx;uintvoltage1,Disval1,voltage2,Disval2;uintvalue,dis_val;/無(wú)符號(hào)整型全局變量定義ucharstatus=4,status_1=0,status_

3、2=0,flag;/無(wú)符號(hào)字符型全局變量定義ucharstatus_sw=0;ucharnum;/*#defineS1(PINA&0x01)/遞減#defineS2(PINA&0x02)/位數(shù)設(shè)定#defineS3(PINA&0x04)/運(yùn)行#defineS4(PINA&0x08)/存儲(chǔ)#defineS5(PINA&0x10)/M4#defineS6(PINA&0x20)/M3#defineS7(PINA&0x40)/M2/#defineS8(PINA&0x80)/M1#defineS9(PINC&0x02)/遞增#def

4、ineS10(PINC&0x01)/切換#definextal8#defineEEWE1#defineEEMWE2#defineEERE0/*寫(xiě)EEPROM子函數(shù)*/*為待寫(xiě)數(shù)據(jù),add 為 EEPROM 的某單voidWRITE_EEP(uintaddress,uchardat)/dat元地址while(EECR&(1<<EEWE);EEAR=address;EEDR=dat;EECR|=(1<<EEMWE);/ 等待前一次寫(xiě)操作完成/ 設(shè)定單元地址/ 將數(shù)據(jù)寫(xiě)入 EEDR/ 允許 EEPROM 操作EECR|=(1<<EEWE);/*/

5、開(kāi)始 EEPROM 寫(xiě)操作讀 EEPROMuchar READ_EEP(uint address) 子函數(shù) */ add 為 EEPROM 的某單元地址while(EECR&(1<<EEWE);EEAR=address;EECR|=(1<<EERE);return EEDR;/等待前一次寫(xiě)操作完成設(shè)定單元地址/開(kāi)始 EEPROM 寫(xiě)操作返回讀出的數(shù)據(jù)/*voidDelay_1ms(void)uinti;for(i=1;i<(uint)(xtal*143-2);i+)/voidDelay_nms(uintn)uinti=0;while(i<n)Dela

6、y_1ms();i+;/*/uint conv(uint l) /數(shù)據(jù)轉(zhuǎn)換子函數(shù),定義i 為無(wú)符號(hào)整型變量long m; / 定義 x 為無(wú)符號(hào)長(zhǎng)整型局部變量uint n; / 定義 y 為無(wú)符號(hào)整型局部變量m=(5000*(long)l)/1023; /將變量 i 轉(zhuǎn)換成需要顯示的形式n=(uint)m; / 將無(wú)符號(hào)長(zhǎng)整型變量x 強(qiáng)制轉(zhuǎn)換成無(wú)符號(hào)整型變量yreturn n; / 返回 y 的值/*/void port_init(void)PORTA = 0x7F;DDRA = 0x00;MCUCSR|=0x80;/PORTB = 0x00;DDRB = 0xFF;MCUCSR|=0x80;

7、/使 PORTB 端口的 JTAG 功能無(wú)效使 PORTC 端口的 JTAG 功能無(wú)效PORTC=0x03;DDRC=0xfC;MCUCSR|=0x80;/使PORTD端口的JTAG功能無(wú)效PORTD=0x00;DDRD=0xff;voidtimer0_init(void)TCNT0=0x83;TCCR0=0x04;voidtimer1_init(void)TCCR1A=0xA3;TCCR1B=0x0A;OCR1A=0x00;OCR1B=0x00;TCNT1H=0xD8;TCNT1L=0xF0;/*看門(mén)狗初始化 ,分頻系數(shù)為 256K*void watchdog_init(void)_watc

8、hdog_reset();WDTCR = 0x1b;WDTCR = 0x00;void adc_init(void) /ADCSRA=0x00;ADMUX = 0x07; /ACSR = 0x80; /ADCSRA= 0xCE;/模數(shù)轉(zhuǎn)換初始化子函數(shù)選擇 ADC 輸入通道為 7關(guān)掉模擬比較器單次轉(zhuǎn)換 中斷/ADCSRA = 0xE9; /ADC 使能中斷使能,預(yù)分頻器系數(shù)取2 , ADC 轉(zhuǎn)換使能,自動(dòng)觸發(fā)void init_devices(void)_disable_interrupt(); /disable all interrupts port_init();timer0_init();

9、/timer1_init();adc_init();MCUCR = 0x8A;/ 中斷方式控制GICR=0xC0;/使能中斷方式TIMSK=0x03;_enable_interrupt();/re-enableinterrupts11)/*/voidscan()if(S10=0)/切換鍵Delay_nms(10);if(S10=0)while(!S10);if(+status_2>2)status_2=0;)if(S9=0)/個(gè)十百位選擇Delay_nms(10);if(S9=0)while(!S9);if(+status_sw>3)status_sw=0;if(status_sw

10、=0)PORTB|=(1<<0);PORTB&=(1<<1);PORTB&=(1<<2);PORTB&=(1<<3);elseif(status_sw=3)PORTB|=(1<<1);PORTB&=(1<<0);PORTB&=(1<<2);PORTB&=(1<<3);elseif(status_sw=2)PORTB|=(1<<2);PORTB&=(1<<1);PORTB&=(1<<0);PORTB&a

11、mp;=(1<<3);elseif(status_sw=1)PORTB|=(1<<3);PORTB&=(1<<1);PORTB&=(1<<2);PORTB&=(1<<0);if(S2=0)/遞增Delay_nms(10);if(S2=0)while(!S2);if(status_2=0)&&(status_sw=0)(if(+cnt1_1>9)cnt1_1=0;)elseif(status_2=0)&&(status_sw=1)(if(+cnt1_2>9)cnt1_2

12、=0;)elseif(status_2=0)&&(status_sw=2)(if(+cnt1_3>9)cnt1_3=0;)elseif(status_2=0)&&(status_sw=3)(if(+cnt1_4>9)cnt1_4=0;)lllllllllllllllllllllllllllllllllllllllllif(status_2=1)&&(status_sw=0)(if(+cnt2_1>9)cnt2_1=0;)elseif(status_2=1)&&(status_sw=1)(if(+cnt2_2>

13、;9)cnt2_2=0;)elseif(status_2=1)&&(status_sw=2)(if(+cnt2_3>9)cnt2_3=0;)elseif(status_2=1)&&(status_sw=3)(if(+cnt2_4>9)cnt2_4=0;)if(S1=0)/遞減(Delay_nms(10);if(S1=0)while(!S1);if(status_2=0)&&(status_sw=0)if(-cnt1_1=0)cnt1_1=9;elseif(status_2=0)&&(status_sw=1)if(-cn

14、t1_2=0)cnt1_2=9;elseif(status_2=0)&&(status_sw=2)if(-cnt1_3=0)cnt1_3=9;elseif(status_2=0)&&(status_sw=3)if(-cnt1_4=0)cnt1_4=9;/if(status_2=1)&&(status_sw=0)if(-cnt2_1=0)cnt2_1=9;elseif(status_2=1)&&(status_sw=1)if(-cnt2_2=0)cnt2_2=9;elseif(status_2=1)&&(status

15、_sw=2)if(-cnt2_3=0)cnt2_3=9;elseif(status_2=1)&&(status_sw=3)if(-cnt2_4=0)cnt2_4=9;if(S5=0)/儲(chǔ)存Delay_nms(10);if(S5=0)while(!S4);WRITE_EEP(345,cnt1_1);Delay_nms(10);WRITE_EEP(350,cnt1_2);Delay_nms(10);WRITE_EEP(355,cnt1_3);Delay_nms(10);WRITE_EEP(360,cnt1_4);Delay_nms(10);WRITE_EEP(365,cnt2_1)

16、;Delay_nms(10);WRITE_EEP(370,cnt2_2);Delay_nms(10);WRITE_EEP(375,cnt2_3);Delay_nms(10);WRITE_EEP(380,cnt2_4);Delay_nms(10);if(S3=0)/啟動(dòng)位翻轉(zhuǎn)Delay_nms(10);if(S3=0)while(!S3);PORTC|=(1<<4);/CPL_BIT(start_flag,0);/*if(start_flag=0x01)/啟動(dòng)PORTC|=(1<<4);if(start_flag=0x00)/停止PORTC&=(1<<

17、4);*/if(S4=0)/啟動(dòng)位翻轉(zhuǎn)Delay_nms(10);if(S4=0)while(!S4);PORTC&=(1<<4);voidmain(void)/*init_devices();cnt1_1=READ_EEP(345);Delay_nms(10);cnt1_2=READ_EEP(350);Delay_nms(10);cnt1_3=READ_EEP(355);Delay_nms(10);cnt1_4=READ_EEP(360);Delay_nms(10);cnt2_1=READ_EEP(365);Delay_nms(10);cnt2_2=READ_EEP(37

18、0);Delay_nms(10);cnt2_3=READ_EEP(375);Delay_nms(10);cnt2_4=READ_EEP(380);Delay_nms(10);*/while(1)scan();if(num>20)Delay_nms(10);if(flag=1)dis_val=(conv(value);flag=0;num=0;Delay_nms(100);if(dis_val>(cnt1_1+cnt1_2*10+cnt1_3*100+cnt1_4*1000)PORTC&=(1<<4);/M1驅(qū)動(dòng)關(guān)閉/if(dis_val<(cnt2_1+c

19、nt2_2*10+cnt2_3*100+cnt2_4*1000)PORTC|=(1<<4);/M1驅(qū)動(dòng)開(kāi)起/*if(S10=0)status_1=0;status=6;if(+status_2>4)status_2=0;Delay_nms(150);/切換鍵*/*elseif(S1=0)WRITE_EEP(345,cnt1);Delay_nms(10);WRITE_EEP(350,cnt2);Delay_nms(10);WRITE_EEP(355,cnt3);Delay_nms(10);WRITE_EEP(360,cnt4);Delay_nms(10);WRITE_EEP(3

20、65,cnt5);Delay_nms(10);/儲(chǔ)存鍵*/*elseif(S9=0)if(status_2=0)if(+cnt1>99)cnt1=0;if(status_2=1)if(+cnt2>99)cnt2=0;if(status_2=2)if(+cnt3>99)cnt3=0;if(status_2=3)if(+cnt4>99)cnt4=0;if(status_2=4)if(+cnt5>99)cnt5=0;Delay_nms(150);/遞增鍵*/*elseif(S2=0)if(status_2=0)if(-cnt1=0)cnt1=99;if(status_2

21、=1)if(-cnt2=0)cnt2=99;if(status_2=2)if(-cnt3=0)cnt3=99;if(status_2=3)if(-cnt4=0)cnt4=99;if(status_2=4)if(-cnt5=0)cnt5=99;Delay_nms(150);/遞減鍵elseif(S4=0)PORTC|=(1<<3);PORTB|=(1<<0);status_2=0;status=0;status_1=1;Delay_nms(cnt1*100);PORTC&=(1<<3);PORTB&=(1<<0);/QGelseif

22、(S8=0)PORTC|=(1<<4);PORTB|=(1<<1);status_2=1;status=1;status_1=1;Delay_nms(cnt2*100);PORTC&=(1<<4);PORTB&=(1<<1);/M1elseif(S7=0)PORTC|=(1<<5);PORTB|=(1<<2);status_2=2;status=2;status_1=1;Delay_nms(cnt3*100);PORTC&=(1<<5);PORTB&=(1<<2);/

23、M2elseif(S6=0)PORTC|=(1<<6);PORTB|=(1<<3);status_2=3;status=3;status_1=1;Delay_nms(cnt4*100);PORTC&=(1<<6);PORTB&=(1<<3);/M3elseif(S5=0)PORTC|=(1<<7);PORTC|=(1<<2);status_2=4;status=4;status_1=1;Delay_nms(cnt5*100);PORTC&=(1<<7);PORTC&=(1<

24、<2);/M4elseif(S3=0)PORTC|=(1<<4);PORTC|=(1<<5);PORTC|=(1<<6);PORTC|=(1<<7);PORTC|=(1<<3);PORTB|=(1<<0);PORTB|=(1<<1);PORTB|=(1<<2);PORTB|=(1<<3);PORTC|=(1<<2);status_2=5;status=5;Delay_nms(cnt1*100);PORTC&=(1<<3);PORTC&=(1&

25、lt;<4);PORTC&=(1<<5);PORTC&=(1<<6);PORTC&=(1<<7);PORTB&=(1<<0);PORTB&=(1<<1);PORTB&=(1<<2);PORTB&=(1<<3);PORTC&=(1<<2);*/*elseif(S3=0)Delay_nms(20);CPL_BIT(start_flag,0);Delay_nms(20);if(start_flag=0x01)PORTC|=(1<&

26、lt;4);PORTC|=(1<<5);PORTC|=(1<<6);PORTC|=(1<<7);PORTC|=(1<<3);Delay_nms(cnt1*100);PORTC&=(1<<3);PORTC&=(1<<4);PORTC&=(1<<5);PORTC&=(1<<6);PORTC&=(1<<7);PORTC=0x00;status_2=0;status=9;status_1=0;Delay_nms(cnt4*100);start_flag=0

27、x00;運(yùn)行鍵if(start_flag=0x00)watchdog_init();Delay_nms(400);*/*/#pragmavector=TIMER0_OVF_vect_interruptvoidtimer0_ovf_isr(void)/SREG=0x80;TCNT0=0x83;if(+i>3)i=0;switch(i)case0:if(status_2=0)PORTD=SEG7cnt1_1;PORTB&=(1<<4);PORTB|=(1<<5)|(1<<6)|(1<<7);if(status_2=1)PORTD=SEG

28、7cnt2_1;PORTB&=(1<<4);PORTB|=(1<<5)|(1<<6)|(1<<7);if(status_2=2)PORTD=SEG70;PORTB&=(1<<4);PORTB|=(1<<5)|(1<<6)|(1<<7);break;case 1: if(status_2=0)PORTD=SEG7cnt1_2;PORTB&=(1<<5);PORTB|=(1<<4)|(1<<6)|(1<<7);if(status_2=1)PORTD=SEG7cnt2_2;PORTB&=(1<<5);PORTB|=(1<<4)|(1<<6)|(1<<7);if(status_2=2)PORTD=SEG

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論