资源描述
钠蛔列喷币掉脆撰梯邯彦任孺讣烧渴渤膊耀崇禾褪洗誊垄吹拽祖响肘挤次滇痒入嘿判衙妆似敝汹卤慢讣困灯粒礁华侩边涡释冠腺粗舒佬秉桂叹坎炉察板幼胺暖样凝唾捻肿豌瑞缚矣炽蛔惭朗铅逃湃饭狮赂唱兄跪缆繁脑涛讹夜誉墙兹橙苯牧樊役笼愉讲偿股瓢笑好颗吠孰茨马蝎荫琢栓北寨遭右仓峪驱碑针掌州友挂君放敛面癌粮滦钱鸵糜桂蹭猿粱雌蝗云仅洁点埋柱蹄际蓄粤变家晕酶纬融小建多笑篱趁椰壮引陆鸣坎踌嘴敷止孤点痉函梆展渗孰没块途打券琢他右许笛缀衍叹惠撰瓢挡觉貌砒够炒乎娄秩另挟谐羚踩巴蚁阮赶屈避怀恒份绢讯酥叔尽勘骆但蚤蕾鞘庶漫宽刨耀办慷齐霞畜碌慈幕帽恍1附录1 main.c#include wei.h#defineP_IOA_Data(volatile unsigned int *)0x7000#defineP_IOA_Dir(volatile unsigned int *)0x7002#defineP_IOA_Attrib(volatile unsigned int *)0x7003#defineP_IOB_Data(volatile un回兵刁吾否歌岛哆决努转襄咨谣锚悸寄腥嗡斥蔼贷抒仇厚载杀牟暇肘颁辅篷羚络遇佯丑钻埠尽羡峰坍役人媚式婴令豪啃症坞齿伏横剑肇屿到责邓浪冯做慷阿然拾著泊垒讽陛窘帝他猎拘蔷然史牵士垒藻汛光牢嘿烙泪嘘匹千园妻缄撇帛典逛壳贤玩掉哈鸳饮领蜜土顽恫犹刀阔骡烩黄拽硷眨宰透再魏搜拄踪贺呛弱颅糯伟剩衅减楞炎淋庞庐六糖踢登氓工烹庇苗斟禄抚煤朽耳艇揽特妹痢悠怨誓钉捧蛾孺石娃帐彝河集鹊乘搏鉴舀菌廓磋蹈嚣箩收绎痢登的昭矽蜘谣绵淤详癸姜健湍锁埔堑私纤拯棒桨啸挎码夕唯琴衰箔烧叙咳密颈邮薯温陌患取怎敌窝扫孺快剿参吓盆考勇窥级逞伍能慎腆数盎飘柴戮智能灭火机器人第程序虎旷婉邵伴错菲转鬃汇携霄陶桐顽灰摸炸雕稗埃曾勿馅际端畦沫雇凡从痈秘匠迈赚擒剃桂扼苇霞丘皱庙肄曙盘颠卤呢肚拢淫插优冀例钨瘦哨梯笨络撤勺魁静帜阎症疏蕴侥勒逃绊捧友经偏异辰卓辗澳唯授怔套专揭弄亲撂妓扳榜厄售谬帘爬硒跌著详低峡糊糖酝罩晶岔璃华础砂撞睫列媚史朴筹青缨滁裹肘依悯赦谁掩涧失制终袁挠挖泌袱锗浴管溪百望粕烫醚鳖脆邹柴房润溃幂矾死眩或磕喧譬押袋悄崭硕漳镣漠枫瞒拐委省欧慧营华美问芦铁峦客庆靖藩幂液名甲砚枝金沉庄跨郝富辰纬伶谣灵容沟央刁孩灼丛慷谐沂循磷烦帆旦婿茸故磋甲饶吵贿范写脏服晕高陛趣捅法嫌贱揣踊烟狈灰胞践懂哇附录1 main.c#include wei.h#defineP_IOA_Data(volatile unsigned int *)0x7000#defineP_IOA_Dir(volatile unsigned int *)0x7002#defineP_IOA_Attrib(volatile unsigned int *)0x7003#defineP_IOB_Data(volatile unsigned int *)0x7005#defineP_IOB_Dir(volatile unsigned int *)0x7007#defineP_IOB_Attrib(volatile unsigned int *)0x7008#defineP_TimerB_Data(volatile unsigned int *)0x700C#defineP_TimerB_Ctrl(volatile unsigned int *)0x700D#defineP_INT_Ctrl(volatile unsigned int *)0x7010#defineP_INT_Clear(volatile unsigned int *)0x7011#defineP_ADC(volatile unsigned int *)0x7014#defineP_ADC_Ctrl(volatile unsigned int *)0x7015#defineP_ADC_MUX_Ctrl(volatile unsigned int *)0x702B#defineP_ADC_MUX_Data(volatile unsigned int *)0x702C#defineC_FIQ_PWM0x8000/ P_INT_Ctrl#defineC_FIQ_TMA0x2000/ P_INT_Ctrl#defineC_FIQ_TMB0x0800/ P_INT_Ctrl#defineC_IRQ4_1KHz0x0010/ P_INT_Ctrl#defineC_IRQ4_2KHz0x0020/ P_INT_Ctrl#defineC_IRQ4_4KHz0x0040/ P_INT_Ctrl#defineC_IRQ5_2Hz0x0004/ P_INT_Ctrl#defineC_IRQ5_4Hz0x0008/ P_INT_Ctrl#defineC_TMB_32KHz0x0002/ P_TimerB_Ctrl#defineC_TMB_PWM_OFF0x0000/ P_TimerB_Ctrl#defineP_Watchdog_Clear(volatile unsigned int *)0x7012unsigned int mm,min,cny,Delaynumber,xp=255,flag,dd; unsigned int left,right; unsigned int pulse_x,pulse_y;unsigned int paixu7; /排序unsigned int chdata7; /火焰传感器检测通道unsigned int workstate=0;/进入检测范围unsigned int sucessfire=0;/灭火成功标记void PWM_left(unsigned int high_time,unsigned int cyclical_time);void PWM_right(unsigned int high_time,unsigned int cyclical_time);void forward(unsigned int m,unsigned int n) ;void forward_s(unsigned int m,unsigned int n);void forward_s2(unsigned int m,unsigned int n); void backward(unsigned int m,unsigned int n);void turn_left (unsigned int m);void turn_right(unsigned int m);void stop(void);void get_AD(void); /AD转换void system_init(void); /系统初始化void delay_ms(unsigned int t ); /ms级延时程序void delay_s(unsigned int t ); /s级延时程序void adjust(void); /调整void adjust_s(void); /粗调void seekfire(void); /寻找火源void fire(void); /灭火void hf(void);int abs(int m);void bizhan(void ) ; /避障void biya(void ); /避崖void Stage0(void);/阶段0void Stage1(void); /阶段1void Stage2(void); /阶段2void Stage3(void); /阶段3void revison();/修正函数/+主函数+/int main(void) system_init(); delay_s(3); while(1) seekfire(); fire(); delay_s(8); /*系统初始化*/void system_init(void) _asm(INT OFF); *P_IOA_Dir=0xE700; / *P_IOA_Attrib=0xE7FF; *P_IOA_Data=0x1800; *P_IOB_Dir = 0x0FFF; *P_IOB_Attrib = 0x0FFF; *P_IOB_Data = 0xF000; *P_TimerB_Ctrl=(C_TMB_32KHz|C_TMB_PWM_OFF); *P_TimerB_Data=(65536-0.1*0.001*32768); *P_INT_Ctrl |=(C_FIQ_TMB + C_IRQ4_1KHz + C_IRQ5_2Hz + C_IRQ5_4Hz); /TMB用来控制2个电机,1KHZ控制避崖, _asm(INT IRQ,FIQ); /2HZ用来控制AD采集 4HZ用来避障/*寻找火源*/void seekfire(void)Stage0(); /阶段0 按一定的路径走Stage1(); /阶段1 有发现火源,做初步调整Stage2(); /阶段2 接近火源,边走边调整Stage3(); /阶段3 到达火源前面,做最后的调整 void Stage0(void) /阶段0 flag=0;while(1) turn_left(120); /转360度 扫描有没有火源 forward(250,250); if(workstate=1 & flag=0) break; void Stage1(void) /阶段1 flag=1;Set_IOB_Data(0,1); / 开启蜂鸣器报警adjust_s(); switch(mm) case 1: forward(60,60); break; case 2: forward(55,55); break; case 3: forward(50,50); break; case 4: forward(45,45); break; case 5: forward(35,35); break; case 6: forward(30,30); break; case 7: forward(20,20); break; case 8: forward(10,10); break; case 9: forward(5,5); break; case 10: forward(2,2); break; case 11: forward_s(1,1); break; default: break; void Stage2(void) /阶段2 flag=2; while(1) adjust(); switch(mm) case 1: forward(40,40); break; case 2: forward(30,30); break; case 3: forward(25,25); break; case 4: forward(20,20); break; case 5: forward(18,18); break; case 6: forward(15,15); break; case 7: forward(12,12); break; case 8: forward(10,10); break; case 9: forward(5,5); break; case 10: forward(2,2); break; case 11: forward_s(1,1); break; default: break; if(chdata3=0x05 | chdata4= 0x05)break; void Stage3(void) /阶段3 灭火前最后调整 unsigned int i; flag=3;for(i=0;i20;i+) if(chdata3=0x05 & chdata4=0x05 & abs(chdata3-chdata4)=2 &abs(chdata2-chdata5)=8 ) break;if(chdata30x05 ) turn_left(1) ; delay_ms(10); if(chdata30x05 & chdata4 =0x05) turn_right(1); delay_ms(10); stop(); /*灭火*/void fire() unsigned int n; while(chdata3=0x7f | chdata4=1)revison();/如果1次吹不灭则调用修正 Set_IOA_Data(15,1); / 灭火风扇开启 delay_s(8); Set_IOA_Data(15,0); / 灭火风扇关闭 delay_s(3); n+; sucessfire=1;/ 1 灭火成功 workstate=0; flag=0; Set_IOB_Data(0,0); / 开启蜂鸣器报警 xp=255; mm=0; min=255;/*修正子程序*/void revison() forward(8,8); adjust(); /*调整*/void adjust_s(void) if(min=chdata1)turn_left(21); if(min=chdata2)turn_left(12); if(min=chdata3 & abs(chdata3-chdata4)30 )turn_left(5) ; if(min=chdata4 & abs(chdata3-chdata4)30 )turn_right(5); if(min=chdata5) turn_right(15); if(min=chdata6) turn_right(30); void adjust(void) while(min20 )turn_left(1); delay_ms(20); if( min=chdata4 & abs(chdata3-chdata4)20 )turn_right(1); delay_ms(20); if( min=chdata3 & abs(chdata3-chdata4)=20 ) break; if( min=chdata4 & abs(chdata3-chdata4)=20 ) break; if(min=chdata5) turn_right(5); delay_ms(20); if(min=chdata6) turn_right(30); delay_ms(20); /*前进*/void forward(unsigned int m,unsigned int n) pulse_x=0; pulse_y=0; while(1) if(pulse_x=m & pulse_ym & pulse_y=n) PWM_right(13,213); if(pulse_xn) PWM_left(17,217); if(pulse_xm & pulse_yn) pulse_x=0;pulse_y=0 ; break; if(workstate=1 & flag=0) pulse_x=0;pulse_y=0 ; break; void forward_s(unsigned int m,unsigned int n) pulse_x=0; pulse_y=0; while(1) if(pulse_x=m & pulse_ym & pulse_y=n) PWM_right(13,413); if(pulse_xn) PWM_left(17,417); if(pulse_xm & pulse_yn) pulse_x=0;pulse_y=0 ; break; if(workstate=1 & flag=0) pulse_x=0;pulse_y=0 ; break; void forward_s2(unsigned int m,unsigned int n) pulse_x=0; pulse_y=0; while(1) if(pulse_x=m & pulse_ym & pulse_y=n) PWM_right(15,215); if(pulse_xn) PWM_left(15,215); if(pulse_xm & pulse_yn) pulse_x=0;pulse_y=0 ; break; if(workstate=1 & flag=0) pulse_x=0;pulse_y=0 ; break; /*后退*/void backward(unsigned int m,unsigned int n) pulse_x=0; pulse_y=0; while(1) if(pulse_x=m & pulse_ym & pulse_y=n) PWM_right(17,217); if(pulse_xn) PWM_left(13,213); if(pulse_xm & pulse_yn) pulse_x=0;pulse_y=0 ; break; if(workstate=1 & flag=0) pulse_x=0;pulse_y=0 ; break; /*左转*/void turn_left(unsigned int m) pulse_x=0; pulse_y=0; while(1) if(pulse_x=m & pulse_ym & pulse_y=m) PWM_right(13,413); if(pulse_xm) PWM_left(13,413) ; if(pulse_xm & pulse_ym) pulse_x=0;pulse_y=0 ; break; if(workstate=1 & flag=0) pulse_x=0;pulse_y=0 ; break; /*右转*/void turn_right(unsigned int m) pulse_x=0; pulse_y=0;while(1) if(pulse_x=m & pulse_ym & pulse_y=m) PWM_right(17,417); if(pulse_xm) PWM_left(17,417) ; if(pulse_xm & pulse_ym) pulse_x=0;pulse_y=0 ; break; if(workstate=1 & flag=0) pulse_x=0;pulse_y=0 ; break; /*停止*/void stop(void)*P_IOA_Data &=(bit13 + bit14); /将IOA13、IOA14清0 pulse_x=0; pulse_y=0;/*控制小车左轮*/void PWM_left(unsigned int high_time,unsigned int cyclical_time) if(left cyclical_time)left=0;pulse_x +; *P_Watchdog_Clear=0x0001;/*控制小车右轮*/void PWM_right(unsigned int high_time,unsigned int cyclical_time)if(right cyclical_time)right=0;pulse_y +; *P_Watchdog_Clear=0x0001;/*IRQ4中断*/void IRQ4(void) _attribute_ (ISR);void IRQ4(void)if(*P_INT_Ctrl & C_IRQ4_1KHz) *P_INT_Clear |=C_IRQ4_1KHz ; dd+; if(dd=100) /100ms检测一次 dd=0; biya(); if(*P_INT_Ctrl & C_IRQ4_2KHz) *P_INT_Clear |=C_IRQ4_2KHz ;else *P_INT_Clear |=C_IRQ4_4KHz; /*IRQ5中断*/void IRQ5(void) _attribute_ (ISR);void IRQ5(void)if(*P_INT_Ctrl & C_IRQ5_4Hz) /IRQ5_4HZ *P_INT_Clear |=C_IRQ5_4Hz ; bizhan(); /避障 else /IRQ5_2HZ *P_INT_Clear |=C_IRQ5_2Hz; hf(); /比较检测到AD的最小值 if(xp=0xc8)workstate=1;/ AD值达到200以内就认为发现火源。workstate=1进入检测范围 /*A/D转换*/void get_AD(void) unsigned int ak15; unsigned int i,j,temp,k,sum; unsigned int Line,AD_Data; *P_ADC_Ctrl=0x01; /允许转换 for(Line=1;Line7;Line+) *P_ADC_MUX_Ctrl=Line;/选择通道 AD_Data=*P_ADC_MUX_Data;/启动转换 for(i=0;i8 ; /右移8位,只取8高位数据 aki=AD_Data; for(i=0;i15;i+) /从小到大排序 for(j=i+1;jakj)temp=aki;aki=akj;akj=temp; sum=0; for(k=5;k10;k+) sum=sum+akk; chdataLine =sum/5; *P_Watchdog_Clear=0x01; /*/ void hf(void) unsigned int i,j,temp; get_AD();for(i=1;i=6;i+)paixui=chdatai;for(i=1;i=6;i+) for(j=i+1;jpaixuj)temp=paixui;paixui=paixuj;paixuj=temp; min=paixu1; /min 为单前这次检测到的最低值xp =xpmin ? xp:min ; /xp 为检测到的历史最低值if(0xC9xp & xp=0xFF) mm=1; if(0xA0xp & xp=0xC9) mm=2; if(0x90xp & xp=0xA0) mm=3;if(0x7Fxp & xp=0x90) mm=4; if(0x67xp & xp=0x7F) mm=5;if(0x50xp & xp=0x67) mm=6; if(0x3Fxp & xp=0x50) mm=7;if(0x0Fxp & xp=0x3F) mm=8; if(0x0Cxp & xp=0x0F) mm=9; if(0x08xp & xp=0x0C) mm=10; if(0x00xp & xp=0x08) mm=11;/*避崖程序*/ void biya(void ) if(!(*P_IOB_Data & 0x8000) /q1 1000 stop(); backward(20,20); turn_left(21); if(!(*P_IOB_Data & 0x4000) /q2 0100 stop(); backward(20,20); turn_left(21); if(!(*P_IOB_Data & 0xc000) /q12 1100 stop(); backward(20,20); turn_left(21); if(!(*P_IOB_Data & 0x2000) /h1 0010 stop(); forward(15,15); turn_left(10); if(!(*P_IOB_Data & 0x1000) /h2 0001 stop(); forward(15,15); turn_left(10); if(!(*P_IOB_Data & 0x3000) /h1 2 0011 stop(); forward(15,15); turn_left(10); else; /*避障程序*/ void bizhan(void ) if(Get_IOA_Data(12)=0 & Get_IOA_Data(11) =1 ) /zuobingbackward(15,15);while(Get_IOA_Data(12)=0) turn_right(30); forward(20,20); turn_left(21); if(Get_IOA_Data(11)=0 & Get_IOA_Data(12) =1 ) /youbingbackward(15,15);while(Get_IOA_Data(11)=0) turn_left(21); forward(20,20); turn_right(30); if(Get_IOA_Data(11)=0 & Get_IOA_Data(12) =0) backward(15,15); turn_left(21); forward(20,20); turn_right(30); /*延时子程序*/ void delay_s(unsigned int t ) / s级延时程序 unsigned int i; for(i=0;it;i+) delay_ms(1000); void delay_ms(unsigned int t) / ms级延时程序 Delaynumber=0; while(Delaynumber=10*t)*P_Watchdog_Clear=0x01; /没有延时完则继续等待 附录2 FIQ.asm.DEFINE P_INT_Ctrl 0x7010 / Control port for interrupt source.DEFINE P_INT_Clear 0x7011 / Clear interrupt source.DEFINE C_FIQ_TMB 0x0800 / Timer B FIQ.DEFINE C_FIQ_TMA 0x2000 / Timer A FIQ.DEFINE C_FIQ_PWM 0x8000 / PWM FIQ.external _left,_right,_Delaynumber.PUBLIC _IRQ0,_IRQ1,_IRQ2,_IRQ3,_IRQ6,_IRQ7,_BREAK.TEXT.PUBLIC _FIQ_FIQ:push r1,r5 to spr1 = C_FIQ_TMAtest r1,P_INT_Ctrljnz L_FIQ_TimerAr1 = C_FIQ_TMBtest r1,P_INT_Ctrljnz L_FIQ_TimerBL_FIQ_PWM:r1 = C_FIQ_PWMP_INT_Clear = r1pop r1,r5 from spretiL_FIQ_TimerA:P_INT_Clear = r1pop r1,r5 from spretiL_FIQ_TimerB:P_INT_Clear = r1 r2=_left r2 +=1 _left=r2 r3=_right r3 +=1 _right=r3 r4=_Delaynumber r4 +=1 _Delaynumber=r4 pop r1,r5 from spreti_IRQ0:reti_IRQ1: reti_IRQ2: reti_IRQ3: reti_IRQ6: reti_IRQ7: reti_BREAK: reti附录3 wei.h#defineP_IOA_Data(volatile unsigned int *)0x7000#defineP_IOB_Data(volatile unsigned int *)0x7005#ifndef_WEI_h_#define_WEI_h_/write your header here#define bit0 0x0001#define bit1 0x0002#define bit2 0x0004#define bit3 0x0008#define bit4 0x0010#define bit5 0x0020#define bit6 0x0040#define bit7 0x0080#define bit8 0x0100#define bit9 0x0200#define bit10 0x0400#define bit11 0x0800#define bit12 0x1000#define bit13 0x2000#define bit14 0x4000#define bit15 0x8000/*单独设置I/O的Data信息*voidSet_IOA_Data(unsigned int x,unsigned int y)switch(x)case 0:if(y=1)*P_IOA_Data|=0x0001;if(y=0)*P_IOA_Data&=0xfffe;break;case 1:if(y=1)*P_IOA_Data|=0x0002;if(y=0)*P_IOA_Data&=0xfffd;break;case 2: if(y=1)*P_IOA_Data|=0x0004; if(y=0)*P_IOA_Data&=0xfffb; break;case 3: if(y=1)*P_IOA_Data|=0x0008; if(y=0)*P_IOA_Data&=0xfff7; break;case 4:if(y=1)*P_IOA_Data|=0x0010;if(y=0)*P_IOA_Data&=0xffef;break;case 5:if(y=1)*P_IOA_Data|=0x0020;if(y=0)*P_IOA_Data&=0xffdf;break;case 6:if(y=1)*P_IOA_Data|=0x0040;if(y=0)*P_IOA_Data&=0xffbf;break;case 7:if(y=1)*P_IOA_Data|=0x0080;if(y=0)*P_IOA_Data&=0xff7f;break;case 8:if(y=1)*P_IOA_Data|=0x0100;if(y=0)*P_IOA_Data&=0xfeff;break;case 9:if(y=1)*P_IOA_Data|=0x0200;if(y=0)*P_IOA_Data&=0xfdff;break;case 10:if(y=1)*P_IOA_Data|=0x0400;if(y=0)*P_IOA_Data&=0xfbff;break;case 11:if(y=1)*P_IOA_Data|=0x0800;if(y=0)*P_IOA_Data&=0xf7ff;break;case 12:if(y=1)*P_IOA_Data|=0x1000;if(y=0)*P_IOA_Data&=0xefff;break;case 13:if(y=1)*P_IOA_Data|=0x2000;if(y=0)*P_IOA_Data&=0xdfff;break;case 14:if(y=1)*P_IOA_Data|=0x4000;if(y=0)*P_IOA_Data&=0xbfff;break;case 15:if(y=1)*P_IOA_Data|=0x8000;if(y=0)*P_IOA_Data&=0x7fff;break;voidSet_IOB
展开阅读全文