原理完全同红外避障

上传人:第*** 文档编号:38878240 上传时间:2018-05-08 格式:PDF 页数:13 大小:562.50KB
返回 下载 相关 举报
原理完全同红外避障_第1页
第1页 / 共13页
原理完全同红外避障_第2页
第2页 / 共13页
原理完全同红外避障_第3页
第3页 / 共13页
原理完全同红外避障_第4页
第4页 / 共13页
原理完全同红外避障_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《原理完全同红外避障》由会员分享,可在线阅读,更多相关《原理完全同红外避障(13页珍藏版)》请在金锄头文库上搜索。

1、原理完全同红外避障,区别是传感器的位置不同,程序略做修改.我用洞洞板固定红外反射传感器,红外线发射管用稍长热缩套管,目的是限制发射角度,可根据轨迹线的宽度和传感器高度而定.发射功率的调整是调节 38khz 载波的占空比,不需要改变电阻,而直接使用固定电阻,可靠性大大提高.现在我设置的占空比是 12.5%,发射电流不变,1.5ma,黑线用的是电工胶带,强烈吸收光线.白线就是地板.从实验效果看,3个传感器的安装位置相对黑线宽度过大,另外程序也很简陋,这引起小车左右调节幅度较大.视频地址:http:/ #include #include “STC12C5410AD.H“#include “sio.h

2、“#define MIN9MS 0x0120/9ms 中心是 0x0159#define MAX9MS 0x01a0#define MIN45MS 0x0090/4.5ms 中心是 0x00ac#define MAX45MS 0x00d0#define MIN225MS 0x0040/2.25ms 中心是 0x0056#define MAX225MS 0x0080#define MIN056MS 0x000e/0.56ms 中心是 0x0015#define MAX056MS 0x001b#define MIN168MS 0x0020/1.68ms 中心是 0x0040#define MAX1

3、68MS 0x0060sfr ISP_CUNTR = 0xE7;sbit LED1 = P11;sbit LED2 = P12;sbit IR_FRONT = P33;sbit IR_LEFT = P34;sbit IR_RIGHT = P35;sbit IR_BACK = P13;sbit IR_OUT = P10;sbit PWM0 = P37;sbit MOTO_IN_A1 = P17;sbit MOTO_IN_A2 = P16;sbit MOTO_IN_B1 = P15;sbit MOTO_IN_B2 = P14;bit power_stat;static unsigned char

4、car_stat; /小车状态:0,停止;1,前进;2,后退;3,左转;4,右转;ff,自控寻线模式static unsigned char code led_mod_table320 = 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0;unsigned char idata led_mod = 0;static unsigned char idata led_tick = 0;static unsign

5、ed char idata led_ptr = 0;#define IR_SIGNAL_TOTAL 21#define IR_SIGNAL_VALID 18static unsigned char code ir_tableIR_SIGNAL_TOTAL = 1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0;static unsigned char code ir_check_tableIR_SIGNAL_TOTAL = 0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0;static unsigned char idata i

6、r_ptr = 0;static unsigned char idata front_signal = 0;static unsigned char idata back_signal = 0;static unsigned char idata left_signal = 0;static unsigned char idata right_signal = 0;static bit front_obj = 0, back_obj = 0, left_obj = 0, right_obj = 0;static void delay(unsigned long v) while (v-) /*

7、 PCA 中断计数,根据位置判断信号区域和定义,位置 0 表示初始,1 代表引导码信号,2 表示引导码间隔,* 3 表示第一个 bit 的信号,4 表示第一个 bit 的间隔,以次类推.* 更具体见对应的红外线协议.*/static unsigned char idata pca_tick;static unsigned char idata pca_int_count;static unsigned char data pca_int_total;/* 根据引导头确定总长度 */static unsigned int idata period;/* 红外信号占或空周期计数 */static

