/************************************************************************************
** --------------------------- Revision History: --------------------------------
************************************************************************************/
/************************************************************************************
** Function: playNote()
** Routine Description: -
** 演奏乐曲,在PWM发声的同时点亮LED灯,反之熄灭
** Input parameters: -
** The Note Pointer.
** Output parameters: NONE
** Returned Value: NONE
** Remarks:
**
** Date created: 12:21:20,01/10/2012
** Author: tcpipstack
************************************************************************************/
void playNote(const tNote *pNote)
{
while (1)
{
if (pNote->mTime == 0)
{
break;
}
setPWMFreq(pNote->mName);
setPWMState(TRUE);
ledOn(TARGET_LED_EN);
SysCtlDelay(pNote->mTime * (SysCtlClockGet() / 2000));
setPWMState(FALSE);
ledOff(TARGET_LED_EN);
SysCtlDelay(10 * (SysCtlClockGet() / 2000));
pNote++;
}
SysCtlDelay(2000 * (SysCtlClockGet() / 2000));
}
/************************************************************************************
** Function: displayNoteName()
** Routine Description: -
** display the note name on the screen
** Input parameters: -
** NONE
** Output parameters: NONE
** Returned Value: NONE
** Remarks:
**
** Date created: 12:32:45,01/10/2012
** Author: tcpipstack
************************************************************************************/
void displayNoteName(const tMusic *pMusic)
{
RIT128x96x4StringDraw(pMusic->cName, 0, 10*2+6, 11);
}
最后我们在uC/OS-II里面作为一个music任务,这样播放过程中不会被其他任务所抢占而中断:
/************************************************************************************
** Function: taskMusic()
** Routine Description: -
** the Music Task
** Input parameters: -
** NONE
** Output parameters: NONE
** Returned Value: NONE
** Remarks:
**
** Date created: 11:58:59,01/10/2012
** Author: Long.Luo
************************************************************************************/
static void taskMusic(void *parg)
{
(void)parg;
while (1)
{
RIT128x96x4Clear();
RIT128x96x4StringDraw("Task Music", 30, 20, 15);
playNote(ButterflyLove);
OSTimeDly(2 * OS_TICKS_PER_SEC);
}
}
文章评论(0条评论)
登录后参与讨论