赞
踩
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); } }
key.h:
#ifndef __KEY_H
#define __KEY_H
#include "sys.h"
void Key_Exti_Init(void);
void EXTI9_5_IRQHandler(void);
#endif
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 ++; }
smg.h:
#ifndef __SMG_H
#define __SMG_H
void SMG_Init(void);//数码管IO口的初始化
#endif
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);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。