各位大神!新人用库文件写了个用延时控制小车速度的程序
各位大神!帮忙看看我这个用库文件写的用延时控制小车速度的程序为什么不能控制小车速度!谢谢!求修改啊!很急用啊!{:cry:}/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
#include <stm32f10x_lib.h>
#include "platform_config.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
ErrorStatus HSEStartUpStatus;
u8 count=0;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void Delay(vu32 nCount);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name: main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
u32 T=9000000+9000000;
u32 SPEED=17999990;
u32 i;
u32 LuCheng=100;
/* System Clocks Configuration **********************************************/
RCC_Configuration();
/* NVIC Configuration *******************************************************/
NVIC_Configuration();
//配置时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
//配置引脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |GPIO_Pin_1 |GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;// 设定输出速率50MHZHz
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA, GPIO_Pin_All);
for(i=0;i<LuCheng;i++)
{
GPIO_SetBits(GPIOA, GPIO_Pin_0);//电机一起转动
//第一个动作
while(1)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1| GPIO_Pin_3);//电机一起转动
Delay(T-SPEED);
Delay(T-SPEED);
GPIO_ResetBits(GPIOA, GPIO_Pin_1| GPIO_Pin_3);//电机停止
/* Insert delay */
Delay(SPEED);
SPEED=SPEED+5;
}
}
}
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
}
/*******************************************************************************
* Function Name: NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdefVECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else/* VECT_TAB_FLASH*/
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
/*******************************************************************************
* Function Name: Delay
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length.
* Output : None
* Return : None
*******************************************************************************/
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
#ifdefDEBUG
/*******************************************************************************
* Function Name: assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* Input : - file: pointer to the source file name
* - line: assert_param error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
这里是51单片机区,STM32请发到隔壁。 阿莫斯瓦辛格 发表于 2013-4-25 13:25 static/image/common/back.gif
这里是51单片机区,STM32请发到隔壁。
哦哦,知道了 与时俱进也刚学习了STM32,参考一下!! gxlao6 发表于 2013-4-25 14:22 static/image/common/back.gif
与时俱进也刚学习了STM32,参考一下!!
很好!应该如此,哈哈{:lol:} 控制小车速度用PWM? AE007 发表于 2013-4-26 17:44 static/image/common/back.gif
控制小车速度用PWM?
是啊!就是不知怎么用
页:
[1]