[ESK32-360 Review] + Button control LED number running lights flash, and there is a prompt sound when pressing the button
[Copy link]
This post was last edited by szkei on 2020-8-8 23:18
1. Acknowledgments.
I have known Hetai since 2010, but I could not use Hetai because I could not afford to buy a programmer. Ten years have passed in a flash. In July, I came to EEWROLD and found that Hetai ESK32-360 development board was being evaluated. I applied immediately. As a result, EEWROLD gave me this opportunity to have a close contact with Hetai. When I received the board, I felt inexplicably excited and wanted to open the package to see the real appearance of [ESK32-360 development board]. However, I was determined enough and waited until I got home to open it. The unexpected result was that the packaging of the development board from the outside to the inside was so exquisite, and it was made of real materials. This is the good result of EEWROLD and Hetai staff's meticulous work requirements. Thanks to EEWROLD and Hetai staff for their concern for the experiencers.
2. The true appearance of [ESK32-360 development board].
After unpacking, I was attracted by the large size of the development board, especially the layout of the development board according to the standard requirements of the textbook, with horizontal lines on the top layer and vertical lines on the bottom layer, and the silk screen printing close to the component package. It is so professional. Let's see it together in the picture.
3. Test objectives and introduction.
In most cases, every experiencer starts with lighting the development board, which is the most basic test for each MCU. From the title, we can see that the number of LEDs is controlled by pressing the button.
1. Use the wakeup button to control the flashing of an LED light.
2. Key1 controls the flashing of two lights.
3. Press key2 to make the three materials flash.
4. When power is turned on, all LEDs are in OFF state.
Fourth, keil5 environment construction and function implementation.
1. Establish the environment. Since the information of Hetai MCU is relatively less than that of others, we can only use the routines given in this evaluation for transplantation.
2. Unzip the attached “ HT32_STD_1xxxx_FWLib_v004_2103.zip ” compressed package. Change the folder “HT32_STD_1xxxx_FWLib_v004_2103” to “EEWORLD_HT32F1654_TEST__LED+BUZZER”. Then open ..\project_template\IP\Example and delete the maic.c file. Then open the folder MDK_ARMv5 and double-click Project_1654.uvprojx.
3. After opening the keil5 software, create a new main.c file under User in the left project column and add the header file as follows
#include "ht32.h"
#include "ht32_board.h"
#include "ht32_board_config.h"
4. The following functions are needed to create this title.
5. Regarding port initialization, Hetai provides a simple and practical function. For details, please refer to the HT32F1xxxx_Programmer_Guide_v004_2103.chm file in the example program, find the location of the figure below, and check the method function under Functions.
6. This test only uses the following 7 functions:
void HT32F_DVB_LEDInit (LED_TypeDef HT_LEDn); //LED initialization
void HT32F_DVB_LEDOn (LED_TypeDef HT_LEDn); //LED on
void HT32F_DVB_LEDOff (LED_TypeDef HT_LEDn); //LED off
void HT32F_DVB_PBInit (BUTTON_TypeDef BUTTON_x, BUTTON_MODE_TypeDef BUTTON_MODE_x); //Button initialization
u32 HT32F_DVB_PBGetState (BUTTON_TypeDef BUTTON_x); //Get button status
void HT32F_DVB_BuzzerFun (u16 hFreq, u8 bDuty, u32 mode); //Buzzer initialization
void HT32F_DVB_BuzzerOutputCmd (ControlStatus Control) ; //Buzzer enable
Each function has a detailed explanation, and it is worth it for other software personnel to read this help document, which will give an unexpected benefit and can be regarded as a self-communication and improvement manual.
7. The specific implementation code is as follows:
When you press a key, the buzzer will sound once, and it will sound again only when you release the key and press it again.
#include "ht32.h"
#include "ht32_board.h"
#include "ht32_board_config.h"
u8 led_show_amount_value = 0; //led显示数量值
u8 forx = 0; //循环显示
bool key_down_flag = FALSE; //按键按下状态
void LED_Init(void);
void LED_Function(void);
void SET_LED_SHOW_COUNT(void);
void Delay(u32 clock);
int main(void){
LED_Init();
while(1){
LED_Function();
}
}
void LED_Init(void){
/* LED初始化 */
HT32F_DVB_LEDInit(HT_LED1);
HT32F_DVB_LEDInit(HT_LED2);
HT32F_DVB_LEDInit(HT_LED3);
/* 按键初始化 */
HT32F_DVB_PBInit(BUTTON_WAKEUP,BUTTON_MODE_GPIO);
HT32F_DVB_PBInit(BUTTON_KEY1,BUTTON_MODE_GPIO);
HT32F_DVB_PBInit(BUTTON_KEY2,BUTTON_MODE_GPIO);
/* LED状态关闭 */
HT32F_DVB_LEDOff(HT_LED1);
HT32F_DVB_LEDOff(HT_LED2);
HT32F_DVB_LEDOff(HT_LED3);
HT32F_DVB_BuzzerFun(2400,50,0); //蜂鸣器初始化
}
void SET_LED_SHOW_COUNT(void){
if(HT32F_DVB_PBGetState(BUTTON_WAKEUP) == SET){
if(!key_down_flag){
HT32F_DVB_BuzzerOutputCmd(ENABLE); //使能蜂鸣器
key_down_flag = TRUE;
}else{
HT32F_DVB_BuzzerOutputCmd(DISABLE); //禁止使能蜂鸣器
}
led_show_amount_value = 1;
}else if(HT32F_DVB_PBGetState(BUTTON_KEY1) == RESET){
if(!key_down_flag){
HT32F_DVB_BuzzerOutputCmd(ENABLE);
key_down_flag = TRUE;
}else{
HT32F_DVB_BuzzerOutputCmd(DISABLE); //禁止使能蜂鸣器
}
led_show_amount_value = 2;
}else if(HT32F_DVB_PBGetState(BUTTON_KEY2) == RESET){
if(!key_down_flag){
HT32F_DVB_BuzzerOutputCmd(ENABLE);
key_down_flag = TRUE;
}else{
HT32F_DVB_BuzzerOutputCmd(DISABLE); //禁止使能蜂鸣器
}
led_show_amount_value = 3;
}else if(key_down_flag){
HT32F_DVB_BuzzerOutputCmd(DISABLE); //禁止使能蜂鸣器
key_down_flag = FALSE;
}
}
void Delay(u32 clock){
do{
__NOP();
}while(clock--);
}
void LED_Function(void){
SET_LED_SHOW_COUNT();
for(forx = 0;forx < led_show_amount_value;forx++){
Delay(3000000);
SET_LED_SHOW_COUNT();
HT32F_DVB_LEDOn((LED_TypeDef)forx);
Delay(3000000);
SET_LED_SHOW_COUNT();
HT32F_DVB_LEDOff((LED_TypeDef)forx);
}
}
5. Thoughts after use.
The official provision of these functions is undoubtedly a blessing for some software engineers who do not understand hardware. Click the code HT_LED1 and select the definition to pop up ht32f1654_dvb.h. In this file, you can modify the desired port to quickly define and use this port, which will bring developers a qualitative speed and code quality, and reduce many other unknown BUGs written by individuals.
6. Video and the original code of the entire test project.
Video address: https://training.eeworld.com.cn/course/5749/learn?preview=1#lesson/26888
Original code
EEWORLD_HT32F1654_TEST__LED BUZZER.rar
(4.73 MB, downloads: 0)
|