52智能小车+红外遥控+超声波,红外避障+PWM波调速度+超声波测距+测小车行驶速度,距离+红外循迹
单片机源程序如下:
- /***************************************
- 《智能小车》
- 作者: 欢。
- 功能: 红外遥控
- 超声波,红外避障
- PWM波调速度
- 超声波测距
- 测小车行驶速度,行走路程
- 红外循迹
-
- *****************************************/
- #include "reg52.h"
- #include "CarControl.h"
- #include "lcd1602.h"
- #include "SuperWave.h"
- #include "IRLED.h"
- #include "MeasureSpeed.h"
- #define uchar unsigned char
- #define uint unsigned int
- sfr IPH = 0XB7;//优先级配置寄存器
- sbit IRIN = P3^3; //红外接收器数据线
- extern uchar IRLedValue ;//红外遥控器值
- extern bit RedTracking;//是否循迹
- bit IsCarRunning=0;//车是否在跑
- /***************************************
-
- 定时器0:计数器模式,用于计算码盘脉冲个数
- 定时器1:定时器模式,用于计算超声波距离
- 定时器2:定时器模式,产生PWM波
- 外部中断0:红外接收中断
- 优先级:
- 外部中断0 > 定时器2 > 定时器1 > 定时器0
- *****************************************/
- void main()
- {
- PT0=1; //提升外部中断1高于定时器0
- IPH|=0x22;//提升定时器2优先级仅次于外部中断1
- PWMinit();
- LCD_Init();
- SuperWave_Init();
- IRLED_Init();
- MeasureSpeed_Init_T0();
- LCD_Write_String(0,0,"Num: ");
- while(1)
- {
- if(RedTracking == 0)
- {
- SuperWave_GetCount();
- }
- else
- {
- Tracking();
- }
- }
- }
复制代码
所有资料51hei提供下载:
智能遥控小车.rar
(70.91 KB, 下载次数: 99)
|