找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 6174|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

51單片機(jī) 語音芯片YF017 驅(qū)動(dòng)函數(shù)以及簡(jiǎn)單調(diào)用例程

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主








//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);
}

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏5 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:334749 發(fā)表于 2019-12-6 09:33 | 只看該作者
有辦法做到不阻塞嗎?
回復(fù)

使用道具 舉報(bào)

板凳
ID:425175 發(fā)表于 2019-12-6 14:08 | 只看該作者

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

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表