气流量控制系统方案.doc

上传人:scccc 文档编号:13922739 上传时间:2022-01-26 格式:DOC 页数:10 大小:84KB
返回 下载 相关 举报
气流量控制系统方案.doc_第1页
第1页 / 共10页
气流量控制系统方案.doc_第2页
第2页 / 共10页
气流量控制系统方案.doc_第3页
第3页 / 共10页
亲,该文档总共10页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《气流量控制系统方案.doc》由会员分享,可在线阅读,更多相关《气流量控制系统方案.doc(10页珍藏版)》请在三一文库上搜索。

1、/*xtal=8 AVR16 2011-5-11 MS*huang*#include #include#define uchar unsigned char#define uint unsigned int#defi ne CPL_BIT(x,y) (xA=(1y)_flash uchar SEG710=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;_flash uchar SEG49=0x77,0x7C,0x39,0x5e,0x79,0x71,0x6f,0x74,0x40;_flash ucharACT4=0xef,0xdf,0xbf,0

2、x7f;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;uchar start_flag,start_flag1;uchar i;long x;uint voltage1,Disval1,voltage2,Disval2;uint value,dis_val; / 无符号整型全局变量定义uchar status=4,status_1=0,status_2=0,flag; /无符号字符型

3、全局变量定义uchar status_sw=0;uchar num;/*#define S1 (PINA&0x01)/递减#define S2 (PINA&0x02)/位数设定#define S3 (PINA&0x04)/运行#define S4 (PINA&0x08)/存储#define S5 (PINA&0x10)/M4#define S6 (PINA&0x20)/M3#define S7 (PINA&0x40)/M2/#define S8 (PINA&0x80)/M1#define S9 (PINC&0x02)/ 递增#define S10 (PINC&0x01)/ 切换#define

4、xtal 8*#defineEEWE1#defineEEMWE2#defineEERE0/* 写EEPROM 子函数 *void WRITE_EEP(uint address,uchar dat) /dat为待写数据 ,add 为 EEPROM 的某单元地址 while(EECR&(1EEWE);/等待前一次写操作完成EEAR=address;/设定单元地址EEDR=dat;/ 将数据写入 EEDREECR|=(1EEMWE);/允许 EEPROM 操作/*读 EEPROM子函数*uchar READ_EEP(uint address) while(EECR&(1EEWE);EEAR=addr

5、ess;/ add 为 EEPROM 的某单元地址/ 等待前一次写操作完成/ 设定单元地址EECR|=(1EERE);/ 开始 EEPROM 写操作return EEDR;/ 返回读出的数据/* void Delay_1ms(void) uint i;for(i=1;i(uint)(xtal*143-2);i+)/=void Delay_nms(uint n)uint i=0;while(i2)status_2=0;if(S9=0)/ 个十百位选择Delay_nms(10);if(S9=0)while(!S9);if(+status_sw3)status_sw=0;if(status_sw=0

6、)PORTB|=(10);PORTB&=(11);PORTB&=(12);PORTB&= (13);else if(status_sw=3)PORTB|=(11);PORTB&=(10);PORTB&=(12);PORTB&= (13);else if(status_sw=2)PORTB|=(12);PORTB&=(11);PORTB&=(10);PORTB&= (13);else if(status_sw=1)PORTB|=(13);PORTB&=(11);PORTB&=(12);PORTB&= (19)cnt1_1=0;else if(status_2=0)&(status_sw=1) i

7、f(+cnt1_29)cnt1_2=0;else if(status_2=0)&(status_sw=2) if(+cnt1_39)cnt1_3=0;else if(status_2=0)&(status_sw=3) if(+cnt1_49)cnt1_4=0;/ if(status_2=1)&(status_sw=0) if(+cnt2_19)cnt2_1=0;else if(status_2=1)&(status_sw=1) if(+cnt2_29)cnt2_2=0;else if(status_2=1)&(status_sw=2)if(+cnt2_39)cnt2_3=0;else if(s

8、tatus_2=1)&(status_sw=3) if(+cnt2_49)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;else if(status_2=0)&(status_sw=1)if(-cnt1_2=0)cnt1_2=9;else if(status_2=0)&(status_sw=2)if(-cnt1_3=0)cnt1_3=9;else if(status_2=0)&(status_sw=3)if(-cnt1_4=0)cnt

9、1_4=9;/if(status_2=1)&(status_sw=0)if(-cnt2_1=0)cnt2_1=9;else if(status_2=1)&(status_sw=1)if(-cnt2_2=0)cnt2_2=9;else if(status_2=1)&(status_sw=2)if(-cnt2_3=0)cnt2_3=9;else if(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(1

10、0);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);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(!

11、S3);PORTC|=(14);/CPL_BIT(start_flag,0);/* if(start_flag=0x01)/ 启动PORTC|=(14);if(start_flag=0x00)/ 停止PORTC&=(14);*/if(S4=0)/ 启动位翻转Delay_nms(10);if(S4=0)while(!S4);PORTC&=(120) flag=0;num=0;Delay_nms(100); if(dis_val(cnt1_1+cnt1_2*10+cnt1_3*100+cnt1_4*1000)PORTC&=(14); /M1 驱动关闭/if(dis_val(cnt2_1+cnt2_

12、2*10+cnt2_3*100+cnt2_4*1000)PORTC|=(14)status_2=0;Delay_nms(150);/ 切换键 */ /*else if(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(365,cnt5);Delay_nms(10);/ 储存键 */* else if(S9=0)if(status_2 = 0)if

13、(+cnt199)cnt1=0;if(status_2 = 1)if(+cnt299)cnt2=0;if(status_2 = 2)if(+cnt399)cnt3=0;if(status_2 = 3)if(+cnt499)cnt4=0;if(status_2 = 4)if(+cnt599)cnt5=0;Delay_nms(150);/ 递增键 */* else if(S2=0)if(status_2 = 0)if(-cnt1=0)cnt1=99;if(status_2 = 1)if(-cnt2=0)cnt2=99;if(status_2 = 2)if(-cnt3=0)cnt3=99;if(st

14、atus_2 = 3)if(-cnt4=0)cnt4=99;if(status_2 = 4)if(-cnt5=0)cnt5=99;Delay_nms(150);/ 递减键else if(S4=0)PORTC|=(13);PORTB|=(10);status_2=0;status=0;status_1=1;Delay_nms(cnt 1*100);PORTC&=(13);PORTB&=(10);/QGelse if(S8=0)PORTC|=(14);PORTB|=(11);status_2=1;status=1;status_1=1;Delay_nms(cnt 2*100);PORTC&=(14

15、);PORTB&=(11);/M1else if(S7=0)PORTC|=(15);PORTB|=(12);status_2=2;status=2;status_1=1;Delay_nms(cnt 3*100);PORTC&=(15);PORTB&=(12);/M2else if(S6=0)PORTC|=(16);PORTB|=(13);status_2=3;status=3;status_1=1;Delay_nms(cnt 4*100);PORTC&=(16);PORTB&=(13);/M3else if(S5=0)PORTC|=(17);PORTC|=(12);status_2=4;sta

16、tus=4;status_1=1;Delay_nms(cnt 5*100);PORTC&=(17);PORTC&=(12);/M4else if(S3=0)PORTC|=(14);PORTC|=(15);PORTC|=(16);PORTC|=(17);PORTC|=(13);PORTB|=(10);PORTB|=(11);PORTB|=(12);PORTB|=(1 3);PORTC|=(12);status_2=5;status=5;Delay_nms(cnt1*100);PORTC&=(13);PORTC&=(14);PORTC&=(15);PORTC&=(16);PORTC&=(17);P

17、ORTB&=(10);PORTB&=(11);PORTB&=(12);PORTB&=(13);PORTC &=(12);*/*else if(S3=0)Delay_nms(20);CPL_BIT(start_flag,0); Delay_nms(20);if(start_flag=0x01)PORTC|=(14);PORTC|=(15);PORTC|=(16);PORTC|=(17);PORTC|=(13);Delay_nms(cnt1*100);PORTC&=(13);PORTC&=(14);PORTC&=(15);PORTC&=(16);PORTC&=(13)i=0;switch(i)ca

18、se 0: if(status_2=0)PORTD=SEG7cnt1_1;PORTB&=(14);PORTB|=(15)|(16)|(17); if(status_2=1)PORTD=SEG7cnt2_1;PORTB&=(14);PORTB|=(15)|(16)|(17);if(status_2=2)PORTD=SEG70;PORTB&=(14);PORTB|=(15)|(16)|(17);break;case 1: if(status_2=0)PORTD=SEG7cnt1_2;PORTB&=(15);PORTB|=(14)|(16)|(17); if(status_2=1)PORTD=SEG

19、7cnt2_2;PORTB&=(15);PORTB|=(14)|(16)|(17); if(status_2=2)PORTD=SEG7(dis_val/10)%10;PORTB&=(15);PORTB|=(14)|(16)|(17);break;case 2: if(status_2=0)PORTD=SEG7cnt1_3;PORTB&=(17);PORTB|=(14)|(15)|(16); if(status_2=1)PORTD=SEG7cnt2_3;PORTB&=(17);PORTB|=(14)|(15)|(16); if(status_2=2)PORTD=SEG7(dis_val/100)

20、%10;PORTB&=(17);PORTB|=(14)|(15)|(16);break;case3:if(status_2=0)PORTD=SEG7cnt1_4;PORTB&=(16);PORTB|=(14)|(15)|(17); if(status_2=1)PORTD=SEG7cnt2_4;PORTB&=(16);PORTB|=(14)|(15)|(17); if(status_2=2)PORTD=SEG7dis_val/1000;PORTB&=(16);PORTB|=(14)|(15)|(17); break;default:break;#pragma vector=ADC_vect_interrupt void adc_isr(void)/conversion complete, read value (int) using. value=ADCL;/ 取得模数转换值 value|=(int)ADCH 8;flag=1; / 置标志 flag 为 1ADMUX = 0x07;ADCSRA|=0xCE;/ 单道输入通道 PA7 +num;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1