8、unsigned char idata data_buf6; /* 红外线协议数据缓冲区 */static unsigned int idata ccap1;/PCA0 上一次的的计数static unsigned char idata frame_dog; /红外帧看门狗,限定时间未接收完成清除工作void time0_isr() interrupt 1unsigned char tmp;if (ir_tableir_ptr+) IR_OUT = 0; else IR_OUT = 1;ir_ptr %= IR_SIGNAL_TOTAL;tmp = ir_check_tableir_ptr;i

9、f (!IR_FRONT if (!IR_LEFT if (!IR_RIGHT if (!IR_BACK if (ir_ptr = 0) / com_putchar(front_signal);if (front_signal= IR_SIGNAL_VALID)front_obj = 1;elsefront_obj = 0;if (back_signal= IR_SIGNAL_VALID)back_obj = 1;elseback_obj = 0;if (left_signal= IR_SIGNAL_VALID)left_obj = 1;elseleft_obj = 0;if (right_s

10、ignal= IR_SIGNAL_VALID)right_obj = 1;elseright_obj = 0;front_signal = 0;back_signal = 0;left_signal = 0;right_signal = 0;void time0_initialize(void)TMOD /* clear timer 0 mode bits */TMOD |= 0x02;/* put timer 0 into MODE 2 */TH0 = 0x5C;/* 256 - XTAL*dur/T1_12/1000000, dur=定时器的周期,以 us 为单位*/TL0 = 0x5C;

11、/* 100us */PT0 = 0;/* 时钟 0 中断低优先级 */TR0 = 1;ET0 = 1;static void wakeup (void) interrupt 2static void pca_isr (void) interrupt 6unsigned char i, j;if (CCF1) CCF1 = 0; /清 PCA1 中断标志LED1 = IR_RIGHT;LED2 = IR_RIGHT;if (!pca_int_count) /第一次收到信号if (!IR_RIGHT) ccap1 = pca_tick * 256 + CCAP1H;pca_int_count+;

12、 else /已经收到一些信号period = pca_tick * 256 + CCAP1H - ccap1;ccap1 = pca_tick * 256 + CCAP1H;/com_putchar(period / 256);/com_putchar(period % 256);if (pca_int_count = 1) if (period MAX9MS) /9mspca_int_count = 0;frame_dog = 0; elsepca_int_count+; else if (pca_int_count = 2) if (period MIN225MS com_putchar

13、(data_buf2);if (data_buf0 = 0x40) switch (data_buf2) case 0x5F: /左car_stat = 3;break;case 0x5B: /右car_stat = 4;break;case 0x5A: /上car_stat = 1;break;case 0x5E: /下car_stat = 2;break;case 0x56: /菜单car_stat = 0;break;case 0x0: /数字 0car_stat = 0xff;break;case 0x12: /POWER/ power_stat = power_stat;break;

14、default:break; else /重复信号,仅含有引导信号pca_int_count = 0;frame_dog = 0; else pca_int_count+; else pca_int_count = 0;frame_dog = 0; else j= (pca_int_count - 3) / 2;i= j / 8;j= j % 8;if (period MIN168MS if (led_mod_tableled_modled_ptr+) LED1 = 0;LED2 = 0; else LED1 = 1;LED2 = 1;led_ptr %= 20;if (pca_int_cou

15、nt) frame_dog+;if (frame_dog= 15) /100ms 后重新开始分析新的红外线数据包pca_int_count = 0;frame_dog = 0;void auto_power_down() delay(30000);ISP_CUNTR = 0x20; /从 AP 复位并从 AP 执行void main (void)unsigned char i;unsigned long j;MOTO_IN_A1 = 0;MOTO_IN_A2 = 0;MOTO_IN_B1 = 0;MOTO_IN_B2 = 0;P1M1 = 0xf0; /P1.7P1.4 强推挽输出EA = 0;power_stat = 0;time0_initialize();com_initialize ();/* initialize interrupt driven serial I/O */com_baudrate (4800); /* setup for 1200 baud */*CMOD = 0x01;/ #00000000B,PCA空闲计数,PCA计数源=Fosc/12

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 工程造价

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号