Chinaunix首页 | 论坛 | 博客
  • 博客访问: 304366
  • 博文数量: 169
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 12
  • 用 户 组: 普通用户
  • 注册时间: 2013-07-10 12:00
文章分类

全部博文(169)

文章存档

2014年(38)

2013年(131)

我的朋友

分类: C/C++

2014-02-24 22:07:45

原文地址:STM32F4 多路ad和da 作者:M甲壳虫M

/******************************************************************
*******????·???????????????????×???????????????????????************
*******????????????·??÷????????????????????????????????????********
*******???????????????¨?±?÷??????**********************************
*×÷????????
*?±????2013-07-09
*******************************************************************/
#include "USER_DIDO.h"
 vu16 DO_State_RES = 0x0000;  //????·????¨???ó???á?¨??extern???¨???????????ú??????
 vu8 DI_State_RES = 0x00; 






static void DO_GPIO_Config(void)  //DO×??????ù?????????è?????????????????è????0
{
 GPIO_InitTypeDef  GPIO_InitStructure;


    BSP_PeriphEn(BSP_PERIPH_ID_GPIOH);                          /* Configure GPIOG for LED1 and LED2                    */


    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6 | GPIO_Pin_7| GPIO_Pin_8| GPIO_Pin_9| GPIO_Pin_10| GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;


    GPIO_Init(GPIOH, &GPIO_InitStructure);


 BSP_PeriphEn(BSP_PERIPH_ID_GPIOE);                          /* Configure GPIOG for LED1 and LED2                    */


    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;


    GPIO_Init(GPIOE, &GPIO_InitStructure);
}


static void DO_TIM2_Config(void)   //???±????
{
;
}
void DO_I(void)
{
DO_GPIO_Config();

}


static void DI_GPIO_Config(void)  //?????????é???¨??
{
GPIO_InitTypeDef  GPIO_InitStructure;



    BSP_PeriphEn(BSP_PERIPH_ID_GPIOD);                          /* Configure GPIOG for LED1 and LED2                    */


    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15| GPIO_Pin_2| GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP; //??????????±??????¨
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;


    GPIO_Init(GPIOD, &GPIO_InitStructure);


 BSP_PeriphEn(BSP_PERIPH_ID_GPIOG);                          /* Configure GPIOG for LED1 and LED2                    */


    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_2 | GPIO_Pin_9| GPIO_Pin_13| GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;


    GPIO_Init(GPIOG, &GPIO_InitStructure);

 BSP_PeriphEn(BSP_PERIPH_ID_GPIOC);                          /* Configure GPIOG for LED1 and LED2                    */


    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8 | GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;


    GPIO_Init(GPIOC, &GPIO_InitStructure);

BSP_PeriphEn(BSP_PERIPH_ID_GPIOH);                          /* Configure GPIOG for LED1 and LED2                    */


    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_14;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;


    GPIO_Init(GPIOH, &GPIO_InitStructure);

BSP_PeriphEn(BSP_PERIPH_ID_GPIOI);                          /* Configure GPIOG for LED1 and LED2                    */


    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;


    GPIO_Init(GPIOI, &GPIO_InitStructure);

}


/*
static void DI_EXIT_Config(void)
{

  EXTI_InitTypeDef EXTI_InitStructure;  //?¨????????±???
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//????syscfg???±??
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOI,EXTI_PinSource0);//?¨??EXIT???¨??????,????°ó?¨ EXTI??????
EXTI_InitStructure.EXTI_Line = EXTI_Line0;      //??????
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;    
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;   
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;      //
  EXTI_Init(&EXTI_InitStructure);

}
?????????±·?????
*/






void DI_Init(void)
{
DI_GPIO_Config();//??????gpio14×
  //NVIC_Configuration();
DI_TIM2_Config();//????????Tim2?±?? 1s???????ó?á???????????????????¨????±?



BSP_IntVectSet(BSP_INT_ID_TIM2, TIM2_IQR_TEST);  //??×????¨????????  BSP_IntHandlerUSART1
NVIC_Configuration();
  BSP_IntPrioSet(BSP_INT_ID_TIM2,2);    
  BSP_IntEn(BSP_INT_ID_TIM2);                             //????????




}






static void DI_TIM2_Config(void)
{
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
   //TIM_OCInitTypeDef TIM_OCInitStructure;
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
//TIM_DeInit(TIM2); //???????è??tim???±????
   TIM_TimeBaseStructure.TIM_Period=1000-1; /* ×?????×°???????÷????????(??????) 1S??????*/
/* ???? TIM_Period???????ó?ú?ú?????ü???ò?????? */
   TIM_TimeBaseStructure.TIM_Prescaler=0x0;    /* ?±???¤·?????   ???????±??????=APB1=42MHZ/(?±???¤·???+1) */
   TIM_TimeBaseStructure.TIM_ClockDivision= 0x0; /* ???ù·??? */
   TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; /* ?ò?????????? */
   TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);


TIM_PrescalerConfig(TIM2,0xA40F,TIM_PSCReloadMode_Immediate);//?±??·?????????42000???????¨?±?÷?±????2s
   TIM_ARRPreloadConfig(TIM2, DISABLE);//?????°×??????÷
   TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);


   TIM_Cmd(TIM2, ENABLE);        //






  
 
}


/*******************************************************************************
* Function Name  : NVIC_Configuration
* Description    : Configuration the nested vectored interrupt controller.
* Input          : None
* Output         : None
* Return         : None
* Attention : None
*******************************************************************************/
void NVIC_Configuration(void)
{
  NVIC_InitTypeDef  NVIC_InitStructure;  
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);   //Tim2????????????????2??????8??8·?????????????
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;  //?????¨?? 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//????????????2????????0??????
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;//?à??????????1???????ó????????
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}










void TIM2_IQR_TEST(void)
{
BSP_LED_Toggle(3);
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update); 
}



这部分是多路ad和da的数据采集初始化配置内容,希望对给位有用




































阅读(1171) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~