블루 브리지 내장형 KEYAgain
3512 단어 블루 브리지 컵의 삽입식블루 브리지의 삽입식 개발
1. 주요 코드
main.c
/*******************************************************************************
* :main.c
* :
* :CLAY
* :v1.0.0
* : 2019 2 19
* : LCD
* 2ms ; B1,LED1
*******************************************************************************
*/
#include "stm32f10x.h"
#include "lcd.h"
#include "e2prom.h"
#include "stdio.h"
#include "i2c.h"
#include "adc.h"
#include "rtc.h"
#include "usart2.h"
#include "pwm.h"
#include "pwm_oc.h"
#include "pwm_ic.h"
#include "timer.h"
#include "led.h"
#include "key.h"
u32 TimingDelay = 0;
u8 RxdCnt = 0;
u8 RxdOver = 0;
u8 RxdBuf[20];
void Delay_Ms(u32 nTime);
u8 RTC_Flag = 0;
//Main Body
int main(void)
{
STM3210B_LCD_Init();
LCD_Clear(Blue);
LCD_SetBackColor(Blue);
LCD_SetTextColor(White);
SysTick_Config(SystemCoreClock/1000);
//PWM_Init(500, 60);//500Hz 60% //PA1
PWM_OC_Init(500, 60);//500Hz 60% PA1
PWM_IC_Init();//PA7
TIM4_Init(2000, 72);// 2ms
LED_Init();//LED
KeyInit();
while(1)
{
KeyDriver();
}
}
void KeyAction(int code)
{
if(code == 1)// B1,LED1
{
GPIOD->ODR |= (1<<2);// 573
GPIOC->ODR ^= (1<<8);//LED1
GPIOD->ODR &= (1<<2);// 573
}
}
//
void Delay_Ms(u32 nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
key.c
#include "stm32f10x.h"
#include "key.h"
extern void KeyAction(int code);
u8 KeySta[4] = {1, 1, 1, 1};
void KeyInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void KeyDriver(void)
{
u8 i;
static u8 backup[4] = {1, 1, 1, 1};
for(i=0; i<4; i++)
{
if(backup[i] != KeySta[i])
{
if(backup[i] != 0)
{
KeyAction(i+1);
}
backup[i] = KeySta[i];
}
}
}
void KeyScan(void)
{
u8 i;
static u8 keybuf[4] = {0xFF, 0xFF, 0xFF, 0xFF};
keybuf[0] = (keybuf[0] << 1) | KEY1;
keybuf[1] = (keybuf[1] << 1) | KEY2;
keybuf[2] = (keybuf[2] << 1) | KEY3;
keybuf[3] = (keybuf[3] << 1) | KEY4;
for(i=0; i<4; i++)
{
if(keybuf[i] == 0xFF)
{
KeySta[i] = 1;
}
else if(keybuf[i] == 0x00)
{
KeySta[i] = 0;
}
else
{}
}
}
key.h
#ifndef _KEY_H
#define _KEY_H
#define KEY1 GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)
#define KEY2 GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8)
#define KEY3 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1)
#define KEY4 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_2)
void KeyInit(void);
void KeyDriver(void);
void KeyScan(void);
#endif
stm32f10x_it.c
void TIM4_IRQHandler(void)
{
if(TIM_GetITStatus(TIM4, TIM_IT_Update) == SET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
KeyScan();
}
}
주의사항
1, PA0/PA8/PB1/PB2 키 추가
2. 매크로 정의 버튼은 맛볼 만하다
#define KEY1 GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)
3. 주함수에 있는 것을 잊지 마라
KeyInit
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
블루 브리지 내장형 KEYAgain프로젝트 가시성 Github 1. 주요 코드 main.c key.c key.h stm32f10x_it.c 주의사항 1, PA0/PA8/PB1/PB2 키 추가 2. 매크로 정의 버튼은 맛볼 만하다 3. 주함수에 있는 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.