学前班
最后登录1970-1-1
在线时间 小时
注册时间2014-3-8
|
由于板子晚上才到,又爱学,群里人爱积分,把我弄到帖子来啦,
由于实验室的板子的外部晶振没了,用了内部晶振,代码如下:图如下 记住 外部晶振没了 坏了;
led.c
/*
*ÎļþÃû £ºled.c
*ÃèÊö £ºledÓ¦ÓóÌÐò
*Ó²¼þÁ¬½Ó£º---------
* | pc3-led1 |
* | pc4-led2 |
* | pc5-led3 |
****************************/
#include "led.h"
#include "stm32f10x_flash.h"
/*
*function :led_GPIO_Config
*discription :configration i/o of led
*input :none
*output :none
*/
void led_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_led;
/***/
RCC_DeInit();
RCC_HSICmd(ENABLE); // internal HSI RC (8 MHz)
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
RCC_HSEConfig(RCC_HSE_OFF);
RCC_LSEConfig(RCC_LSE_OFF);
RCC_PLLConfig(RCC_PLLSource_HSI_Div2,RCC_PLLMul_8); // 32HMz
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_0);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE);
/**/
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
GPIO_led.GPIO_Pin=GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
GPIO_led.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_led.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_led);
/**/
GPIO_SetBits(GPIOF,GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9);
// GPIO_ResetBits(GPIOF,GPIO_Pin_8|GPIO_Pin_9);
}
led.h
#ifndef _led_h
#define _led_h
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#define ON 1
#define OFF 0
#define led1(a) if(a) GPIO_SetBits(GPIOF,GPIO_Pin_7); \
else GPIO_ResetBits(GPIOF,GPIO_Pin_7)
#define led2(a) if(a) GPIO_SetBits(GPIOF,GPIO_Pin_8);\
else GPIO_ResetBits(GPIOF,GPIO_Pin_8)
#define led3(a) if(a) GPIO_SetBits(GPIOF,GPIO_Pin_9);\
else GPIO_ResetBits(GPIOF,GPIO_Pin_9)
/**/
void led_GPIO_Config(void);
#endif
}
main.c
/**
******************************************************************************
* @file main.c
* @author fire
* @version V1.0
* @date 2013-xx-xx
* @brief ÓÃ3.5.0°æ±¾¿â½¨µÄ¹¤³ÌÄ£°å
******************************************************************************
* @attention
*
* ʵÑéƽ̨:Ò°»ð iSO-MINI STM32 ¿ª·¢°å
* ÂÛ̳ :http://www.firebbs.cn
* ÌÔ±¦ :http://firestm32.taobao.com
*
******************************************************************************
*/
#include "stm32f10x.h"
#include "led.h"
void Delay(__IO u32 nCount);
/**
* @brief Ö÷º¯Êý
* @param ÎÞ
* @retval ÎÞ
*/
int main(void)
{
led_GPIO_Config();//led³õʼ»¯
while(1)
{
led1(ON);
Delay(0x0FFFFFF);
led1(OFF);
led2(ON);
Delay(0x0FFFFFF);
led2(OFF);
led3(ON);
Delay(0x0FFFFFF);
led3(OFF);
}
/* add your code here ^_^. */
}
void Delay(__IO u32 nCount)
{
while(nCount--);
}
/*********************************************END OF FILE**********************/
|
|