标题:
STM32按键执行程序
[打印本页]
作者:
WR111222
时间:
2019-8-28 15:39
标题:
STM32按键执行程序
自己编写的按键执行程序,实现上翻、下翻、功能、确认、返回的功能。新手编写,高手绕道!
单片机源程序如下:
#include "stm32f10x.h"
#include "stdio.h"
#include "tm1620.h"
#include "common.h"
#include "KeyScan.h"
#include "delay.h"
#include "Keyexec.h"
#include "tim.h"
ErrorStatus HSEStartUpStatus;
void RCC_Configuration(void);
void NVIC_Configuration(void);
#ifdef DEBUG
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert error has occurred.
* Input : - file: pointer to the source file name
* - line: assert error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number */
printf("\n\r Wrong parameter value detected on\r\n");
printf(" file %s\r\n", file);
printf(" line %d\r\n", line);
/* Infinite loop */
/* while (1)
{
} */
}
#endif
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();//复位RCC时钟
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);//RCC配置
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);//72Mhz
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);//ADC时钟 72/6=12M
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x9000);
#endif
}
void IWDG_Configuration(void)
{
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);//启动寄存器读写
IWDG_SetPrescaler(IWDG_Prescaler_32);//40K时钟32分频
IWDG_SetReload(0xfff); //计数器数值 819.2ms
IWDG_ReloadCounter(); //重启计数器
IWDG_Enable(); //启动看门狗
}
u8 Value;
u8 Value1;
u8 Value2;
u8 Value3;
int main(void)
{
RCC_Configuration();
//NVIC_Configuration();
__set_FAULTMASK(0); //打开所有中断
IOOUT_Init();
TM1616_init();
KeyScan_Init();
Timer3_Init(49);
Timer2_Init(9999);
while(1)
{
key_function();
key_execute();
}
}
复制代码
所有资料51hei提供下载:
按键执行程序.7z
(182.27 KB, 下载次数: 23)
2019-8-28 20:27 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1