標題: stm32平衡小車程序 [打印本頁]

作者: wanlong    時間: 2019-5-8 22:19
標題: stm32平衡小車程序
/******************** (C) COPYRIGHT (2015)BST BALANCECAR **************************
* 文件名  :main.c
**********************************************************************************/
#include "stm32f10x.h"
#include "mpu6050.h"
#include "i2c_mpu6050.h"
#include "motor.h"
#include "24l01.h"      
#include "SysTick.h"
#include "led.h"
#include "usart.h"
#include "i2c.h"
#include "outputdata.h"
#include "timer.h"
#include "Lcd_Driver.h"
#include "main.h"
#include "key.h"
#include "delay.h"
#include "GUI.h"
#include "stdio.h"
#include "pwm.h"
//#include "motor.h"
//PA0,PA1,PA2,PA3 PWM輸出  PB13,PB15,接顯示屏       key1:PB5  key2:PB6   key3:PB7    P波分度值為1000,初始為0
//電機驅動  PB0 PB1 PB10 PB11
//key1  切換  key2  +     key3    -
int Compare1=0,Compare2=0,Compare3=0,Compare4=0;//改變占空比 ,分度值是1000



float pwm1,pwm2,pwm3,pwm4;
unsigned char string_pwm1[20],string_pwm2[20],string_pwm3[20],string_pwm4[20],string_compare13[20],string_compare24[20],string_key_flag[20];
extern int _200ms;
extern void moto_GPIO_Init();
int key_flag=0;
int main()
{     
   
     delay_init(72);//Delay init.
  TIM2_PWM_Init();
   Key_Init();
    Lcd_Init();
    LCD_LED_SET;
    SysTick_Config(SystemCoreClock/1000);
        Gui_DrawFont_GBK16(0,130,RED,GRAY0, "QQ:2534656669");   
      Lcd_Clear(WHITE);
   moto_GPIO_Init();
      GPIO_SetBits(GPIOB,GPIO_Pin_0);
        GPIO_SetBits(GPIOB,GPIO_Pin_1);
        GPIO_SetBits(GPIOB,GPIO_Pin_10);
        GPIO_SetBits(GPIOB,GPIO_Pin_11);
   
    while(1)
{
    pwm1=(Compare1/20000.0)*100,pwm2=(Compare2/20000.0)*100,    pwm3=(Compare3/20000.0)*100,    pwm4=(Compare4/20000.0)*100;
  TIM_SetCompare1(TIM2,Compare1);
  TIM_SetCompare2(TIM2,Compare2);
  TIM_SetCompare3(TIM2,Compare3);
  TIM_SetCompare4(TIM2,Compare4);
  sprintf(string_pwm1,"pwm1:%.3f",pwm1);
    sprintf(string_pwm2,"pwm2:%.3f",pwm2);
    sprintf(string_pwm3,"pwm3:%.3f",pwm3);
    sprintf(string_pwm4,"pwm4:%.3f",pwm4);
  sprintf(string_key_flag,"key_flag:%d",key_flag);
    Gui_DrawFont_GBK16(0,0,RED,GRAY0,string_pwm1);   
    Gui_DrawFont_GBK16(0,20,RED,GRAY0,string_pwm2);
    Gui_DrawFont_GBK16(0,40,RED,GRAY0,string_pwm3);
    Gui_DrawFont_GBK16(0,60,RED,GRAY0,string_pwm4);
  Gui_DrawFont_GBK16(0,80,RED,GRAY0,string_key_flag);
}
   
}




恒溫屋.7z

280.82 KB, 下載次數(shù): 7, 下載積分: 黑幣 -5


作者: admin    時間: 2019-5-9 04:40
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1