#include "main.h"
#include "stdio.h"
USART_InitTypeDef USART_InitStructure;
#define RCC_KEY1 RCC_APB2Periph_GPIOD
#define GPIO__KEY1_Port GPIOD
#define KEY1 GPIO_Pin_3
#define RCC_KEY@ RCC_APB2Periph_GPIOA
#define GPIO_KEY2_Port GPIOA
#define KEY2 GPIO_Pin_8
#define RCC_KEY3 RCC_APB2Periph_GPIOC
#define GPIO_KEY3_PORT GPIOC
#define GPIO_KEY3 GPIO_Pin_13
#define RCC_KEY4 RCC_APB2Periph_GPIOA
#define GPIO_KEY4_PORT GPIOA
#define GPIO_KEY4 GPIO_Pin_0
#define NOKEY 0
#define KEY1 1
#define KEY2 2
#define KEY3 3
#define KEY4 4
INT8U KeyNum = 0;
static OS_STK TaskOSSTK[128];
static OS_STK Task1OSSTK[128];
static OS_STK Task2OSSTK[128];
static OS_STK Task3OSSTK[128];
static OS_STK Task4OSSTK[128];
static void Task0(void * pdata); //优先级6
static void Task1(void * pdata); //7
static void Task2(void * pdata); //8
static void Task3(void * pdata); //9
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (unsigned char) ch);// USART1 可以换成 USART2 等
while (!(USART1->SR & USART_FLAG_TXE));
return (ch);
}
// 接收数据
int GetKey (void) {
while (!(USART1->SR & USART_FLAG_RXNE));
return ((int)(USART1->DR & 0x1FF));
}
int main()
{
SystemInit();
RCC_Configuration();
GPIO_Configuration()
USART_Configuration();
OSInit();
OSTaskCreate(Task0,(void *)0,(OS_STK *)&Task0OSSTK[128-1],6);
OSStart();
while(1);
}
static void Task0(void *pdata)
{
(void)pdata;
OS_CPU_SysTickInit();
OSTaskCreate(Task1, (void *)0, (OS_STK *)&Task1OSStk[128-1], 7);
OSTaskCreate(Task2, (void *)0, (OS_STK *)&Tas2OSStk[128-1], 8);
OSTaskCreate(Task3, (void *)0, (OS_STK *)&Task3OSStk[128-1], 9);
for(;;)
{
OSTimeDly(OS_TICKS_PER_SEC);
GPIO_SetBits(GPIOF, GPIO_Pin_6);
OSTimeDly(OS_TICKS_PER_SEC);
GPIO_ResetBits(GPIOF, GPIO_Pin_6);
}
}
static void Task1(void *pdata)
{
(void)pdata;
for(;;)
{
OSTimeDly(OS_TICKS_PER_SEC/2);
GPIO_SetBits(GPIOF, GPIO_Pin_7);
OSTimeDly(OS_TICKS_PER_SEC/2);
GPIO_ResetBits(GPIOF, GPIO_Pin_7);
}
}
static void Task2(void *pdata)
{
(void)pdata;
for(;;)
{ printf("灯3开始闪烁\r\n");
OSTimeDly(OS_TICKS_PER_SEC/5);
GPIO_SetBits(GPIOF, GPIO_Pin_8);
OSTimeDly(OS_TICKS_PER_SEC/5);
GPIO_ResetBits(GPIOF, GPIO_Pin_8);
}
}
static void Task3(void *pdata)
{
(void)pdata;
while(1)
{
KeyNum = ReadKeyDown();
if(KeyNum==KEY1)
{
OSTimeDly(OS_TICKS_PER_SEC/10);
GPIO_SetBits(GPIOF, GPIO_Pin_9);
OSTimeDly(OS_TICKS_PER_SEC/10);
GPIO_ResetBits(GPIOF, GPIO_Pin_9);
}
}
}
INT8U ReadKeyDown(void)
{
/* 1 key is pressed */
if(!GPIO_ReadInputDataBit(GPIO_KEY1_PORT, GPIO_KEY1))
{
return KEY1;
}
/* 2 key is pressed */
if(!GPIO_ReadInputDataBit(GPIO_KEY2_PORT, GPIO_KEY2))
{
return KEY2;
}
/* 3 key is pressed */
if(!GPIO_ReadInputDataBit(GPIO_KEY3_PORT, GPIO_KEY3))
{
return KEY3;
}
/* 4 key is pressed */
if(!GPIO_ReadInputDataBit(GPIO_KEY4_PORT, GPIO_KEY4))
{
return KEY4;
}
/* No key is pressed */
else
{
return NOKEY;
}
}
Previous article:[HAL library learning path] 7. Timer interrupt
Next article:STM32F103 LED light simple program implementation
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- 280049Solution to the problem of LaunchPad emulator not being able to connect
- Commonly used algorithms for drones - Kalman filter (XI)
- What is PWM "dead zone"?
- E-sports data: Design and practice of common analog systems for e-sports based on TI devices - high-speed DAC module design
- How to choose 18650 charging IC?
- ATL431 by name parameters and package guidelines
- Hey guys, help me~ I want to ask about some common application scenarios of DCDC power supply
- APP development | Introduction to three APP development methods of Gizwits
- [Posting Notes] 2022 Digi-Key Innovation Design Competition
- 【LAUNCHXL-CC1350-4】- 4: Things are not that simple