欢迎来到天天文库
浏览记录
ID:39640072
大小:32.50 KB
页数:7页
时间:2019-07-08
《寻轨小车程序=》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedintucharpwm;uchara;voidforward(); //前voidturnleft(); //左voidturnright(); //右voidstop(); //停 sbitm1z=P2^0; //定义电机端口(高电平有效)sbitm1f
2、=P2^1;sbitm2z=P2^2;sbitm2f=P2^3;sbitd1=P2^4; //定义灯端口sbitd2=P2^5;sbitd3=P2^6; //定义红反射外传感器端口(反射白色面时为高电平,反射黑色面或无反射时为低电平)sbithwcg1=P1^0;sbithwcg2=P1^1;sbithwcg3=P1^2;/*-----------------------------------------------------------------------------------------------*/voidms(c)
3、 //PWM{uintb;while(c--){for(b=0;b<500;b++);}}/*-------------------------------------------------------------------------------------------------- 初始化-------------------------------------------------------------------
4、---------------------------------*/voiddelay_ms(uintc) //延时程序{while(c--){uchara;for(a=0;a<123;a++);}}voidinit_all(void) //初始化程序{ P1=0x00; P2=0x00;delay_ms(6000);}/*-------------------------------------------------------------------------------------
5、----------- 前后左右电机转法 -------------------------------------------------------------------------------------------------*/voidforward() //向前{if(hwcg1==1&&hwcg2==0&&hwcg3==1){ P2=0X30; delay_m
6、s(10); if(hwcg1==1&&hwcg2==0&&hwcg3==1) { m1z=m2z=0xff; ms(4); m1z=m2z=0x00; ms(2); while(hwcg1==1&&hwcg2==0&&hwcg3==1) { m1z=m2z=0xff; ms(2); m1z=m2z=0x00; ms(3); } } }}voidrecede() //向后{if(hwcg1==1&&hwcg2==1&&hwcg3==1){ P2=0
7、X30; delay_ms(10); if(hwcg1==1&&hwcg2==1&&hwcg3==1) { m1f=m2f=0xff; ms(4); m1f=m2f=0x00; ms(2); while(hwcg1==1&&hwcg2==1&&hwcg3==1) { m1f=m2f=0xff; ms(3); m1f=m2f=0x00; ms(3); }} }}/*-------------------------------------------------------------------
8、-------------------
此文档下载收益归作者所有