本帖最后由 jinglixixi 于 2022-9-29 09:04 编辑
尽管在ESK32-21001扩展板上配有I2S功能单元,但HT32F54253却没有 I2S接口,因此就无法借助它来实现语音播放功能了。为此,我们可以借助MP3功能模块来实现音乐播放的功能,其外观及引脚布局见图1所示。
图1 MP3功能模块
MP3功能模块支持2种工作模式,即按键操控模式和串口控制模式。为了便于直观地以菜单的方式来选取乐曲,是由MDM_2802显示模块来显示播放菜单,并以“★”来进行指示标识,其界面效果如图2所示。
图2 界面效果
进行选取操作则是通过扩展板上机械按键,并采用巡回的处理方式来处理,其效果如图3所示。
图3 菜单选择
在菜单选取时,K1键是向下选取,K2键则是向上选取。,按键的电路连接如图4所示。
图4 按键原理图
K1键的处理函数为:void KEY1(void)
{
int i;
FlagStatus InputStatus = SET;
InputStatus = GPIO_ReadInBit(HT_GPIOB, GPIO_PIN_2);
if(InputStatus == RESET)
{
if(w<180)
{
showhanzi16(30,75+w,37,RED,RED);
playn(w/30);
w=w+30;
showhanzi16(30,75+w,37,YELLOW,RED);
for(i=0; i<10; i++)
{
UxART_TxSend(cmd3[i]);
}
}
else
{
showhanzi16(30,255,37,RED,RED);
w=0;
showhanzi16(30,75+w,37,YELLOW,RED);
}
while(GPIO_ReadInBit(HT_GPIOB, GPIO_PIN_2) == RESET);
}
}
K2键的处理函数为:void KEY2(void)
{
int i;
FlagStatus InputStatus = SET;
InputStatus = GPIO_ReadInBit(HT_GPIOD, GPIO_PIN_3);
if(InputStatus == RESET)
{
if(w>=30)
{
showhanzi16(30,75+w,37,RED,RED);
playn(w/30);
w=w-30;
showhanzi16(30,75+w,37,YELLOW,RED);
for(i=0; i<10; i++)
{
UxART_TxSend(cmd3[i]);
}
}
else
{
showhanzi16(30,75,37,RED,RED);
w=180;
showhanzi16(30,255,37,YELLOW,RED);
}
while(GPIO_ReadInBit(HT_GPIOD, GPIO_PIN_3) == RESET);
}
}
在MP3功能模块的控制上是将其RX引脚与PA4相连接,从而接收核心板所发送的指令,其测试结果如图6所示。 图5 串口通信接口
图6 指令发送
实现菜单显示及选择处理的主程序为:int main(void)
{
HT32F_DVB_LEDInit(HT_LED1);
UxART_Configuration();
UxART_TxTest();
app_tft_init();
ili9341_init();
ili9341_clear(RED);
LCD_DrawLine(WHITE ,0, 50, 239, 50);
LCD_DrawLine(WHITE,0, 290, 239, 290);
BACK_COLOR=RED;
POINT_COLOR=YELLOW;
showimage();
GUI_DispChar('M', 80,16);
GUI_DispChar('P', 90,16);
GUI_DispChar('3', 100,16);
showhanzi16(115,16,32,WHITE,RED);
showhanzi16(135,16,33,WHITE,RED);
showhanzi16(155,16,34,WHITE,RED);
showhanzi16(175,16,35,WHITE,RED);
showhanzi16(195,16,36,WHITE,RED);
showhanzi16(60,75,0,YELLOW,RED);
showhanzi16(80,75,1,YELLOW,RED);
showhanzi16(100,75,2,YELLOW,RED);
showhanzi16(30,75,37,YELLOW,RED);
showhanzi16(60,105,3,YELLOW,RED);
showhanzi16(80,105,4,YELLOW,RED);
showhanzi16(100,105,5,YELLOW,RED);
showhanzi16(120,105,6,YELLOW,RED);
showhanzi16(60,135,7,YELLOW,RED);
showhanzi16(80,135,8,YELLOW,RED);
showhanzi16(60,165,9,YELLOW,RED);
showhanzi16(80,165,10,YELLOW,RED);
showhanzi16(60,195,11,YELLOW,RED);
showhanzi16(80,195,12,YELLOW,RED);
showhanzi16(100,195,13,YELLOW,RED);
showhanzi16(120,195,14,YELLOW,RED);
showhanzi16(60,225,15,YELLOW,RED);
showhanzi16(80,225,16,YELLOW,RED);
showhanzi16(100,225,17,YELLOW,RED);
showhanzi16(120,225,18,YELLOW,RED);
showhanzi16(140,225,19,YELLOW,RED);
showhanzi16(60,255,20,YELLOW,RED);
showhanzi16(80,255,21,YELLOW,RED);
showhanzi16(100,255,22,YELLOW,RED);
showhanzi16(120,255,23,YELLOW,RED);
showhanzi16(140,255,24,YELLOW,RED);
showhanzi16(160,255,25,YELLOW,RED);
showhanzi16(180,255,26,YELLOW,RED);
LCD_ShowString(60,294,"BY: jinglixixi");
key_Configuration();
while (1)
{
KEY1();
KEY2();
}
}
|