L298N驱动电机程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includereg51.h#definesen_portP1sbitSEN1=P1^0;sbitSEN2=P1^1;sbitEN1=P2^2;sbitA1=P1^1;sbitA2=P1^2;sbitEN2=P2^5;sbitB1=P1^3;SbitB2=P1^4;voiddelay(intn)//延时子程序{unsignedchari,j,k;for(i=n;i0;i--)for(j=100;j0;j--)for(k=200;k0;k--);}unsignedcharsensor_inp(){unsignedcharsensor;sensor=sen_port;sensor&=0x03;P0=sensor;returnsensor;}voidforward()//twomotosareruningforward{IN1=1;IN2=0;IN3=1;IN4=0;EN1=1;EN2=1;}voidbackward()//twomotosareruningbackward{IN1=0;IN2=1;IN3=0;IN4=1;EN1=1;EN2=1;}voidturn_left()//leftmotoisruning,butrightmotoisbrake{IN1=1;IN2=0;IN3=0;IN4=0;EN1=1;EN2=1;}voidrotate_left()//rightmotoisruningforward,andleftmotoisrunningbackward{IN1=1;IN2=0;IN3=0;IN4=1;EN1=1;EN2=1;}voidturn_right()//rightmotoisruning,butleftmotoisbrake{IN1=0;IN2=0;IN3=1;IN4=0;EN1=1;EN2=1;}voidrotate_right()//leftmotoisrunningforward,andrightmotoisrunningbackward{IN1=0;IN2=1;IN3=1;IN4=0;EN1=1;EN2=1;}voidfree()//twomotosisfree{IN1=0;IN2=0;IN3=0;IN4=0;EN1=0;EN2=0;}voidstop()//twomotosstop{IN1=1;IN2=1;IN3=1;IN4=1;EN1=1;EN2=1;}voidmain(void){delay(10);P0=0x55;while(1){//P0=P1;//delay(100);forward();//delay(100);stop();delay(100);backward();delay(100);stop();delay(100);turn_left();delay(100);stop();delay(100);turn_right();delay(100);stop();delay(100);rotate_left();delay(100);stop();delay(100);rotate_right();delay(100);stop();delay(100);stop();delay(20);forward();delay(20);backward();delay(20);/**/}}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功