之前在STM32Nano开发板开发是基于裸机开发,即自己在main方法写死循环。死循环轮流执行各个任务逻辑的方法。这样做直接简单,但是不同任务有不同优先级,对CPU响应要求不同。逻辑容易某个任务卡住了,导致别的任务也卡死。比如串口发送长数据时候。LED闪烁会停止。
FreeRTOS移植源码
C#通过Winform串口配合交互的源码
本次移植花了大几天才彻底搞定。官方Demo倒是很快,然而我不想直接用官方Demo删东西搞工程,也不想用他那个目录布局。折腾工程到编译没错误搞了半天。然后把我之前裸机实现的LED、蜂鸣器、串口的功能移植花了小半天。因为创建任务时候把任务优先级和堆栈大小参数给反了。把一个小于32的任务优先级给了堆栈,造成堆栈溢出很多奇特的内存bug。
1.有调用用vTaskDelay延迟函数后就所有任务死掉的消息,然后给前后加临界保护后又正常了。
taskENTER_CRITICAL();
vTaskDelay(10);
taskEXIT_CRITICAL();
2.延迟方法调用崩溃问题通过临界保护解决之后又碰到给串口任务多加一行代码或者少加一行代码导致所有任务卡死问题。然后我就一段段代码去了测试。发现代码留的少就可以,就算加的代码分支执行条件永远是假也会导致任务卡死。那么问题肯定不是业务运行导致异常了。猜测是内存方面问题,然后折腾STM32F10x.s汇编代码的堆栈和FreeRTOSConfig.h的配置搞了好久还是解决不了诡异现象。
3.然后求助专业嵌入式老兄宏伟给看看我代码问题。发现我创建任务把任务优先级和堆栈大小给反了。小于32的堆栈对我串口测试的复杂任务不够。然后结合编译器的编译,有时候能达到微妙的平衡。大概就像下图: OS移植第一步搞定了,感受颇深,学习了不少东西,争取把FreeRTOS搞透彻。
不依赖OS写法(不能区分任务紧急程度,难以充分利用CPU算力):
#include "delay.h"
#include "led.h"
#include "beep.h"
#include "key.h"
#include "usart.h"
#include "hardware.h"
#include "timer.h"
#include "smg.h"
int main(void)
{
Stm32_Clock_Init(9);
delay_init(72);
while (1)
{
}
}
所以在功能慢慢做复杂后引入任务调度是必然的。在多个嵌入式实时操作系统里我选择了学习FreeRTOS。为什么选择它呢,一是FreeRTOS是开源的,不涉及收费,真要有用时候免得有版权问题(UCOS商用收费)。二是很多芯片基本标配FreeRTOS了,很流行,资料也不少。综合选择采用FreeRTOS。三是FreeRTOS对硬件要求少,最少3kb就可以跑起来,我这个STM32Nano开发版只能说是20kb内存高配了。
首先到FreeRTOS下载源码,我下载的是最新的FreeRTOS202112.00版本 FreeRTOS官网
解压目录如下:
目前先学内核,不涉及周边模块。所以-Plus先不管。下图是内核源码和示例目录。
找到STM32Nano用的芯片的示例
拷入FreeRTOS源码到自己工程 配置OS
工程目录
主要实现代码 FreeRTOSConfig.h
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 72000000 )
#define configTICK_RATE_HZ ( ( TickType_t ) 100 )
#define configMAX_PRIORITIES ( 32 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 )
#define configTOTAL_HEAP_SIZE (( size_t) (17*1024))
#define configMAX_TASK_NAME_LEN (16)
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define configKERNEL_INTERRUPT_PRIORITY 255
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 191
#define configLIBRARY_KERNEL_INTERRUPT_PRIORITY 15
#endif
InitOS.h
#ifndef __INITOS
#define __INITOS
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "stm32f10x_it.h"
void InitHardware(void);
#endif
InitOS.c
#include "InitOS.h"
#include "stm32f10x_nvic.h"
void InitHardware(void)
{
RCC_DeInit();
RCC_HSEConfig( RCC_HSE_ON );
while( RCC_GetFlagStatus( RCC_FLAG_HSERDY ) == RESET )
{
}
*( ( unsigned long * ) 0x40022000 ) = 0x02;
RCC_HCLKConfig( RCC_SYSCLK_Div1 );
RCC_PCLK2Config( RCC_HCLK_Div1 );
RCC_PCLK1Config( RCC_HCLK_Div2 );
RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_9 );
RCC_PLLCmd( ENABLE );
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK );
while( RCC_GetSYSCLKSource() != 0x08 )
{
}
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );
NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 );
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK );
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init( &NVIC_InitStructure );
}
STM32F10x.s(调整了串口中断等)
;
;
;
;
;
;
;
;
;
;
;
;
;
;
Stack_Size EQU 0x0000200
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
;
;
;
Heap_Size EQU 0x00000000
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
IMPORT xPortPendSVHandler
IMPORT xPortSysTickHandler
IMPORT vPortSVCHandler
IMPORT vTimer2IntHandler
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD vPortSVCHandler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD xPortPendSVHandler ; PendSV Handler
DCD xPortSysTickHandler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMAChannel1_IRQHandler ; DMA Channel 1
DCD DMAChannel2_IRQHandler ; DMA Channel 2
DCD DMAChannel3_IRQHandler ; DMA Channel 3
DCD DMAChannel4_IRQHandler ; DMA Channel 4
DCD DMAChannel5_IRQHandler ; DMA Channel 5
DCD DMAChannel6_IRQHandler ; DMA Channel 6
DCD DMAChannel7_IRQHandler ; DMA Channel 7
DCD ADC_IRQHandler ; ADC
DCD USB_HP_CAN_TX_IRQHandler ; USB High Priority or CAN TX
DCD USB_LP_CAN_RX0_IRQHandler ; USB Low Priority or CAN RX0
DCD CAN_RX1_IRQHandler ; CAN RX1
DCD CAN_SCE_IRQHandler ; CAN SCE
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_IRQHandler ; TIM1 Break
DCD TIM1_UP_IRQHandler ; TIM1 Update
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD vTimer2IntHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line
DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend
AREA |.text|, CODE, READONLY
; Reset Handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMAChannel1_IRQHandler [WEAK]
EXPORT DMAChannel2_IRQHandler [WEAK]
EXPORT DMAChannel3_IRQHandler [WEAK]
EXPORT DMAChannel4_IRQHandler [WEAK]
EXPORT DMAChannel5_IRQHandler [WEAK]
EXPORT DMAChannel6_IRQHandler [WEAK]
EXPORT DMAChannel7_IRQHandler [WEAK]
EXPORT ADC_IRQHandler [WEAK]
EXPORT USB_HP_CAN_TX_IRQHandler [WEAK]
EXPORT USB_LP_CAN_RX0_IRQHandler [WEAK]
EXPORT CAN_RX1_IRQHandler [WEAK]
EXPORT CAN_SCE_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_IRQHandler [WEAK]
EXPORT TIM1_UP_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT TIM4_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT I2C2_EV_IRQHandler [WEAK]
EXPORT I2C2_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT USART3_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT USBWakeUp_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMAChannel1_IRQHandler
DMAChannel2_IRQHandler
DMAChannel3_IRQHandler
DMAChannel4_IRQHandler
DMAChannel5_IRQHandler
DMAChannel6_IRQHandler
DMAChannel7_IRQHandler
ADC_IRQHandler
USB_HP_CAN_TX_IRQHandler
USB_LP_CAN_RX0_IRQHandler
CAN_RX1_IRQHandler
CAN_SCE_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_IRQHandler
TIM1_UP_IRQHandler
TIM1_TRG_COM_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
USBWakeUp_IRQHandler
B .
ENDP
ALIGN
; User Initial Stack & Heap
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
main.c
#include "InitOS.h"
#include "led.h"
#include "beep.h"
#include "key.h"
#include "usart.h"
#include "hardware.h"
#define LedTaskPriority (tskIDLE_PRIORITY+3)
#define LedTaskStakSize (configMINIMAL_STACK_SIZE + 50)
#define BeepTaskPriority (tskIDLE_PRIORITY+4)
#define BeepTaskStakSize (configMINIMAL_STACK_SIZE + 50)
#define UsartTaskPriority (tskIDLE_PRIORITY+10)
#define UsartTaskStakSize (configMINIMAL_STACK_SIZE + 1500)
void vTimer2IntHandler( void )
{
TIM2->SR &= (u16)~((u16)0x0001);
}
int main( void )
{
InitHardware();
InitLedEnv();
InitBeepEnv();
InitKeyEnv();
InitUsart(72, 9600);
xTaskCreate(LED0Task,"LED0",LedTaskStakSize,NULL,LedTaskPriority,NULL);
xTaskCreate(BeepTask,"BEEP",BeepTaskStakSize,NULL,BeepTaskPriority,NULL);
xTaskCreate(UsartCmdChlTask,"USART",UsartTaskStakSize,NULL,UsartTaskPriority,NULL);
vTaskStartScheduler();
return 0;
}
hardware.c
#include "InitOS.h"
#include "led.h"
#include "beep.h"
#include "key.h"
#include "usart.h"
#include "hardware.h"
#include "string.h"
void UsartCmdChlTask(void *pvParameters)
{
const u8 ENQ = 0x05;
const u8 EOT = 0x04;
const u8 Key0OpenCmd = 0x0F;
const u8 Key0CloseCmd = 0x10;
const u8 Key1OpenCmd = 0x11;
const u8 Key1CloseCmd = 0x12;
const u8 Key2OpenCmd = 0x13;
const u8 Key2CloseCmd = 0x14;
const u8 Key3OpenCmd = 0x15;
const u8 Key3CloseCmd = 0x16;
const u8 Key4OpenCmd = 0x17;
const u8 Key4CloseCmd = 0x18;
const u8 Key5OpenCmd = 0x19;
const u8 Key5CloseCmd = 0x1A;
const u8 Key6OpenCmd = 0x1B;
const u8 Key6CloseCmd = 0x1C;
const u8 Key7OpenCmd = 0x1D;
const u8 Key7CloseCmd = 0x1E;
const u8 BeepOpenCmd = 0x1F;
const u8 BeepCloseCmd = 0x20;
const char* machData="02 30 36 30 33 32 0D FF 20 52 45 53 55 4C 54 20 20 0D 21 20 30 31 31 2E 39 53 68 20 20 20 0D 22 20 30 32 2E 37 31 53 20 20 20 20 0D 23 20 30 32 32 2E 38 53 20 20 20 20 0D 24 20 30 30 2E 34 35 53 20 20 20 20 0D 25 20 30 30 33 2E 38 53 20 20 20 20 0D 28 20 30 38 2E 34 35 53 48 20 20 20 0D 29 20 30 37 31 2E 30 53 20 20 20 20 0D 2A 20 30 30 2E 31 33 53 20 20 20 20 0D 2B 20 30 30 31 2E 31 53 20 20 20 20 0D 2C 20 30 30 2E 31 35 53 20 20 20 20 0D 2D 20 30 30 31 2E 33 53 20 20 20 20 0D 2E 20 30 30 2E 30 34 53 20 20 20 20 0D 2F 20 30 30 30 2E 33 53 20 20 20 20 0D 30 20 30 30 2E 30 34 53 20 20 20 20 0D 31 20 30 30 30 2E 33 53 20 20 20 20 0D 32 20 30 34 2E 35 36 20 20 20 20 20 0D 33 20 30 31 33 2E 31 20 20 20 20 20 0D 34 20 30 33 39 2E 38 20 20 20 20 20 0D 35 20 30 30 30 38 37 20 20 20 20 20 0D 36 20 30 32 38 2E 37 20 20 20 20 20 0D 37 20 30 33 33 2E 30 20 20 20 20 20 0D 38 20 30 31 36 2E 31 20 68 20 20 20 0D 3A 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 40 20 30 30 32 36 33 20 20 20 20 20 0D 41 20 30 30 37 2E 39 20 20 20 20 20 0D 42 20 30 2E 32 30 39 20 20 20 20 20 0D 43 20 30 31 32 2E 35 20 20 20 20 20 0D 50 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 51 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 52 20 20 20 20 20 0D 53 20 20 20 20 20 20 20 0D 54 20 4E 45 55 2B 0D 55 20 0D 56 20 0D 57 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 27 3D 66 AE F0 FF E5 B7 89 75 6B 64 60 5E 60 5E 5E 5F 5D 51 43 3B 35 33 31 2F 2D 2C 2A 29 28 27 26 26 25 25 25 24 24 24 23 23 23 23 23 22 21 21 21 21 21 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 58 20 20 20 20 20 20 20 20 20 20 20 20 21 20 20 20 20 20 20 20 20 20 21 24 29 30 3D 4B 5F 7C 98 B2 CD DF F2 FB FD FF F8 E9 DA CA B5 9D 8B 80 73 67 5B 51 4C 47 41 3B 38 34 2F 2D 2D 2A 27 26 24 23 22 22 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 59 20 20 20 20 20 20 20 20 20 20 20 26 34 48 63 7E A0 C2 E3 F8 FF FF FF F8 F1 EA E3 D6 CF C8 BB B4 A7 A0 92 8C 85 7E 77 77 71 6A 63 63 5C 56 56 4F 4F 48 3B 3B 34 34 2D 2D 26 26 26 26 26 26 26 26 26 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 5A 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 25 3D 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 3F 38 35 32 31 30 2E 2C 2A 2B 29 27 27 26 26 26 25 27 23 25 24 23 24 24 23 22 23 21 22 22 22 21 22 21 21 22 21 21 20 20 21 20 21 20 20 21 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 21 0D 5B 20 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 36 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 38 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 36 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 30 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 42 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 30 31 31 34 31 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 36 30 30 30 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 36 31 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 42 32 38 38 38 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 38 35 34 46 43 31 30 30 30 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 31 31 41 44 35 35 38 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 31 31 35 31 46 31 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 33 42 46 33 46 33 30 30 30 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 44 46 36 38 34 30 38 30 30 30 30 30 30 30 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 38 42 43 45 39 30 30 34 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 31 45 42 46 46 45 41 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 43 37 46 46 46 46 34 30 32 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 38 37 46 46 46 39 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 36 37 46 46 46 46 44 32 30 30 30 30 30 30 30 30 30 30 33 30 30 30 30 30 30 30 30 30 30 30 30 31 35 46 44 46 46 46 44 41 34 30 38 30 30 34 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 32 33 46 46 46 46 46 44 32 30 30 30 30 30 30 30 32 30 38 30 30 30 30 30 30 30 30 30 32 30 30 30 31 42 46 46 46 46 46 44 34 34 32 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 46 46 46 46 46 42 45 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 35 46 46 46 46 44 41 30 30 30 30 30 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 35 41 46 46 46 46 45 46 31 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 30 30 30 30 30 30 44 46 46 46 46 46 34 45 38 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 31 46 46 46 46 46 45 33 30 30 30 38 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 46 46 46 46 46 46 39 31 34 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 42 46 46 46 46 46 38 30 30 30 32 30 30 30 32 31 38 30 30 30 30 30 30 30 30 30 30 30 30 30 32 37 46 46 46 46 46 46 41 36 38 30 30 30 34 30 30 31 30 30 30 30 30 30 30 30 30 31 30 30 30 30 31 42 36 46 46 46 46 44 41 43 43 30 32 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 37 46 46 46 46 46 45 30 30 32 30 38 30 30 30 38 31 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 37 46 46 46 46 46 44 36 30 30 30 32 30 30 30 30 34 30 30 30 30 30 30 30 30 30 31 30 30 30 30 33 37 46 46 46 46 46 46 38 34 30 30 30 30 30 38 30 30 43 34 30 31 30 30 30 30 30 30 38 30 30 30 31 33 46 46 46 46 46 42 43 30 30 30 30 34 30 30 38 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 32 46 46 46 46 46 46 46 41 34 30 30 30 34 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 39 46 46 46 46 46 46 45 30 37 46 30 32 30 30 30 33 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 42 46 46 46 46 46 44 43 34 39 36 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 46 46 46 46 46 43 39 30 30 30 30 32 41 41 30 30 30 30 30 30 32 30 30 30 30 30 30 30 30 30 30 33 46 46 46 46 46 43 43 41 30 34 34 43 36 31 30 32 31 30 30 34 30 30 30 30 30 30 30 30 30 30 32 31 46 46 46 46 46 35 39 39 31 32 34 31 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 46 46 46 46 43 37 34 30 39 31 41 35 34 30 30 30 34 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 46 44 46 42 46 46 39 36 32 31 36 31 33 31 32 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 32 46 45 46 45 46 45 36 43 44 42 35 32 32 34 41 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 45 36 46 44 45 45 39 36 32 42 46 32 38 34 31 30 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 32 41 33 37 46 33 45 34 45 35 46 31 37 45 34 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 32 32 34 42 41 35 32 46 45 35 44 43 34 41 41 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32 37 32 30 42 37 44 31 37 39 31 45 45 38 45 36 30 38 30 30 30 30 30 30 31 30 30 30 30 30 30 31 30 30 39 44 45 37 41 43 46 37 39 34 43 36 33 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 36 32 37 45 36 45 37 36 45 35 39 37 35 33 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 32 46 37 37 45 46 45 38 46 43 39 34 36 30 31 30 31 34 30 30 30 30 30 30 30 30 30 30 30 32 33 37 46 46 46 46 46 36 45 42 45 33 35 31 31 38 30 30 32 30 30 30 30 30 31 30 30 30 30 30 32 31 31 46 46 46 46 46 46 44 44 46 34 43 34 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 38 33 46 46 46 46 46 46 44 45 41 34 30 30 34 30 30 30 30 30 38 30 31 30 30 30 30 30 30 30 30 30 33 46 37 46 46 46 46 46 41 35 44 30 30 30 34 30 30 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 46 46 46 46 46 46 46 45 38 36 34 31 30 32 31 30 32 30 30 38 30 30 30 30 30 30 30 30 30 30 30 39 42 46 46 46 46 46 46 36 38 44 30 32 38 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 35 46 46 46 46 46 46 32 36 39 30 30 30 30 30 30 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 42 46 46 46 44 44 42 30 45 30 30 31 30 32 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 31 34 44 46 37 46 46 46 33 30 38 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 37 46 42 46 46 31 43 30 34 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 35 30 33 46 39 37 31 32 33 31 30 34 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 30 30 34 31 31 41 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 38 31 38 36 36 42 32 30 41 30 30 30 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 30 30 38 30 42 43 34 30 33 39 42 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 41 32 38 30 34 32 31 35 38 34 31 30 30 30 34 30 30 31 30 30 30 30 38 30 30 30 30 30 30 30 30 30 30 30 31 30 30 38 30 30 30 30 31 30 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0D 5D 20 30 31 32 20 30 36 37 20 31 32 30 20 30 30 30 20 30 30 30 0D 5E 20 30 32 34 20 30 34 39 0D 5F 20 30 39 38 0D 60 20 30 31 32 20 30 36 37 20 31 32 30 0D 61 20 30 32 34 20 30 32 37 20 30 35 30 20 30 33 35 20 31 31 38 20 30 33 31 20 30 37 32 20 30 37 33 20 31 30 30 20 30 37 32 20 31 30 30 20 31 31 38 20 30 32 37 20 30 36 37 20 30 35 31 20 30 30 32 20 30 30 32 20 30 30 32 0D 66 20 20 20 20 20 4C 6D 6E 65 2D 20 20 20 20 20 0D 70 20 30 31 0D 71 20 31 39 2F 31 31 2F 31 34 20 31 30 68 33 39 6D 6E 34 39 73 0D 72 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 73 20 30 30 30 30 0D 75 20 31 30 32 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 76 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 77 20 20 20 20 20 20 20 20 20 0D 78 20 20 20 20 0D 79 20 30 0D 7B 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 7C 20 20 20 20 20 20 20 20 20 20 20 0D 7D 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 7F 20 41 42 58 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 80 20 42 0D 83 20 41 42 58 0D 8B 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0D 90 20 30 31 33 38 32 20 30 31 33 30 37 20 30 31 33 39 36 20 30 31 33 37 37 20 30 31 34 32 31 20 30 31 34 36 33 20 30 31 33 31 38 20 30 31 33 39 33 20 30 31 33 37 37 20 30 31 33 39 39 20 30 31 34 34 34 20 30 31 33 34 35 20 30 38 33 34 37 20 30 38 32 37 37 0D 91 20 30 33 35 34 37 20 30 33 35 33 38 20 30 33 36 36 36 20 30 33 36 30 33 20 30 33 36 34 34 20 30 33 35 39 33 20 30 33 36 34 35 20 30 33 37 32 30 20 30 33 36 31 31 20 30 33 35 36 32 20 30 33 35 32 32 20 30 33 35 37 39 20 32 31 35 39 32 20 32 31 36 34 30 0D 92 20 30 32 30 31 35 20 30 32 30 31 35 20 30 32 30 31 35 20 30 30 30 30 30 20 30 30 30 30 30 20 30 30 30 30 30 20 30 30 30 30 30 20 30 30 30 30 30 20 30 30 30 30 30 20 30 30 30 30 30 20 30 30 30 30 30 20 30 30 30 30 30 20 30 32 30 31 35 20 30 33 36 33 36 0D 93 20 30 32 37 37 39 31 32 20 30 32 37 37 34 37 35 20 30 32 38 35 34 31 35 20 30 32 37 37 34 33 36 20 30 32 38 30 39 36 34 20 30 32 37 36 39 34 31 20 30 32 38 30 34 34 32 20 30 32 38 34 34 35 30 20 30 32 37 39 31 31 36 20 30 32 37 33 33 35 33 20 30 32 36 39 38 36 32 20 30 32 37 35 32 31 39 20 31 36 37 36 31 34 34 20 31 36 36 32 34 34 33 0D 94 20 30 32 36 31 31 20 30 32 36 36 37 20 30 32 37 31 38 20 30 32 36 34 30 20 30 32 36 36 37 20 30 32 35 39 31 20 30 32 36 32 33 20 30 32 36 36 34 20 30 32 36 30 34 20 30 32 35 39 31 20 30 32 36 32 31 20 30 32 36 34 34 20 31 35 38 39 35 20 31 35 37 34 38 0D 95 20 30 31 33 38 32 20 30 31 33 30 37 20 30 31 33 39 36 20 30 31 33 37 37 20 30 31 34 32 31 20 30 31 34 36 33 20 30 31 33 31 38 20 30 31 33 39 33 20 30 31 33 37 37 20 30 31 33 39 39 20 30 31 34 34 34 20 30 31 33 34 35 20 30 38 33 34 37 20 30 38 32 37 37 0D 96 20 30 36 30 33 38 20 30 30 30 39 33 0D A3 20 56 0D A4 20 31 0D A5 20 31 0D A6 20 31 0D A7 20 31 0D FD 20 38 38 62 38 0D 03\r\n";
while (1)
{
if (USART_RX_BUF_HASDATA == 1)
{
u8 len = USART_RX_BUF_CUTINDEX;
int cmdStart = 0;
int cmdStartIndex = 0;
u8 cmd;
for (u8 t = 0; t < len; t++)
{
if (USART_RX_BUF[t] == ENQ)
{
cmdStart = 1;
cmdStartIndex = t;
continue;
}
if (cmdStart == 1)
{
cmd = USART_RX_BUF[t];
cmdStart = 0;
}
if (USART_RX_BUF[t] == EOT && (t - cmdStartIndex) == 2)
{
if (cmd == Key0OpenCmd)
{
LED0Open();
}
else if (cmd == Key0CloseCmd)
{
LED0Close();
}
else if (cmd == Key1OpenCmd)
{
LED1Open();
}
else if (cmd == Key1CloseCmd)
{
LED1Close();
}
else if (cmd == Key2OpenCmd)
{
LED2Open();
}
else if (cmd == Key2CloseCmd)
{
LED2Close();
}
else if (cmd == Key3OpenCmd)
{
LED3Open();
}
else if (cmd == Key3CloseCmd)
{
LED3Close();
}
else if (cmd == Key4OpenCmd)
{
LED4Open();
}
else if (cmd == Key4CloseCmd)
{
LED4Close();
}
else if (cmd == Key5OpenCmd)
{
LED5Open();
}
else if (cmd == Key5CloseCmd)
{
LED5Close();
}
else if (cmd == Key6OpenCmd)
{
LED6Open();
}
else if (cmd == Key6CloseCmd)
{
LED6Close();
}
else if (cmd == Key7OpenCmd)
{
LED7Open();
}
else if (cmd == Key7CloseCmd)
{
LED7Close();
}
else if (cmd == BeepOpenCmd)
{
BeepOpen();
}
else if (cmd == BeepCloseCmd)
{
BeepClose();
}
printf("收到命令:");
USART1->DR = cmd;
while ((USART1->SR & 0X40) == 0);
printf("\r\n");
}
}
USART_RX_BUF_HASDATA = 0;
}
int key = GetPressKey(0);
if (key >= 0)
{
if (key == 0)
{
printf("KEY0\r\n");
}
else if (key == 1)
{
printf("KEY1\r\n");
}
else if (key == 2)
{
printf("KEY2\r\n");
}
else if (key == 3)
{
GPIOC->ODR |= 1 << 0;
BeepOpen();
vTaskDelay(10);
BeepClose();
U8Send(machData);
vTaskDelay(10);
printf("zlz\r\n");
}
}
vTaskDelay(10);
}
}
int LED_IS_INIT = 0;
int BEEP_IS_INIT = 0;
void LED0Open(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR &= ~(1 << 0);
}
void LED0Close(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR |= 1 << 0;
}
void LED1Open(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR &= ~(1 << 1);
}
void LED1Close(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR |= 1 << 1;
}
void LED2Open(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR &= ~(1 << 2);
}
void LED2Close(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR |= 1 << 2;
}
void LED3Open(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR &= ~(1 << 3);
}
void LED3Close(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR |= 1 << 3;
}
void LED4Open(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR &= ~(1 << 4);
}
void LED4Close(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR |= 1 << 4;
}
void LED5Open(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR &= ~(1 << 5);
}
void LED5Close(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR |= 1 << 5;
}
void LED6Open(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR &= ~(1 << 6);
}
void LED6Close(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR |= 1 << 6;
}
void LED7Open(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR &= ~(1 << 7);
}
void LED7Close(void)
{
if (LED_IS_INIT == 0)
{
InitLedEnv();
LED_IS_INIT = 1;
}
GPIOC->ODR |= 1 << 7;
}
void BeepOpen(void)
{
if (BEEP_IS_INIT == 0)
{
InitBeepEnv();
BEEP_IS_INIT = 1;
}
GPIOB->ODR &= ~(1 << 8);
}
void BeepClose(void)
{
if (BEEP_IS_INIT == 0)
{
InitBeepEnv();
BEEP_IS_INIT = 1;
}
GPIOB->ODR |= 1 << 8;
}
void U8Send(const char * str)
{
int len=strlen(str);
for(int i=0;i<len;i+=3)
{
if(i+1<len)
{
char one=str[i];
char tow=str[i+1];
u8 oneHex=HexToInt(one)*16+HexToInt(tow);
USART1->DR = oneHex;
while ((USART1->SR & 0X40) == 0);
}
}
}
int HexToInt(char c)
{
if(c=='0')
{
return 0;
}
else if(c=='1')
{
return 1;
}
else if(c=='2')
{
return 2;
}
else if(c=='3')
{
return 3;
}
else if(c=='4')
{
return 4;
}
else if(c=='5')
{
return 5;
}
else if(c=='6')
{
return 6;
}
else if(c=='7')
{
return 7;
}
else if(c=='8')
{
return 8;
}
else if(c=='9')
{
return 9;
}
else if(c=='A')
{
return 10;
}
else if(c=='B')
{
return 11;
}
else if(c=='C')
{
return 12;
}
else if(c=='D')
{
return 13;
}
else if(c=='E')
{
return 14;
}
else if(c=='F')
{
return 15;
}
return 16;
}
|