当前位置:   article > 正文

外中断控制数码管显示_如何开放外部中断2,如何送数码管显示、

如何开放外部中断2,如何送数码管显示、

main.c:

#include "stm32f10x.h"
#include "delay.h"
#include "key.h"
#include "smg.h"
#include "sys.h"

uint16_t table[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint16_t dis, cnt = 0;

int main()
{
	NVIC_Configuration();
	SMG_Init();
	Key_Exti_Init();
	while(1)
	{
		dis=table[cnt%10];	
		GPIO_Write(GPIOB, dis); 
		delay(500);
	}
}


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

key.h:

#ifndef __KEY_H
#define __KEY_H

#include "sys.h"


void Key_Exti_Init(void);
void EXTI9_5_IRQHandler(void);

#endif

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

key.c:

#include "key.h"
#include "stm32f10x.h"
#include "delay.h"
#include "sys.h"

extern uint16_t cnt;

void Key_Exti_Init(void)
{
	//启用GPIO复用
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE); 

	
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(GPIOC, &GPIO_InitStructure); 
	
	
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource8); 

	
	//配置中断线
	EXTI_InitTypeDef EXTI_InitStructure;
	EXTI_InitStructure.EXTI_Line = EXTI_Line8;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //中断模式
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure); 
	
	NVIC_InitTypeDef NVIC_InitStructure;
	NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;	//抢占优先级 分组2中为0-3
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;	//响应优先级
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure); 

}

void EXTI9_5_IRQHandler()
{
	cnt ++;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

smg.h:

#ifndef __SMG_H
#define __SMG_H

void SMG_Init(void);//数码管IO口的初始化
#endif

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

smg.c:

#include "smg.h"
#include "stm32f10x.h"

void SMG_Init(void)
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB    , ENABLE); //启动GBIOC的时钟
	
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //配置为推挽输出
	GPIO_Init(GPIOB, &GPIO_InitStructure); 	
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/408838
推荐阅读
相关标签
  

闽ICP备14008679号