27,374
社区成员
发帖
与我相关
我的任务
分享
#include "stm32f4xx.h"
#define GPIO_Pin_6 0x0040
#define GPIO_Pin_7 0x0080
#define GPIO_Pin_8 0x0100
#define GPIO_Pin_9 0x0200
#define light_num 4
void light_init(void);
void interrupt(void);
void light_init(void)
{
RCC->AHB1ENR |= 0x00000020;
GPIOF->MODER |= 0x00055000;
GPIOF->OTYPER |= 0x000003C0;
GPIOF->OSPEEDR |= 0x00055000;
GPIOF->PUPDR &= 0xFFF00FFF;
GPIOF->BSRRL |= GPIO_Pin_6;
GPIOF->BSRRL |= GPIO_Pin_7;
GPIOF->BSRRL |= GPIO_Pin_8;
GPIOF->BSRRL |= GPIO_Pin_9;
}
void interrupt(void)
{
RCC->APB1ENR |= 0x00000008;
TIM5->PSC = 4199;
TIM5->ARR = 50000;
//TIM5->CR1 |= 1<<2;
TIM5->DIER |= 1;
TIM5->DIER |= 1<<6;
NVIC->IP[50] = 0x00;
NVIC->ISER[1] |= (1<<18);
TIM5->CR1 |= 1;
}
int main()
{
light_init();
interrupt();
while(1){
};
}
void TIM5_IRQHandler(void)
{
if(TIM5->SR&0x0001){
GPIOF->BSRRH |= GPIO_Pin_6;
}
TIM5->SR &= ~(0x0001);
}
#include "stm32f4xx.h"
#define GPIO_Pin_6 0x0040
#define GPIO_Pin_7 0x0080
#define GPIO_Pin_8 0x0100
#define GPIO_Pin_9 0x0200
#define light_num 4
int flag = 0;
void light_init(void);
void interrupt(void);
int n = 0;
void light_init(void)
{
// ¿ªÆôF¶Ë¿ÚµÄʱÖÓ
RCC->AHB1ENR |= 0x00000020;
// ģʽΪ£ºÊä³öģʽ
GPIOF->MODER |= 0x00055000;
// Êä³öÀàÐÍ£º1¡¢¿ªÂ©£»2¡¢ÍÆÍì
GPIOF->OTYPER |= 0x000003C0;
// ÉèÖÃËÙ¶È
GPIOF->OSPEEDR |= 0x00055000;
// ²»À¸ß²»ÀµÍ
GPIOF->PUPDR &= 0xFFF00FFF;
GPIOF->BSRRL |= GPIO_Pin_6;
GPIOF->BSRRL |= GPIO_Pin_7;
GPIOF->BSRRL |= GPIO_Pin_8;
GPIOF->BSRRL |= GPIO_Pin_9;
}
void interrupt(void)
{
// ÅäÖÃʱÖÓ
RCC->APB1ENR |= 0x00000008; // ¿ªÆôTIM5
TIM5->PSC = 4199; // Ô¤·ÖƵ4200
TIM5->ARR = 5000; // ¶¨Ê±5Ãë
TIM5->CR1 = 1<<7;
TIM5->DIER |= 1;
TIM5->DIER |= 1<<6;
NVIC->IP[50] = 0x00;
NVIC->ISER[1] |= (1<<18); // ʹÄÜ50ºÅÖжÏ,¼´TIM5
TIM5->CR1 |= 1;
}
void led(u16 n){
if(n==0){
GPIOF->BSRRH |= GPIO_Pin_6;
}else if(n==1){
GPIOF->BSRRL |= GPIO_Pin_6;
}
}
int main()
{
light_init();
interrupt();
while(1){
}
}
void TIM5_IRQHandler(void)
{
if(TIM5->SR&0x0001){
led(flag);
flag = !flag;
}
TIM5->SR &= ~(0x0001);
}
经过调试,终于对了,现在0.5s闪亮PF6灯!#include "stm32f4xx.h"
#define GPIO_Pin_6 0x0040
#define GPIO_Pin_7 0x0080
#define GPIO_Pin_8 0x0100
#define GPIO_Pin_9 0x0200
#define light_num 4
void light_init(void);
void interrupt(void);
void light_init(void)
{
// ¿ªÆôF¶Ë¿ÚµÄʱÖÓ
RCC->AHB1ENR |= 0x00000020;
// ģʽΪ£ºÊä³öģʽ
GPIOF->MODER |= 0x00055000;
// Êä³öÀàÐÍ£º1¡¢¿ªÂ©£»2¡¢ÍÆÍì
GPIOF->OTYPER |= 0x000003C0;
// ÉèÖÃËÙ¶È
GPIOF->OSPEEDR |= 0x00055000;
// ²»À¸ß²»ÀµÍ
GPIOF->PUPDR &= 0xFFF00FFF;
GPIOF->BSRRL |= GPIO_Pin_6;
GPIOF->BSRRL |= GPIO_Pin_7;
GPIOF->BSRRL |= GPIO_Pin_8;
GPIOF->BSRRL |= GPIO_Pin_9;
}
void interrupt(void)
{
// ÅäÖÃʱÖÓ
RCC->APB1ENR |= 0x00000008; // ¿ªÆôTIM2
TIM5->PSC = 4199; // Ô¤·ÖƵ4200
TIM5->ARR = 50000; // ¶¨Ê±5Ãë
//TIM5->CR1 |= 1<<2;
//TIM5->DIER |= 1;
//TIM5->DIER |= 1<<6;
//NVIC->IP[50] = 0x00;
//NVIC->ISER[1] |= (1<<18); // ʹÄÜ50ºÅÖжÏ,¼´TIM5
TIM5->CR1 |= 1;
}
int main()
{
light_init();
interrupt();
NVIC->IP[50] = 0x00;
NVIC->ISER[1] |= (1<<18); // ʹÄÜ50ºÅÖжÏ,¼´TIM5
TIM5->DIER |= 1;
TIM5->DIER |= 1<<6;while(1){
};
}
void TIM5_IRQHandler(void)
{
if(TIM5->SR&0x0001){
GPIOF->BSRRH |= GPIO_Pin_6;
}
TIM5->SR &= ~(0x0001);
}