• 博客(0)
  • 资源 (1)

空空如也

智能小车的制作

c程序/******************************************************************************** * 描述: * * lcd1602显示 遥控键值读取器 * * lcd1602显示 遥控器接p3.2 * * 喇叭接p1.5 继电器接p1.4 * * 17(40h)键按下,继电器吸合。19(04h)键按下,继电器关闭。 * * 连接方法:使用红外功能时 J1跳线短接 * ********************************************************************************/ #include <reg51.h> #include <intrins.h> #define uchar unsigned char #define uint unsigned int void delayus (uint us);//电机延时程序 void dianji(); //电机驱动 sbit key1=P2^0; sbit key2=P2^1; sbit key3=P2^2; sbit key4=P2^3; sbit key5=P2^4; sbit key6=P2^5; sbit led=P3^0; sbit led1=P3^1; uchar code zheng[48]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9,0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9,0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9,0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9,0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9,0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9};//电机正转表 uchar code fan[48]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1,0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1,0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1,0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1,0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1,0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1};//电机反转表 uchar Y0; uchar flag=0; /*******************************************************************/ void main() { led=1; led1=0; while(1)dianji(); } void delayus (uint us) { uint i,j; for (i=0;i<us;i++) for (j=0;j<12;j++); } void dianji() { uchar i; while (key3==0)//步进电机正转 { for (i=0;i<48;i++) { P1=zheng[i]; delayus(11); } } while (key4==0)//步进电机反转 { for (i=0;i<48;i++) { P1=fan[i]; delayus(10); } } while(key1==0)//直流电机后退 { led=0; led1=0; } while(key2==0)//直流电机前进 { led=1; led1=1; } while(key5==0)//直流电机前进 { led=0; led1=1; delayus(10); } }

2013-06-08

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除