標(biāo)題: 51單片機(jī) 語音芯片YF017 驅(qū)動(dòng)函數(shù)以及簡(jiǎn)單調(diào)用例程 [打印本頁(yè)]

作者: 威龍1410    時(shí)間: 2019-12-1 11:33
標(biāo)題: 51單片機(jī) 語音芯片YF017 驅(qū)動(dòng)函數(shù)以及簡(jiǎn)單調(diào)用例程








//YF017---語音播報(bào)程序
#include <reg52.h>
#include <intrins.h>
sbit MUSIC_REST =P2^0;//語音芯片復(fù)位腳                                       
sbit MUSIC_DATA =P2^1;//語音芯片脈沖識(shí)別
sbit bus =P2^2;//語音芯片工作狀態(tài)識(shí)別信號(hào)  

void delay_us(unsigned int us)
{
    while(us--)
    {
            _nop_();
            _nop_();
            _nop_();
            _nop_();
    }
}

void Music(unsigned char music_count)
{
    MUSIC_REST=1;
    delay_us(200);
    MUSIC_REST=0;
    delay_us(200);

    while(music_count>0)
    {
        MUSIC_DATA=1;
        delay_us(100);
        MUSIC_DATA=0;
        delay_us(100);
                music_count--;
    }
}

void Msc_Alarm(uchar dis[]) //距離播報(bào)
{
    if((dis[0]+dis[1]+dis[2])!=0)                   //當(dāng)超出測(cè)量范圍時(shí)不進(jìn)行播報(bào)
        {
                Music(17);                                        //播報(bào):“距離”
                while(!bus);
                if(dis[0]==0){
                              Music(2);                         //播報(bào):“十位數(shù)具體值”          0
                        while(!bus);       
                }                   
                   else {
                        Music(dis[0]+2);                         //播報(bào):“十位數(shù)具體值”
                        while(!bus);
                }
                if((dis[1]+dis[2])!=0){          
                        Music(14);                                        //播報(bào):“點(diǎn)”
                        while(!bus);
                        Music(dis[1]+2);                                //播報(bào):“十分位的具體值”
                        while(!bus);                               
                        Music(dis[2]+2);                                //播報(bào):“百分位的具體值”
                        while(!bus);                   
                       
                }
                Music(26);                                //播報(bào):“米”
                while(!bus);       
        }          
}


void Msc_temp(uint temp)//溫度播報(bào)
{
        temp0=temp/100;
        temp1=temp%10/10;
        temp2=temp%10; //小數(shù)
        Music(21);                                        //播報(bào):“溫度”
        while(!bus);
        if((temp[0]+temp[1])!=0)
        {
                if(temp[0]==0){
                        Music(temp[1]+2);                                //播報(bào):“個(gè)位的具體值”(不播報(bào)十位數(shù)了)
                        while(!bus);
                }
                Music(temp[0]+2);                                //播報(bào):“十位的具體值”
                while(!bus);                               
                Music(temp[1]+2);                                //播報(bào):“個(gè)位的具體值”
                while(!bus);
        }                   
        else{
                Music(temp[1]+2);                         //播報(bào):“0”
                while(!bus);
        }
        if(temp2!=0){          
                Music(14);                                        //播報(bào):“點(diǎn)”
                while(!bus);
                Music(temp[2]+2);                                //播報(bào):“小數(shù)位”
                while(!bus);
                Music(29);                                //播報(bào):“度”
            while(!bus);       
        }
        Music(29);                                //播報(bào):“度”
        while(!bus);       
}

void MscAlarm()
{
        Music(23);                                        //播報(bào):“危險(xiǎn)”
        while(!bus);
}

作者: 老農(nóng)要進(jìn)城    時(shí)間: 2019-12-6 09:33
有辦法做到不阻塞嗎?
作者: 威龍1410    時(shí)間: 2019-12-6 14:08
老農(nóng)要進(jìn)城 發(fā)表于 2019-12-6 09:33
有辦法做到不阻塞嗎?

我頂多算個(gè)新手,關(guān)于阻塞問題,不太懂




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1