这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 高校专区 » 漓东e学堂 » 1040 作业本

共2条 1/1 1 跳转至

1040 作业本

菜鸟
2014-10-23 18:27:04     打赏
/**
  ******************************************************************************
  * @file    GPIO/IOToggle/main.c 
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main program body.
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */ 


/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32_eval.h"
GPIO_InitTypeDef GPIO_InitStructure;


//以内部高速晶振为时钟源
void RCC_Configuration(void)
{
  RCC_DeInit(); /*将外设RCC寄存器重设为缺省值*/
    
  RCC_HSICmd(ENABLE);
  while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET); //等待HSI就绪
  
  RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); //选择内部高速时钟作为系统时钟
  
  RCC_HSEConfig(RCC_HSE_OFF); //关闭外部时钟
  RCC_LSEConfig(RCC_LSE_OFF); //使能或者失能内部低速晶振(LSI)
  RCC_PLLConfig(RCC_PLLSource_HSI_Div2,RCC_PLLMul_9); //  72HMz
  RCC_PLLCmd(ENABLE); //启动PLL
  while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); //设置PLL为系统时钟源
  RCC_ADCCLKConfig(RCC_PCLK2_Div4); //设置ADC时钟(ADCCLK)
  RCC_PCLK2Config(RCC_HCLK_Div1); //配置APB2(PCLK2)钟==AHB时钟
  RCC_PCLK1Config(RCC_HCLK_Div2); //配置APB1(PCLK1)钟==AHB1/2时钟
  RCC_HCLKConfig(RCC_SYSCLK_Div1); //配置AHB(HCLK)时钟等于==SYSCLK
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //配置系统时钟 = PLL时钟
  while(RCC_GetSYSCLKSource() != 0x08); //0x00:HSI作为系统时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE); //RCC_APB2Periph_AFIO
 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE); //disable JTAG
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //选中管脚2
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //端口的翻转速度级别为50MHz
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //LED 推挽输出
  GPIO_Init(GPIOD, &GPIO_InitStructure); //调用函数GPIO_Init()
GPIO_ResetBits(GPIOD,GPIO_Pin_2); //清除指定数据端口位
}


void GPIO_INIT()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //使能GPIOC时钟
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; //开漏输出
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //端口的翻转速度级别为50MHz
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //LED 推挽输出
  GPIO_Init(GPIOC, &GPIO_InitStructure); //调用函数GPIO_Init()
}


void delay_us(u32 n)
{
u8 j;
while(n--)
for(j=0;j<10;j++);
}


void  delay_ms(u32 n)
{
while(n--)
delay_us(1000);
}




/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)

RCC_Configuration();
 GPIO_INIT();
while(1){
GPIO_ResetBits(GPIOC,GPIO_Pin_1|GPIO_Pin_0);
delay_ms(100); //延时100ms
GPIO_SetBits(GPIOC,GPIO_Pin_1|GPIO_Pin_0);
delay_ms(100);}
}







关键词: 时钟    

高工
2014-10-28 00:49:16     打赏
2楼

这是个什么情况,不交任务?


共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]