找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1566|回復: 1
打印 上一主題 下一主題
收起左側(cè)

stm32平衡小車程序

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:526143 發(fā)表于 2019-5-8 22:19 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
/******************** (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
//電機驅(qū)動  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

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:1 發(fā)表于 2019-5-9 04:40 | 只看該作者
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表