-
什么东西 看看
-
大家都是焖起搞研究的 哈哈
-
玩 STM32的 初学者 共勉之
-
这些都是我在开发板上编译通过的,3.4库
-
小弟不才,让各位见笑了。
-
void TIM2_IRQHandler(void)
{
static __IO u8 sign = 0;
if ( TIM_GetITStatus(TIM2 , TIM_IT_CC1) !=RESET)
{
TIM_ClearITPendingBit(TIM2 , TIM_IT_CC1);
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9);
switch(sign)
{
case 0:
GPIO_ResetBits(GPIOF,GPIO_Pin_6); /*点亮DS1灯*/
break;
case 1:
GPIO_ResetBits(GPIOF,GPIO_Pin_7); /*点亮DS2灯*/
break;
case 2:
GPIO_ResetBits(GPIOF,GPIO_Pin_8); /*点亮DS3灯*/
break;
case 3:
GPIO_ResetBits(GPIOF,GPIO_Pin_9); /*点亮DS4灯*/
break;
default:
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9);
break;
}
sign++;
if(sign>4)sign=0;
}
else if(TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2 , TIM_IT_Update);
}
}
-
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_tim.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/*神州III号LED灯相关定义*/
#define RCC_GPIO_LED RCC_APB2Periph_GPIOF /*LED使用的GPIO时钟*/
#define LEDn 4 /*神舟III号LED数量*/
#define GPIO_LED GPIOF /*神舟III号LED灯使用的GPIO组*/
#define DS1_PIN GPIO_Pin_6 /*DS1使用的GPIO管脚*/
#define DS2_PIN GPIO_Pin_7 /*DS2使用的GPIO管脚*/
#define DS3_PIN GPIO_Pin_8 /*DS3使用的GPIO管脚*/
#define DS4_PIN GPIO_Pin_9 /*DS4使用的GPIO管脚*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
ErrorStatus HSEStartUpStatus;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void TIM_Configuration(void);
void Delay(vu32 nCount);
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_GPIO_LED, ENABLE); /*使能LED灯使用的GPIO时钟*/
TIM_Configuration();
NVIC_Configuration();
GPIO_InitStructure.GPIO_Pin = DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_LED, &GPIO_InitStructure); /*神州III号使用的LED灯相关的GPIO口初始化*/
//GPIO_SetBits(GPIO_LED,DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN);/*关闭所有的LED指示灯*/
while(1);
}
void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
u16 CCR1_Val = 2000;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Period = 2500; //TIM_Period设置了在下一个更新事件装入活动的自动重装载寄存器周期的值。它的取值必须在0x0000和0xFFFF之间。
TIM_TimeBaseStructure.TIM_Prescaler = 7200-1; //TIM_Prescaler设置了用来作为TIMx时钟频率除数的预分频值。它的取值必须在0x0000和0xFFFF之间。
TIM_TimeBaseStructure.TIM_ClockDivision =0x0; //TIM_ClockDivision设置了时钟分割。
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//TIM_CounterMode选择了计数器模式,TIM向上计数模式
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Inactive; //选择定时器模式,TIM输出比较非主动模式
TIM_OCInitStructure.TIM_Pulse = CCR1_Val; //设置了待装入捕获比较寄存器的脉冲值,它的取值必须在0x0000和0xFFFF之间
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;//TIM_OCPolarity输出极性,TIM输出比较极性高
TIM_OC1Init(TIM2,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Disable);
TIM_ARRPreloadConfig(TIM2, ENABLE);
TIM_ClearITPendingBit(TIM2,TIM_IT_CC1 | TIM_IT_Update);
TIM_ITConfig(TIM2,TIM_IT_CC1 | TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM2 gloabal Interrupt */
// NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); //中断向量表
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);
}
-
stm32f10x_it.c中的函数
void SysTick_Handler(void)
{
LED_Spark();//LED 启动函数,在中断里自己加的
}
-
#include "stm32f10x.h"
//#include"stm32f10x_gpio.h"
#define RCC_GPIO_LED RCC_APB2Periph_GPIOF
#define GPIO_LED_PORT GPIOF
#define GPIO_LED1 GPIO_Pin_6
#define GPIO_LED2 GPIO_Pin_7
#define GPIO_LED3 GPIO_Pin_8
#define GPIO_LED4 GPIO_Pin_9
#define GPIO_LED_ALL GPIO_LED1 |GPIO_LED2 |GPIO_LED3 |GPIO_LED4
void LED_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOB, GPIOC and AFIO clock */
RCC_APB2PeriphClockCmd(RCC_GPIO_LED | RCC_APB2Periph_AFIO , ENABLE); //RCC_APB2Periph_AFIO
/* LEDs pins configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_LED_ALL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIO_LED_PORT, &GPIO_InitStructure);
}
void Led_Turn_off_all(u8 n)
{
switch(n)
{
case 0:
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_6);
break;
case 1:
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_7);
break;
case 2:
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_8);
break;
case 3:
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9);
break;
}
}
void Led_Turn_on_all(u8 n)
{
switch(n)
{
case 0:
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
break;
case 1:
GPIO_ResetBits(GPIOF,GPIO_Pin_7);
break;
case 2:
GPIO_ResetBits(GPIOF,GPIO_Pin_8);
break;
case 3:
GPIO_ResetBits(GPIOF,GPIO_Pin_9);
break;
}
}
void LED_Spark(void)
{
static __IO uint32_t TimingDelayLocal = 0;
static __IO u8 n = 0;
if (TimingDelayLocal != 0x00) //如果不为0
{
if(TimingDelayLocal < 50) // 后50次熄灭LED指示灯
{
Led_Turn_off_all(n);
}
else // 前50次点亮LED指示灯
{
Led_Turn_on_all(n);
}
TimingDelayLocal--; // 该函数每一次被调用静态本地变量TimingDelayLocal便会减一
}
else
{
TimingDelayLocal = 100;
n++;
if (n>3) n=0;
}
}
/*******************************************************************************
* 函数名 : SysTick_Configuration
* 功能 : 配置SysTick 时基
* 输入 : 无
* 输出 : 无
* 返回 : 无
*******************************************************************************/
void SysTick_Configuration(void)
{
/* Setup SysTick Timer for 10 msec interrupts */
//时间计算就是 SystemCoreClock/(SystemCoreClock/50)
if (SysTick_Config(SystemCoreClock / 100)) //SysTick配置函数,传递的参数是初值 1/100S
{
/* Vector error */
while (1);
}
/* Configure the SysTick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x0);//SysTick中断优先级设置
}
void InterruptConfig(void)
{
/* Set the Vector Table base address at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00000);
}
int main(void)
{
LED_config(); //LED使用的GPIO初始化
Led_Turn_on_all(4); //点亮所有的LED灯
SysTick_Configuration(); //SysTick中断配置
/*主循环 */
while (1)
{
;
}
}
-
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/*神州III号LED灯相关定义*/
#define RCC_GPIO_LED RCC_APB2Periph_GPIOF /*LED使用的GPIO时钟*/
#define LEDn 4 /*神舟III号LED数量*/
#define GPIO_LED GPIOF /*神舟III号LED灯使用的GPIO组*/
#define DS1_PIN GPIO_Pin_6 /*DS1使用的GPIO管脚*/
#define DS2_PIN GPIO_Pin_7 /*DS2使用的GPIO管脚*/
#define DS3_PIN GPIO_Pin_8 /*DS3使用的GPIO管脚*/
#define DS4_PIN GPIO_Pin_9 /*DS4使用的GPIO管脚*/
/* 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);
void Turn_On_LED(u8 LED_NUM);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
/* 配置神舟III号LED灯使用的GPIO管脚模式*/
RCC_APB2PeriphClockCmd(RCC_GPIO_LED, ENABLE); /*使能LED灯使用的GPIO时钟*/
GPIO_InitStructure.GPIO_Pin = DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_LED, &GPIO_InitStructure); /*神州III号使用的LED灯相关的GPIO口初始化*/
GPIO_SetBits(GPIO_LED,DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN);/*关闭所有的LED指示灯*/
while(1)
{
GPIO_SetBits(GPIO_LED,DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN);/*关闭所有的LED指示灯*/
Turn_On_LED(count%4); //点亮一个LED灯
count++;
Delay(0x2FFFFF);
}
}
/*点亮对应灯*/
void Turn_On_LED(u8 LED_NUM)
{
switch(LED_NUM)
{
case 0:
GPIO_ResetBits(GPIO_LED,DS1_PIN); /*点亮DS1灯*/
break;
case 1:
GPIO_ResetBits(GPIO_LED,DS2_PIN); /*点亮DS2灯*/
break;
case 2:
GPIO_ResetBits(GPIO_LED,DS3_PIN); /*点亮DS3灯*/
break;
case 3:
GPIO_ResetBits(GPIO_LED,DS4_PIN); /*点亮DS4灯*/
break;
default:
GPIO_ResetBits(GPIO_LED,DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN); /*点亮所有的灯*/
break;
}
}
/*******************************************************************************
* 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--);
}
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
-
晚上吃了饭 我也来发几个 随便提下问题
-
电子信息科学与技术与电子科学与技术,差距有多大,看出来了
-
我基本天天都来的,就是 记不得 签到
-
这样应该差不多了吧
-
#include "stm32f10x_it.h"
extern void LED_Spark(void);
void SysTick_Handler(void)
{
LED_Spark();//LED 启动函数,在中断里自己加的
}
-
#include "stm32f10x.h"
//#include"stm32f10x_gpio.h"
#define RCC_GPIO_LED RCC_APB2Periph_GPIOF
#define GPIO_LED_PORT GPIOF
#define GPIO_LED1 GPIO_Pin_6
#define GPIO_LED2 GPIO_Pin_7
#define GPIO_LED3 GPIO_Pin_8
#define GPIO_LED4 GPIO_Pin_9
#define GPIO_LED_ALL GPIO_LED1 |GPIO_LED2 |GPIO_LED3 |GPIO_LED4
void LED_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOB, GPIOC and AFIO clock */
RCC_APB2PeriphClockCmd(RCC_GPIO_LED | RCC_APB2Periph_AFIO , ENABLE); //RCC_APB2Periph_AFIO
/* LEDs pins configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_LED_ALL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIO_LED_PORT, &GPIO_InitStructure);
}
void Led_Turn_off_all(u8 n)
{
switch(n)
{
case 0:
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_6);
break;
case 1:
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_7);
break;
case 2:
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_8);
break;
case 3:
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9);
break;
}
}
void Led_Turn_on_all(u8 n)
{
switch(n)
{
case 0:
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
break;
case 1:
GPIO_ResetBits(GPIOF,GPIO_Pin_7);
break;
case 2:
GPIO_ResetBits(GPIOF,GPIO_Pin_8);
break;
case 3:
GPIO_ResetBits(GPIOF,GPIO_Pin_9);
break;
}
}
void LED_Spark(void)
{
static __IO uint32_t TimingDelayLocal = 0;
static __IO u8 n = 0;
if (TimingDelayLocal != 0x00) //如果不为0
{
if(TimingDelayLocal < 50) // 后50次熄灭LED指示灯
{
Led_Turn_off_all(n);
}
else // 前50次点亮LED指示灯
{
Led_Turn_on_all(n);
}
TimingDelayLocal--; // 该函数每一次被调用静态本地变量TimingDelayLocal便会减一
}
else
{
TimingDelayLocal = 100;
n++;
if (n>3) n=0;
}
}
/*******************************************************************************
* 函数名 : SysTick_Configuration
* 功能 : 配置SysTick 时基
* 输入 : 无
* 输出 : 无
* 返回 : 无
*******************************************************************************/
void SysTick_Configuration(void)
{
/* Setup SysTick Timer for 10 msec interrupts */
//时间计算就是 SystemCoreClock/(SystemCoreClock/50)
if (SysTick_Config(SystemCoreClock / 100)) //SysTick配置函数,传递的参数是初值 1/100S
{
/* Vector error */
while (1);
}
/* Configure the SysTick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x0);//SysTick中断优先级设置
}
void InterruptConfig(void)
{
/* Set the Vector Table base address at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00000);
}
int main(void)
{
LED_config(); //LED使用的GPIO初始化
Led_Turn_on_all(4); //点亮所有的LED灯
SysTick_Configuration(); //SysTick中断配置
/*主循环 */
while (1)
{
;
}
}
-
我也知道要同时关断和开启T1 ,T2,关键是关断和开启的条件怎么找,我发下百度文库的链接,这个是我在百度文库看到的。http://wenku.baidu.com/view/3687 ... 36c67481f200187bab5
其实好多地方 我都看到过这种类型的电路了, 下面一个也是
http://www.doc88.com/p-871103143346.html
-
看了,不顶不行呀
-
对的 ,是如何。采样呢就是判断哪个时候是白天哪个时候是晚上呢。两个共阳了呢,说的是,太阳板的正和电瓶的正相连了。按照图上的采样,感觉是太阳的电压在采样的时候是不是和电瓶的相差无几了,当然这个是在IRF3205导通的情况下,这里不明白的是,什么时候通过什么方式关闭MOS管呢
-
不回豆不行