1 OLED显示器显示是哪一首歌曲序号
2 一共四首歌
3 OLED显示器显示出当前歌曲是打开状态还是关闭状态
4 8个独立按键
5 按键1234按下就是切换到对应曲目
按键5上一首
按键6下一首
按键7暂停播放
按键8开始播放
c/*
* OLED引脚分配 绿色板子
* DO(SCLK)------P4.3
* D1(DATA)------P4.0
* RES-----------P3.7
* DC------------P8.2
* CS------------P8.1
*/
/*
* 蜂鸣器OLED----MSP430
* VCC-----3.3V
* GND-----GND
* DAT------P2.4
*/
#define uchar unsigned char
#define uint unsigned int
/* 以下是C调低音的音频宏定义 */
#define L1 262 /* 将"L1"宏定义为低音"1"的频率262Hz 时间是1/262=3826/2 us 取半周期 */
#define L2 286 /* 将"L2"宏定义为低音"2"的频率286Hz */
#define L3 311 /* 将"L3"宏定义为低音"3"的频率311Hz */
#define L4 349 /* 将"L4"宏定义为低音"4"的频率349Hz */
#define L5 392 /* 将"L5"宏定义为低音"5"的频率392Hz */
#define L6 440 /* 将"l_a"宏定义为低音"6"的频率440Hz */
#define L7 494 /* 将"L7"宏定义为低音"7"的频率494Hz */
/* 以下是C调中音的音频宏定义 */
#define Z1 523 /* 将"Z1"宏定义为中音"1"的频率523Hz */
#define Z2 587 /* 将"Z2"宏定义为中音"2"的频率587Hz */
#define Z3 659 /* 将"Z3"宏定义为中音"3"的频率659Hz */
#define Z4 698 /* 将"Z4"宏定义为中音"4"的频率698Hz */
#define Z5 784 /* 将"Z5"宏定义为中音"5"的频率784Hz */
#define Z6 880 /* 将"Z6"宏定义为中音"6"的频率880Hz */
#define Z7 987 /* 将"Z7"宏定义为中音"7"的频率523H */
/* 以下是C调高音的音频宏定义 */
#define H1 1046 /* 将"H1"宏定义为高音"1"的频率1046Hz */
#define H2 1174 /* 将"H2"宏定义为高音"2"的频率1174Hz */
#define H3 1318 /* 将"H3"宏定义为高音"3"的频率1318Hz */
#define H4 1396 /* 将"H4"宏定义为高音"4"的频率1396Hz */
#define H5 1567 /* 将"H5"宏定义为高音"5"的频率1567Hz */
#define H6 1760 /* 将"H6"宏定义为高音"6"的频率1760Hz */
#define H7 1975 /* 将"H7"宏定义为高音"7"的频率1975Hz */
int keyTemp;
unsigned char u, t; /* 音乐所用的变量 */
unsigned char open_flag = 1; /* 暂停时为0 播放时为1 */
unsigned char music_crr = 0; /* 当前是播放哪一首音乐 可以为0 1 2 分别是是三首歌 */
/* ****************************************** */
/* ******** 音乐1 天空之城 */
/* ****************************************** */
static unsigned int music0[] = { Z6, Z7, /**/H1, Z7, H1, H3, /**/Z7, Z3, Z3, /**/
Z6, Z5, Z6, H1, /**/Z5, Z3, Z3, /**/Z4, Z3, Z4,
H1,
Z3, H1, H1, H1, /**/Z7, Z4, Z4, Z7,/**/Z7,
Z6,
Z7, /**/H1, Z7, H1, H3, /**/Z7, Z3, Z3, /**/
Z6, Z5, Z6, H1, Z5, Z3, /**/Z4, H1, Z7, H1, /**/
H2, H2, H2, H1, /**/H1, Z6, Z7, Z5,/**/Z6, H1,
H2, /**/
H3, H2, H3, H5, H2, Z5, Z5, /**/H1, Z7,
H1,
H3, /**/H3, /**/Z6, H1, Z7, H2, /**/H1, Z5,
Z5, /**/
H4, H3, H2, H1, H3, /**/Z3, H3, /**/H6,
H5,
H5, /**/H3, H2, H1, H1, /**/H2, H1, H2, H5, /**/
H3, H3, H6, H5, /**/H3, H2, H1, H1,/**/H2, H1,
H2,
Z7, /**/Z6, Z6, Z7, /**/Z6, 0xff }; /* 以0xff作为音符的结束标志 */
/*
* 以下是简谱中每个音符的节拍
* "4"对应4个延时单位,"2"对应2个延时单位,"1"对应1个延时单位
*/
static unsigned char music0_JP[] = { 4, 4, /**/12, 4, 8, 8, /**/20, 4, 4, /**/
12, 4, 8, 8, /**/20, 4, 4, /**/12, 4, 4,
12, 20, 4, 4, 4, /**/12, 4, 8, 8, /**/20,
4, 4, /**/12, 4, 8, 8, /**/20, 4, 4, /**/
12, 4, 8, 8, 32, 4, /**/8, 4, 6, 8, /**/4,
4, 4, 16, /**/8, 4, 6, 8, /**/24, 4, 4, /**/
12, 4, 8, 8, 24, 4, 4, /**/4, 4, 8, 8, /**/
32, /**/4, 8, 8, 6, /**/12, 4, 16, /**/8,
8, 8, 8, 30, /**/20, 8, /**/16, 8, 8, /**/
4, 4, 16, 8, /**/8, 4, 4, 8, /**/20, 8, 16,
16, /**/4, 20, 8, /**/8, 4, 4, 8, /**/20,
4, 4, 8, 8, /**/8 };
/* ****************************************** */
/* ******** 音乐2 */
/* ****************************************** */
static unsigned int music1[] = { Z3, Z3, Z5, Z6, H1, H1, Z6, Z5, Z5, Z6, Z5, Z3,
Z3,
Z5, Z6, H1, H1, Z6, Z5, Z5, Z6, Z5, Z5, Z5,
Z5,
Z3, Z5, Z6, Z6, Z5, Z3, Z2, Z3, Z5, Z3, Z2,
Z1,
Z1, Z2, Z1, 0xff }; /* 以0xff作为音符的结束标志 */
/*
* 以下是简谱中每个音符的节拍
* "4"对应4个延时单位,"2"对应2个延时单位,"1"对应1个延时单位
*/
static unsigned char music1_JP[] = { 16, 8, 8, 8, 8, 8, 8, 16, 8, 8, 32, 16, 8,
8, 8, 8, 8, 8, 16, 8, 8, 32, 16, 16, 16, 8,
8, 16, 16, 32, 16, 8, 8, 16, 8, 8, 16, 8,
8, 32, 1, 8, 8 };
/* ****************************************** */
/* ******** 音乐3 小星星 */
/* ****************************************** */
static unsigned int music2[] = { H3, H3, H3, H2, H1, H2, H5, H5, H1, H1, H1, H1,
Z6,
Z7, H3, H3, Z5, Z6, H6, H5, H4, H3, H2, H1,
H1,
Z6, H1, H2, H5, H5, H2, H1, H2, H2, Z1, H3,
H3,
H3, H2, H1, H2, H5, H5, H1, H1, H1, H1, Z6,
Z7,
H3, H3, Z5, Z6, H6, H5, H4, H3, H2, H1, H1,
Z6,
H1, H2, H5, H5, Z5, H2, H1,
0xff }; /* 以0xff作为音符的结束标志 */
/*
* 以下是简谱中每个音符的节拍
* "4"对应4个延时单位,"2"对应2个延时单位,"1"对应1个延时单位
*/
static unsigned char music2_JP[] = { 8, 2, 2, 2, 2, 4, 4, 8, 8, 2, 2, 2, 2, 4,
4, 4, 4, 8, 4, 2, 2, 4, 2, 2, 8, 2, 2, 2,
2, 2, 2, 2, 2, 8, 8, 8, 2, 2, 2, 2, 4, 4,
8, 8, 2, 2, 2, 2, 4, 4, 4, 4, 8, 4, 2, 2,
8, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 12, 8, 8 };
/* ****************************************** */
/* ******** 音乐4 */
/* ****************************************** */
static unsigned int music3[] = { Z1, Z2, Z3, Z1, Z1, Z2, Z3, Z1, Z3, Z4, Z5, Z3,
Z4,
Z5, Z5, Z6, Z5, Z4, Z3, Z1, Z5, Z6, Z5, Z4,
Z3,
Z1, Z2, L5, Z1, Z2, L5, Z1, 0xff }; /* 以0xff作为音符的结束标志 */
/*
* 以下是简谱中每个音符的节拍
* "4"对应4个延时单位,"2"对应2个延时单位,"1"对应1个延时单位
*/
static unsigned char music3_JP[] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
4, 4, 4, 4, 8, 8, 4, 4, 4, 4, 8, 8, 8, 8,
16, 8, 8, 8, 1 };
void initClock(void)
{
UCSCTL3 = SELREF_2; /* Set DCO FLL reference = REFO */
UCSCTL4 |= SELA_2; /* Set ACLK = REFO */
UCSCTL0 = 0x0000; /* Set lowest possible DCOx, MODx */
/* Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize */
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
/* Clear XT2,XT1,DCO fault flags */
SFRIFG1 &= ~OFIFG; /* Clear fault flags */
}
while (SFRIFG1 & OFIFG); /* Test oscillator fault flag */
__bis_SR_register( SCG0); /* Disable the FLL control loop */
UCSCTL1 = DCORSEL_5; /* Select DCO range 16MHz operation */
UCSCTL2 |= 249; /*
* Set DCO Multiplier for 8MHz
* (N + 1) * FLLRef = Fdco
* (249 + 1) * 32768 = 8MHz
*/
__bic_SR_register( SCG0); /* Enable the FLL control loop */
/*
* Worst-case settling time for the DCO when the DCO range bits have been
* changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
* UG for optimization.
* 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle
*/
__delay_cycles(250000);
}
int getKeyBoardValue(void)
{
if ((P6IN & BIT0) == 0)
{
if ((P6IN & BIT0) == 0)
{
return (4);
}
}
else if ((P6IN & BIT1) == 0)
{
if ((P6IN & BIT1) == 0)
{
return (3);
}
}
else if ((P6IN & BIT2) == 0)
{
if ((P6IN & BIT2) == 0)
{
return (2);
}
}
else if ((P6IN & BIT6) == 0)
{
if ((P6IN & BIT6) == 0)
{
return (1);
}
}
else if ((P6IN & BIT4) == 0)
{
if ((P6IN & BIT4) == 0)
{
return (8);
}
}
else if ((P7IN & BIT0) == 0)
{
if ((P7IN & BIT0) == 0)
{
return (7);
}
}
else if ((P3IN & BIT6) == 0)
{
if ((P3IN & BIT6) == 0)
{
return (6);
}
}
else if ((P3IN & BIT5) == 0)
{
if ((P3IN & BIT5) == 0)
{
return (5);
}
}
return (0);
}
#define BEEPCLOSE TA2CCR0=0,TA2CCR1=0
#define LED_OPEN P1OUT |= 0X01
#define LED_CLOSE P1OUT &= ~0X01
void set_fre(unsigned int fre)
{
TA2CCR0 = 1000000 / fre; /*选一个频率 */
TA2CCR1 = 500000 / fre;
}
void delay_key(void)
{
if (keyTemp == 1)
{
music_crr = 0;
open_flag = 1;
}
else if (keyTemp == 2)
{
music_crr = 1;
open_flag = 1;
}
else if (keyTemp == 3)
{
music_crr = 2;
open_flag = 1;
}
else if (keyTemp == 4)
{
music_crr = 3;
open_flag = 1;
}
else if (keyTemp == 5) /*下一首 */
{
music_crr = (music_crr + 1) % 4; /* 0 1 2 3 */
open_flag = 1;
}
else if (keyTemp == 6) /*下一首 */
{
if (music_crr > 0)
{
music_crr--;
}
else
{
music_crr = 3;
}
open_flag = 1;
}
else if (keyTemp == 7)
{
open_flag = 0;
}
else if (keyTemp == 8)
{
open_flag = 1;
}
}
完整代码:
https://github.com/xddun/blog_code_search
csharphttps://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2
本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!