#申请原创#
为了充分利用新定义MCU开发板的资源,尤其是发挥触控板的特色而制作了该触控式MP3播放器。 它通过滑条来控制音量,以滑环来选择乐曲,以触控键来改变播放。此外,为了能更显示出歌曲名称,还为它配置了0.96寸的OLED屏。MP3播放模块则是由UART1来控制,其整体构成如图1所示。 其中: OLED_SCL连接P44 OLED-SDA连接P45 MP3_RX 连接P13 图1 整体构成
为实现中文歌单的显示,特配置了相应的中文字库,其结构如下: unsigned char Hzk[][32]={
{0x20,0xC2,0x0C,0x80,0x04,0xA4,0xA4,0xBF,0xA4,0xA4,0x04,0x08,0x84,0x63,0x00,0x00},
{0x04,0x04,0x7E,0x01,0x40,0xCF,0x54,0x44,0x34,0x2F,0xA0,0x41,0x20,0x18,0x06,0x00},
{0x10,0x60,0x02,0x8C,0x00,0x88,0x88,0xFF,0x88,0x88,0x00,0xFE,0x22,0x22,0xFE,0x00},
{0x04,0x04,0x7E,0x01,0x00,0x1F,0x08,0x08,0x08,0x9F,0x60,0x1F,0x42,0x82,0x7F,0x00},
{0x10,0x60,0x02,0x8C,0x24,0x94,0x84,0xBD,0x86,0x84,0xBC,0x84,0x14,0x24,0x00,0x00},
{0x04,0x04,0x7E,0x01,0x00,0x0E,0x0A,0x0A,0x0A,0x4A,0x8A,0x4B,0x38,0x00,0x00,0x00},
....
};
对于该字库其汉字显示函数为: void OLED_ShowCHinese(u8 x,u8 y,u8 no)
{
u8 t,adder=0;
OLED_Set_Pos(x,y);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
adder+=1;
}
OLED_Set_Pos(x,y+1);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
adder+=1;
}
}
为便于在播放乐曲的时候及时显示出歌曲名称,特配置了一个供OLED屏来显示的菜单函数,其内容如下: void Menu(int m)
{
OLED_ShowNum(0,2,m-3,2,16);
OLED_ShowChar(16,2,'-',16);
OLED_ShowString(30,2," ",16);
OLED_ShowString(30,4," ",16);
if(m==1)
{
OLED_ShowCHinese(30,2,0);
OLED_ShowCHinese(46,2,1);
OLED_ShowCHinese(62,2,2);
}
if(m==2)
{
OLED_ShowCHinese(30,2,3);
OLED_ShowCHinese(46,2,4);
OLED_ShowCHinese(62,2,5);
OLED_ShowCHinese(78,2,6);
}
if(m==3)
{
OLED_ShowCHinese(30,2,7);
OLED_ShowCHinese(46,2,8);
}
if(m==4)
{
OLED_ShowCHinese(30,2,9);
OLED_ShowCHinese(46,2,10);
}
if(m==5)
{
OLED_ShowCHinese(30,2,11);
OLED_ShowCHinese(46,2,12);
OLED_ShowCHinese(62,2,13);
OLED_ShowCHinese(78,2,14);
}
if(m==6)
{
OLED_ShowCHinese(30,2,15);
OLED_ShowCHinese(46,2,16);
OLED_ShowCHinese(62,2,17);
OLED_ShowCHinese(78,2,18);
OLED_ShowCHinese(94,2,19);
}
if(m==7)
{
OLED_ShowCHinese(30,2,20);
OLED_ShowCHinese(46,2,21);
}
if(m==8)
{
OLED_ShowCHinese(30,2,22);
OLED_ShowCHinese(46,2,23);
OLED_ShowCHinese(62,2,24);
OLED_ShowCHinese(78,2,25);
OLED_ShowCHinese(94,2,26);
OLED_ShowCHinese(30,4,27);
OLED_ShowCHinese(46,4,28);
}
if(m==9)
{
OLED_ShowCHinese(30,2,20);
OLED_ShowCHinese(46,2,21);
}
if(m==10)
{
OLED_ShowCHinese(30,2,29);
OLED_ShowCHinese(46,2,30);
OLED_ShowCHinese(62,2,31);
OLED_ShowCHinese(78,2,32);
OLED_ShowCHinese(94,2,33);
}
}
图2 播放控制
实现图2所示控制功能的主程序为: void main(void)
{
USCI1_HandleInfoDef USCI1_HandleInfo;
SC_Init();
Sys_Init();
TouchKeyInit();
P4CON = 0xFF;
P4PH = 0x01;
GPIO_Init(GPIO4, GPIO_PIN_4|GPIO_PIN_5,GPIO_MODE_OUT_PP);
OLED_Init();
OLED_Clear();
OLED_ShowString(20,0,"MP3 Player",16);
setVolume(20);
USCI1_HandleInfo.TxState = USCI1_STATE_READY;
USCI1_UART_Transmit(&USCI1_HandleInfo, cmd6, 10, 0xFFFF);
while(1)
{
Sys_Scan();
}
}
演示视频: https://www.bilibili.com/video/BV1rM411C7oh/?vd_source=f302fc0cc3a0425328db53a3b92082ca
相关链接: 1. MDM_2802屏中文菜单的MP3播放器 https://bbs.21ic.com/icview-3266358-1-1.html 2. 触摸控制及数值显示 https://bbs.21ic.com/icview-3265578-1-1.html 3. 双色OLED屏显示驱动 https://bbs.21ic.com/icview-3263564-1-1.html
|