• 嵌入式实验四


    #include "stm32f10x.h"
    #include <stdio.h>
    #include <string.h>

    void RCC_cfg(void);
    void GPIO_cfg(void);
    void NVIC_cfg(void);
    void TIMER_cfg(void);

    int main(void)
    {
     RCC_cfg();
     GPIO_cfg();
     NVIC_cfg();
     TIMER_cfg();
     TIM_Cmd(TIM2,ENABLE);
     while(1);
    }

    void RCC_cfg(void)
    {
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
    }
    void GPIO_cfg(void)
    {
     GPIO_InitTypeDef GPIO_InitStructure;
     GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;//
     GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
     GPIO_Init(GPIOF,&GPIO_InitStructure);
    }

    void NVIC_cfg(void)
    {
     NVIC_InitTypeDef NVIC_InitStructure;
     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
     NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
     NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
     NVIC_Init(&NVIC_InitStructure);
    }

    void TIMER_cfg(void)
    {
     TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
     TIM_DeInit(TIM2);
     TIM_InternalClockConfig(TIM2);
     TIM_TimeBaseStructure.TIM_Prescaler=36000-1;
     TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
     TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
     TIM_TimeBaseStructure.TIM_Period=3000-1;
     TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
     
     TIM_ClearFlag(TIM2,TIM_FLAG_Update);
     TIM_ARRPreloadConfig(TIM2,DISABLE);
     TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
    }

    void TIM2_IRQHandler(void)
    {
     u8 ReadValue;
     if(TIM_GetITStatus(TIM2,TIM_IT_Update)!=RESET)
     {
      TIM_ClearITPendingBit(TIM2,TIM_FLAG_Update);
      ReadValue=GPIO_ReadOutputDataBit(GPIOF,GPIO_Pin_9);//
      if(ReadValue==0)
      {
       GPIO_SetBits(GPIOF,GPIO_Pin_9);
       //GPIO_ResetBits(GPIOF,GPIO_Pin_7);
      }
      else
      {
       GPIO_ResetBits(GPIOF,GPIO_Pin_9);
       //GPIO_SetBits(GPIOF,GPIO_Pin_7);
      }
     }
    }
     
     

  • 相关阅读:
    hdu 4324(dfs)
    hdu 2376(求树上任意两点之间距离之和的平均值)
    hdu 3665(最短路)
    hdu 4463(最小生成树变形)
    hdu 2242(边双连通分量)
    hdu 2682(最小生成树)
    hdu 2444(二分图的判断以及求最大匹配)
    陶哲轩实分析命题6.4.12
    陶哲轩实分析习题8.3.4
    CantorBernsteinSchroeder定理的证明
  • 原文地址:https://www.cnblogs.com/rourou123/p/8053444.html
Copyright © 2020-2023  润新知