ImageVerifierCode 换一换
格式:DOCX , 页数:9 ,大小:17.84KB ,
资源ID:6175460      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6175460.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(智能小车的四路避障C程序.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

智能小车的四路避障C程序.docx

1、智能小车的四路避障C程序智能小车的四路避障C程序默认分类 2009-08-24 10:35 阅读164评论4 字号: 大大 中中 小小 前,左,后避障传感器现在对应中,右,左三路寻线传感器. #include #include #include STC12C5410AD.H#include sio.h#define MIN9MS 0x0120 /9ms中心是0x0159#define MAX9MS 0x01a0#define MIN45MS 0x0090 /4.5ms中心是0x00ac#define MAX45MS 0x00d0#define MIN225MS 0x0040 /2.25ms中心

2、是0x0056#define MAX225MS 0x0080#define MIN056MS 0x000e /0.56ms中心是0x0015#define MAX056MS 0x001b#define MIN168MS 0x0020 /1.68ms中心是0x0040#define MAX168MS 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 =

3、 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 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

4、,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 unsigned 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

5、,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 ir_ptr = 0;static unsigned char idata front_signal = 0;static unsigned char idata back_signal = 0;static unsigned char idata left_signal = 0;static unsign

6、ed 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-) /* * PCA中断计数,根据位置判断信号区域和定义,位置0表示初始,1代表引导码信号,2表示引导码间隔,* 3表示第一个bit的信号,4表示第一个bit的间隔,以次类推.* 更具体见对应的红外线协议.*/static unsigned char idata pca_tick;static unsigned

7、char idata pca_int_count;static unsigned char data pca_int_total; /* 根据引导头确定总长度 */static unsigned int idata period; /* 红外信号占或空周期计数 */static unsigned char idata data_buf6; /* 红外线协议数据缓冲区 */static unsigned int idata ccap1; /PCA0上一次的的计数static unsigned char idata frame_dog; /红外帧看门狗,限定时间未接收完成清除工作void time

8、0_isr() interrupt 1 unsigned char tmp; if (ir_tableir_ptr+) IR_OUT = 0; else IR_OUT = 1; ir_ptr %= IR_SIGNAL_TOTAL; tmp = ir_check_tableir_ptr; if (!IR_FRONT & tmp) | (IR_FRONT & !tmp) front_signal+; if (!IR_LEFT & tmp) | (IR_LEFT & !tmp) left_signal+; if (!IR_RIGHT & tmp) | (IR_RIGHT & !tmp) right_

9、signal+; if (!IR_BACK & tmp) | (IR_BACK & !tmp) back_signal+; if (ir_ptr = 0) / com_putchar(front_signal); if (front_signal = IR_SIGNAL_VALID) front_obj = 1; else front_obj = 0; if (back_signal = IR_SIGNAL_VALID) back_obj = 1; else back_obj = 0; if (left_signal = IR_SIGNAL_VALID) left_obj = 1; else

10、left_obj = 0; if (right_signal = IR_SIGNAL_VALID) right_obj = 1; else right_obj = 0; front_signal = 0; back_signal = 0; left_signal = 0; right_signal = 0; void time0_initialize(void) TMOD &= 0x0F; /* clear timer 0 mode bits */ TMOD |= 0x02; /* put timer 0 into MODE 2 */ TH0 = 0x5C; /* 256 - XTAL*dur

11、/T1_12/1000000, dur=定时器的周期,以us为单位*/ TL0 = 0x5C; /* 100us */ PT0 = 0; /* 时钟0中断低优先级 */ TR0 = 1; ET0 = 1;static void wakeup (void) interrupt 2static void pca_isr (void) interrupt 6 unsigned char i, j; if (CCF1) CCF1 = 0; /清PCA1中断标志 LED1 = IR_RIGHT; LED2 = IR_RIGHT; if (!pca_int_count) /第一次收到信号 if (!IR_

12、RIGHT) ccap1 = pca_tick * 256 + CCAP1H; pca_int_count+; 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) /9ms pca_int_count = 0; frame_dog = 0; else pca_int_count+

13、; else if (pca_int_count = 2) if (period MIN225MS & period MIN45MS & period MIN056MS & period = pca_int_total) /帧接收完毕,下面进行有效分析. if (pca_int_total = 67) /完整信号,含有引导信号,设备码8bit,设备反码8bit,命令字8bit,命令字反码8bit if (data_buf0 data_buf1 = 0xff) & (data_buf2 data_buf3 = 0xff) com_putchar(data_buf0); com_putchar(d

14、ata_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: /数字0 car_stat = 0xff; break; case 0x12: /POWER / power_stat =

15、power_stat; break; 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 & period MAX168MS) /1.68ms / com_putchar(0x01); data_buf |= (0x01 MIN056MS &

16、 period MAX056MS) /0.56ms / com_putchar(0x00); data_buf &= (0x01 = 10) led_tick = 0; if (led_mod_tableled_modled_ptr+) LED1 = 0; LED2 = 0; else LED1 = 1; LED2 = 1; led_ptr %= 20; if (pca_int_count) frame_dog+; if (frame_dog = 15) /100ms后重新开始分析新的红外线数据包 pca_int_count = 0; frame_dog = 0; void auto_powe

17、r_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/

18、O */ com_baudrate (4800); /* setup for 1200 baud */* CMOD = 0x01; / #00000000B,PCA空闲计数,PCA计数源=Fosc/12,PCA溢出中断(做一个定时器使用) CCON = 0x00; /PCA中断标志清0,PCA停止计数 CL = 0x0; CH = 0x0; CCAPM1 = 0x31; /PCA1上升下降沿捕获*/ CMOD = 0x03; /* #00000010B,PCA空闲计数,PCA计数源=fosc/2,PCA溢出中断 */ CCON = 0x00; /PCA中断标志清0,PCA停止计数 CL = 0x0; CH = 0x0; CCAPM1 = 0x31; /PCA1上升下降沿捕获 CCAPM0 = 0x42; /PCA0工作模式:8位pwm P

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1