@@ -10,88 +10,3 @@ TIM2->ARR = (uint32_t)((72000000/freq)-1);TIM2->CCR3 = (uint32_t)(((72000000/fr
|
||||
|
||||
|
||||
|
||||
void add_a_note(uint16_t freq,uint8_t duty,uint16_t deley)
|
||||
{
|
||||
struct notes* buff;
|
||||
buff = (struct notes*)malloc(sizeof(struct notes));
|
||||
if (buff != NULL)
|
||||
{
|
||||
buff->freq = freq;
|
||||
buff->duty = duty;
|
||||
buff->deley = deley;
|
||||
buff->next_note = NULL;
|
||||
|
||||
if (notes == NULL)
|
||||
{
|
||||
notes = buff;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct notes *t = notes;
|
||||
while (t->next_note != NULL)
|
||||
{
|
||||
t = t->next_note;
|
||||
}
|
||||
t->next_note = buff;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void delhead()
|
||||
{
|
||||
if (notes == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (notes->next_note == NULL)
|
||||
{
|
||||
free(notes);
|
||||
notes = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct notes *t = notes;
|
||||
notes = notes->next_note;
|
||||
free(t);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
char buzzer_play_server()
|
||||
{
|
||||
|
||||
|
||||
static char busy_flag=0;
|
||||
static uint32_t play_delay;
|
||||
|
||||
if(notes == NULL)
|
||||
{
|
||||
play_ones(0,0);
|
||||
}else
|
||||
{
|
||||
if(busy_flag==0)
|
||||
{
|
||||
busy_flag=1;
|
||||
play_delay=HAL_GetTick()+notes->deley;
|
||||
play_ones(notes->freq,notes->duty);
|
||||
}
|
||||
if(busy_flag==1)
|
||||
{
|
||||
if(HAL_GetTick()>play_delay)
|
||||
{
|
||||
busy_flag=0;
|
||||
delhead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return busy_flag;
|
||||
}
|
||||
@@ -3,16 +3,9 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
struct notes
|
||||
{
|
||||
uint16_t freq;
|
||||
uint8_t duty;
|
||||
uint16_t deley;
|
||||
struct notes *next_note;
|
||||
};
|
||||
|
||||
|
||||
void play_ones(uint16_t freq,uint8_t dutya);
|
||||
void add_a_note(uint16_t freq,uint8_t duty,uint16_t deley);
|
||||
char buzzer_play_server();
|
||||
|
||||
|
||||
#endif /* BUZZER_H_ */
|
||||
|
||||
@@ -177,6 +177,8 @@ char sys_lan=0;
|
||||
|
||||
int encode_c=0;
|
||||
|
||||
int test_code=0;
|
||||
|
||||
menu menu_main=
|
||||
{
|
||||
"Back\nInput\nBuzzer\nOLED\nAuto\nType\nLanguage\nAbout",
|
||||
@@ -194,10 +196,10 @@ void mymain()
|
||||
|
||||
OLED_Init();//屏幕初始化
|
||||
HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_3);//启动n通道的pwm
|
||||
MUTE(1);//静音
|
||||
//add_a_note(1000,50,1000);//开机响一声
|
||||
|
||||
|
||||
HAL_TIM_Base_Start_IT(&htim3);
|
||||
MUTE(0);
|
||||
|
||||
//play_ones(1000,50);
|
||||
while(1)
|
||||
{
|
||||
|
||||
@@ -218,6 +220,9 @@ void mymain()
|
||||
encode_c+=GET_ENCODE(&E1);
|
||||
sprintf(str,"ENCODE:%d",encode_c);
|
||||
OLED_Str(0,8,8,str,1);
|
||||
|
||||
sprintf(str,"testcode:%d",test_code);
|
||||
OLED_Str(0,16,8,str,1);
|
||||
|
||||
fps_++;
|
||||
sprintf(str,"FPS:%d",fps);
|
||||
@@ -247,7 +252,7 @@ void mymain()
|
||||
|
||||
GEI_BUTTON_CODE(&B1);//循环更新按钮
|
||||
OLED_Cache_to_hardware();//刷新屏幕
|
||||
buzzer_play_server();
|
||||
|
||||
if(HAL_GetTick()>run_tick)
|
||||
{
|
||||
run_tick+=1000;
|
||||
@@ -266,22 +271,40 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
switch (GPIO_Pin)
|
||||
{
|
||||
case en_a_Pin:
|
||||
switch(HAL_GPIO_ReadPin(en_b_GPIO_Port,en_b_Pin))
|
||||
{
|
||||
case 1:
|
||||
E1.code+=1;
|
||||
E1.move_flag=1;
|
||||
break;
|
||||
case 0:
|
||||
E1.code-=1;
|
||||
E1.move_flag=1;
|
||||
break;
|
||||
}
|
||||
switch(HAL_GPIO_ReadPin(en_b_GPIO_Port,en_b_Pin))
|
||||
{
|
||||
case 1:
|
||||
E1.code+=1;
|
||||
E1.move_flag=1;
|
||||
break;
|
||||
case 0:
|
||||
E1.code-=1;
|
||||
E1.move_flag=1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case tack_a_Pin:
|
||||
test_code++;
|
||||
break;
|
||||
case tack_b_Pin:
|
||||
test_code--;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
//__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)//1ms
|
||||
{
|
||||
if (htim == (&htim3))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@ struct morsecode
|
||||
char letter;
|
||||
};
|
||||
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
|
||||
void mymain();
|
||||
|
||||
#endif /* MYMAIN_H_ */
|
||||
|
||||
Reference in New Issue
Block a user