MG996R舵机控制

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

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

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

资源描述

#includereg52.hsbitLED1=P0^0;sbitDJ=P0^0;sbitkey1=P0^1;sbitkey2=P0^2;sbitkey3=P0^3;sbitkey4=P0^4;sbitkey5=P0^5;voidDelay05ms()//@24.000MHz{unsignedchari,j;i=2;j=239;do{while(--j);}while(--i);}voidDelay175ms()//@24.000MHz{unsignedchari,j;i=69;j=20;do{while(--j);}while(--i);}voidDelay18ms()//@24.000MHz{unsignedchari,j;i=71;j=6;do{while(--j);}while(--i);}voidDelay185ms()//@24.000MHz{unsignedchari,j;i=72;j=249;do{while(--j);}while(--i);}voidDelay19ms()//@24.000MHz{unsignedchari,j;i=74;j=235;do{while(--j);}while(--i);}voidright45(){while(1){DJ=1;Delay05ms();Delay05ms();DJ=0;Delay19ms();if(key4!=0){Delay05ms();if(key4!=0)break;}}}voidright90(){while(1){DJ=1;Delay05ms();DJ=0;Delay19ms();Delay05ms();if(key4!=0){Delay05ms();if(key4!=0)break;}}}voidleft45(){while(1){DJ=1;Delay05ms();Delay05ms();Delay05ms();Delay05ms();DJ=0;Delay18ms();if(key2!=0){Delay05ms();if(key2!=0)break;}}}voidleft90(){while(1){DJ=1;Delay05ms();Delay05ms();Delay05ms();Delay05ms();Delay05ms();DJ=0;Delay175ms();if(key5!=0){Delay05ms();if(key5!=0)break;}}}voidmiddle(){while(1){DJ=1;Delay05ms();Delay05ms();Delay05ms();DJ=0;Delay185ms();if(key3!=0){Delay05ms();if(key3!=0)break;}}}voidmain(){while(1){if(key1==0)left90();if(key2==0)left45();if(key3==0)middle();if(key4==0)right45();if(key5==0)right90();}}

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

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

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

×
保存成功