完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
//头文件
#include "stm32f10x.h" #include "usart.h" #include "led.h" #include "RTC_Time.h" #include #include "delay.h" //============================================================================= //函数名称:Delay //功能概要:延时函数 //参数说明:无 //函数返回:无 //============================================================================= //============================================================================= //函数名称:main //功能概要:主函数 //参数说明:无 //函数返回:int //============================================================================= #define uchar unsigned char #define uint unsigned int void motor3(void); void motor4(void); u16 moto0_time=11000; //电机1的运行时间 u16 moto1_time=2000; //电机2的运行时间 void Delay1 (uint32_t nCount) { for(; nCount != 0; nCount--); } void delay1_ms(u16 time) { u16 i=0; while(time--) { i=12000; while(i--) ; } } int main(void) { u8 k=0; //初始化LED USART1_Config(); LED_GPIO_Config(); while (1) { LED0_OFF; if(KEY0==0) //正转按钮 { Delay1(0x00FFFF); //motor1( ); motor3( ); MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF; MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_OFF; k=1; } if(KEY1==0) //反转按钮 { Delay1(0x00FFFF); //motor2( ); motor4(); MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF; MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_OFF; k=0; } } } //正转函数 void motor3(void) { u8 j=0; u16 i; for(i=0;i { switch(j) { case 0:{ { MOTOR_A1_ON; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_ON;} if(i { MOTOR_A_ON; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_ON;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 1:{ {MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_ON;} if(i {MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_ON;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 2:{ { MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_ON; MOTOR_D1_ON;} if(i { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_ON; MOTOR_D_ON;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 3:{ {MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_ON; MOTOR_D1_OFF;} if(i {MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_ON; MOTOR_D_OFF;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 4:{ {MOTOR_A1_OFF; MOTOR_B1_ON; MOTOR_C1_ON; MOTOR_D1_OFF;} if(i {MOTOR_A_OFF; MOTOR_B_ON; MOTOR_C_ON; MOTOR_D_OFF;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 5:{ { MOTOR_A1_OFF; MOTOR_B1_ON; MOTOR_C1_OFF; MOTOR_D1_OFF;} if(i { MOTOR_A_OFF; MOTOR_B_ON; MOTOR_C_OFF; MOTOR_D_OFF;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 6:{ { MOTOR_A1_ON; MOTOR_B1_ON; MOTOR_C1_OFF; MOTOR_D1_OFF;} if(i { MOTOR_A_ON; MOTOR_B_ON; MOTOR_C_OFF; MOTOR_D_OFF;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 7:{ { MOTOR_A1_ON; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_OFF;} if(i { MOTOR_A_ON; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; } j++; if(j>=8) j=0; Delay1(0x01222); //delay1_ms(1); } } //反转函数 void motor4(void) { u8 j; u16 i; j=0; for(i=0;i { switch(j) { case 0:{ { MOTOR_A1_ON; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_OFF;} if(i { MOTOR_A_ON; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 1:{ { MOTOR_A1_ON; MOTOR_B1_ON; MOTOR_C1_OFF; MOTOR_D1_OFF;} if(i {MOTOR_A_ON; MOTOR_B_ON; MOTOR_C_OFF; MOTOR_D_OFF;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 2:{ { MOTOR_A1_OFF; MOTOR_B1_ON; MOTOR_C1_OFF; MOTOR_D1_OFF;} if(i {MOTOR_A_OFF; MOTOR_B_ON; MOTOR_C_OFF; MOTOR_D_OFF;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 3:{ { MOTOR_A1_OFF; MOTOR_B1_ON; MOTOR_C1_ON; MOTOR_D1_OFF;} if(i {MOTOR_A_OFF; MOTOR_B_ON; MOTOR_C_ON; MOTOR_D_OFF;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 4:{ { MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_ON; MOTOR_D1_OFF;} if(i { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_ON; MOTOR_D_OFF; } else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 5:{ { MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_ON; MOTOR_D1_ON;} if(i { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_ON; MOTOR_D_ON;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 6:{ { MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_ON;} if(i { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_ON;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; case 7:{ {MOTOR_A1_ON; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_ON;} if(i { MOTOR_A_ON; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_ON;} else { MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_OFF;} };break; } j++; if(j>=8) j=0; Delay1(0x01222); // delay1_ms(2); } LED0_ON; } /* 四拍 void motor1(void) 反转 { u8 j; u16 i; j=0; for(i=0;i<1000;i++) { switch(j) { case 0:{MOTOR_A_ON; MOTOR_B_ON; MOTOR_C_OFF; MOTOR_D_OFF; MOTOR2_A_ON; MOTOR2_B_ON; MOTOR2_C_OFF; MOTOR2_D_OFF;};break; case 1:{MOTOR_A_OFF; MOTOR_B_ON; MOTOR_C_ON; MOTOR_D_OFF; MOTOR2_A_OFF; MOTOR2_B_ON; MOTOR2_C_ON; MOTOR2_D_OFF;};break; case 2:{MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_ON; MOTOR_D_ON; MOTOR2_A_OFF; MOTOR2_B_OFF; MOTOR2_C_ON; MOTOR2_D_ON;};break; case 3:{MOTOR_A_ON; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_ON; MOTOR2_A_ON; MOTOR2_B_OFF; MOTOR2_C_OFF; MOTOR2_D_ON;};break; } j++; if(j>=4) j=0; //delay_ms(10); Delay1(0x003FFF); } LED0_ON; } void motor2(void) 正转 { u8 j; u16 i; j=0; for(i=0;i<1000;i++) { switch(j) { case 0:{MOTOR_A_ON; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_ON; MOTOR2_A_ON; MOTOR2_B_OFF; MOTOR2_C_OFF; MOTOR2_D_ON;};break; case 1:{MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_ON; MOTOR_D_ON; MOTOR2_A_OFF; MOTOR2_B_OFF; MOTOR2_C_ON; MOTOR2_D_ON;};break; case 2:{MOTOR_A_OFF; MOTOR_B_ON; MOTOR_C_ON; MOTOR_D_OFF; MOTOR2_A_OFF; MOTOR2_B_ON; MOTOR2_C_ON; MOTOR2_D_OFF;};break; case 3:{MOTOR_A_ON; MOTOR_B_ON; MOTOR_C_OFF; MOTOR_D_OFF; MOTOR2_A_ON; MOTOR2_B_ON; MOTOR2_C_OFF; MOTOR2_D_OFF;};break; } j++; if(j>=4) j=0; //delay_ms(5); Delay1(0x003FFF); } } */ /* 八拍加四拍混合 void motor5(void) 反转 { u8 j; u16 i; j=0; for(i=0;i<2000;i++) { switch(j) { case 0:{MOTOR_A1_ON; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_OFF;};break; case 1:{MOTOR_A1_ON; MOTOR_B1_ON; MOTOR_C1_OFF; MOTOR_D1_OFF;};break; case 2:{MOTOR_A1_OFF; MOTOR_B1_ON; MOTOR_C1_OFF; MOTOR_D1_OFF;};break; case 3:{MOTOR_A1_OFF; MOTOR_B1_ON; MOTOR_C1_ON; MOTOR_D1_OFF;};break; case 4:{MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_ON; MOTOR_D1_OFF;};break; case 5:{MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_ON; MOTOR_D1_ON;};break; case 6:{MOTOR_A1_OFF; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_ON;};break; case 7:{MOTOR_A1_ON; MOTOR_B1_OFF; MOTOR_C1_OFF; MOTOR_D1_ON;};break; case 8:{MOTOR_A_ON; MOTOR_B_ON; MOTOR_C_OFF; MOTOR_D_OFF; MOTOR2_A_ON; MOTOR2_B_ON; MOTOR2_C_OFF; MOTOR2_D_OFF;};break; case 9:{MOTOR_A_OFF; MOTOR_B_ON; MOTOR_C_ON; MOTOR_D_OFF; MOTOR2_A_OFF; MOTOR2_B_ON; MOTOR2_C_ON; MOTOR2_D_OFF;};break; case 10:{MOTOR_A_OFF; MOTOR_B_OFF; MOTOR_C_ON; MOTOR_D_ON; MOTOR2_A_OFF; MOTOR2_B_OFF; MOTOR2_C_ON; MOTOR2_D_ON;};break; case 11:{MOTOR_A_ON; MOTOR_B_OFF; MOTOR_C_OFF; MOTOR_D_ON; MOTOR2_A_ON; MOTOR2_B_OFF; MOTOR2_C_OFF; MOTOR2_D_ON;};break; } j++; if(j>=8) j=0; Delay1(0x002FEE); // delay1_ms(2); } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1537 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1490 浏览 1 评论
909 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
653 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1537 浏览 2 评论
1843浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
593浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
496浏览 3评论
494浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
475浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-5 04:17 , Processed in 0.826555 second(s), Total 78, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号