气流量控制系统方案_第1页
气流量控制系统方案_第2页
气流量控制系统方案_第3页
气流量控制系统方案_第4页
气流量控制系统方案_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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;/无符号整型全局变量定义ucharstatus=4,status_1=0,status_

3、2=0,flag;/无符号字符型全局变量定义ucharstatus_sw=0;ucharnum;/*#defineS1(PINA&0x01)/递减#defineS2(PINA&0x02)/位数设定#defineS3(PINA&0x04)/运行#defineS4(PINA&0x08)/存储#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/*写EEPROM子函数*/*为待写数据,add 为 EEPROM 的某单voidWRITE_EEP(uintaddress,uchardat)/dat元地址while(EECR&(1<<EEWE);EEAR=address;EEDR=dat;EECR|=(1<<EEMWE);/ 等待前一次写操作完成/ 设定单元地址/ 将数据写入 EEDR/ 允许 EEPROM 操作EECR|=(1<<EEWE);/*/

5、开始 EEPROM 写操作读 EEPROMuchar READ_EEP(uint address) 子函数 */ add 为 EEPROM 的某单元地址while(EECR&(1<<EEWE);EEAR=address;EECR|=(1<<EERE);return EEDR;/等待前一次写操作完成设定单元地址/开始 EEPROM 写操作返回读出的数据/*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) /数据转换子函数,定义i 为无符号整型变量long m; / 定义 x 为无符号长整型局部变量uint n; / 定义 y 为无符号整型局部变量m=(5000*(long)l)/1023; /将变量 i 转换成需要显示的形式n=(uint)m; / 将无符号长整型变量x 强制转换成无符号整型变量yreturn n; / 返回 y 的值/*/void port_init(void)PORTA = 0x7F;DDRA = 0x00;MCUCSR|=0x80;/PORTB = 0x00;DDRB = 0xFF;MCUCSR|=0x80;

7、/使 PORTB 端口的 JTAG 功能无效使 PORTC 端口的 JTAG 功能无效PORTC=0x03;DDRC=0xfC;MCUCSR|=0x80;/使PORTD端口的JTAG功能无效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;/*看门狗初始化 ,分频系数为 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;/模数转换初始化子函数选择 ADC 输入通道为 7关掉模拟比较器单次转换 中断/ADCSRA = 0xE9; /ADC 使能中断使能,预分频器系数取2 , ADC 转换使能,自动触发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)/个十百位选择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)/储存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)/启动位翻转Delay_nms(10);if(S3=0)while(!S3);PORTC|=(1<<4);/CPL_BIT(start_flag,0);/*if(start_flag=0x01)/启动PORTC|=(1<<4);if(start_flag=0x00)/停止PORTC&=(1<<

17、4);*/if(S4=0)/启动位翻转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驱动关闭/if(dis_val<(cnt2_1+c

19、nt2_2*10+cnt2_3*100+cnt2_4*1000)PORTC|=(1<<4);/M1驱动开起/*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);/储存键*/*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;运行键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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论