智能小车的四路避障 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 中心是0x0056 #define MAX225MS 0x0080 #define MIN056MS 0x000e //0.56ms 中心是0x0015 #define MAX056MS 0x001b #define MIN168MS 0x0020 //1.68ms 中心是0x0040 #define MAX168MS 0x0060 sfr ISP_CUNTR = 0xE7; sbit LED1 = P1^1; sbit LED2 = P1^2; sbit IR_FRONT = P3^3; sbit IR_LEFT = P3^4; sbit IR_RIGHT = P3^5; sbit IR_BACK = P1^3; sbit IR_OUT = P1^0; sbit PWM0 = P3^7; sbit MOTO_IN_A1 = P1^7; sbit MOTO_IN_A2 = P1^6; sbit MOTO_IN_B1 = P1^5; sbit MOTO_IN_B2 = P1^4; bit power_stat; static unsigned char car_stat; //小车状态:0,停止;1,前进;2,后退;3,左转;4,右转;ff,自控寻线模式 static unsigned char code led_mod_table[3][20] = { {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 unsigned char idata led_ptr = 0; #define IR_SIGNAL_TOTAL 21 #define IR_SIGNAL_VALID 18 static unsigned char code ir_table[IR_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_table[IR_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 unsigned char idata right_signal = 0; static bit front_obj = 0, back_obj = 0, left_obj = 0, rig...