文档详情

51单片机无基于线遥控小车设计毕业设计论文.doc

发布:2018-06-21约1.29万字共36页下载文档
文本预览下载声明
51单片机无基于线遥控小车设计毕业设计(论文) #include void delay_nus unsigned int i //延时,单片机为STC10F08XE i i*10/12; while --i ; void Hardware_delay_1ms void TMOD 0xF0; TMOD | 0x01; //T0--16位定时器器模 TH0 0xFC; TL0 0x18; //64536 TF0 0; //清除定时器溢出标志 TR0 1; //启动定时器 while TF0 0 ;//等待计数完成 TR0 0; //停止定时器 void delay_nms int n int j; for j n;j 0;j-- Hardware_delay_1ms ; int P3_5state void return P30x20 ?1:0; //返回P1_2的状态 int main void int counter; int irDetectLeft; uart_Init ; //串口初始化 printf Program Running!\n ; while 1 for counter 0;counter 38;counter++ P2_3 1; //红外发射约38.5 kHz 的红外光 delay_nus 13 ; P2_3 0; delay_nus 13 ; irDetectLeft P3_5state ; //将返回的状态给irDetectLeft printf irDetectLeft %d\n,irDetectLeft ; delay_nms 100 ; 说明: 保持机器人与串口线的连接; 在红外检测电路前放一个物体,比如手或一张纸,距离左侧IR组大约2到3厘米; 当放一个物体在IR组前时,串口调试助手会显示“irDetecfLeft 0”,将物体移开时,它会显示“irDetectLeft 1”; 调整红外检测器的角度,尽量使其与地面垂直; 测试的结果如下图示: 测试结果 红外避障程序 #include #define LeftIR P1_2 //左边红外接收连接到P1_2 #define RightIR P3_5 //右边红外接收连接到P3_5 #define LeftLaunch P1_3 //左边红外发射连接到P1_3 #define RightLaunch P3_6 //右边红外发射连接到P3_6 void delay_nus unsigned int i i i*10/12; while --i ; void Hardware_delay_1ms void TMOD 0xF0; TMOD | 0x01; //T0――16位定时器器模 TH0 0xFC; TL0 0x18; //64536 TF0 0; //清除定时器溢出标志 TR0 1; //启动定时器 while TF0 0 ;//等待计数完成 TR0 0; //停止定时器 void delay_nms int n //延时ms int j; for j n;j 0;j-- Hardware_delay_1ms ; void IRLaunch unsigned char IR int counter; if IR L //左边发射 for counter 0;counter 38;counter++ LeftLaunch 1; delay_nus 13 ; LeftLaunch 0; delay_nus 13 ; if IR R //右边发射 for counter 0;counter 38;counter++ RightLaunch 1; delay_nus 13 ; RightLaunch 0; delay_nus 13 ; void Forward void //向前行走子程序 P1_1 1; delay_nus 1700 ; P1_1 0; P1_0 1; delay_nus 1300 ;
显示全部
相似文档