- #include "stm32f10x.h"
- #include "led.h"
- #include "delay.h"
- #include "pwm.h"
- #include "l298n.h"
- #include "bizhang.h"
- int main(void)
- {
- KEY_Init();
- delay_init();
- LED_Init();
- L298N_Init();
- TIM3_PWM_Init(899,0);
-
- while(1)
- {
-
- if(KEY1==0)
- {
- qianjin();
-
-
- }
- else
- {
- houtui();
-
- }
-
- }
- }
復(fù)制代碼- #include "l298n.h"
- #include "pwm.h"
- void L298N_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//使能時(shí)鐘
-
-
- GPIO_InitStructure.GPIO_Mode= GPIO_Mode_Out_PP;//設(shè)置GPIO工作模式GPIO_Mode_Out_PP是推挽輸出
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;//確定那一個(gè)IO口
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//設(shè)置速度
- GPIO_Init(GPIOB,&GPIO_InitStructure);//確定那一組IO口
- }
- void qianjin(void)
- {
- TIM_SetCompare3(TIM3,500);
- TIM_SetCompare4(TIM3,500);
- IN1 =0;
- IN2 =1;
- IN3 =0;
- IN4 =1;
- }
- void houtui(void)
- {
-
- IN1 =1;
- IN2 =0;
- IN3 =1;
- IN4 =0;
- }
- void zuozhuan(void)
- {
- IN1=0;
- IN2=1;
- IN3=1;
- IN4=0;
- }
- void youzhuan(void)
- {
- IN1=1;
- IN2=0;
- IN3=0;
- IN4=1;
- }
- void shache()
- {
- IN1=1;
- IN2=1;
- IN3=1;
- IN4=1;
- }
復(fù)制代碼
Keil代碼下載:
L298N代碼.7z
(179.26 KB, 下載次數(shù): 67)
2021-11-3 04:40 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|