找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5212|回复: 2
收起左侧

51单片机 语音芯片YF017 驱动函数以及简单调用例程

[复制链接]
ID:425175 发表于 2019-12-1 11:33 | 显示全部楼层 |阅读模式

YF017--数据手册-剪影

YF017--数据手册-剪影
YF017-语音片段.jpg



YF017-run.png



//YF017---语音播报程序
#include <reg52.h>
#include <intrins.h>
sbit MUSIC_REST =P2^0;//语音芯片复位脚                                       
sbit MUSIC_DATA =P2^1;//语音芯片脉冲识别
sbit bus =P2^2;//语音芯片工作状态识别信号  

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[]) //距离播报
{
    if((dis[0]+dis[1]+dis[2])!=0)                   //当超出测量范围时不进行播报
        {
                Music(17);                                        //播报:“距离”
                while(!bus);
                if(dis[0]==0){
                              Music(2);                         //播报:“十位数具体值”          0
                        while(!bus);       
                }                   
                   else {
                        Music(dis[0]+2);                         //播报:“十位数具体值”
                        while(!bus);
                }
                if((dis[1]+dis[2])!=0){          
                        Music(14);                                        //播报:“点”
                        while(!bus);
                        Music(dis[1]+2);                                //播报:“十分位的具体值”
                        while(!bus);                               
                        Music(dis[2]+2);                                //播报:“百分位的具体值”
                        while(!bus);                   
                       
                }
                Music(26);                                //播报:“米”
                while(!bus);       
        }          
}


void Msc_temp(uint temp)//温度播报
{
        temp0=temp/100;
        temp1=temp%10/10;
        temp2=temp%10; //小数
        Music(21);                                        //播报:“温度”
        while(!bus);
        if((temp[0]+temp[1])!=0)
        {
                if(temp[0]==0){
                        Music(temp[1]+2);                                //播报:“个位的具体值”(不播报十位数了)
                        while(!bus);
                }
                Music(temp[0]+2);                                //播报:“十位的具体值”
                while(!bus);                               
                Music(temp[1]+2);                                //播报:“个位的具体值”
                while(!bus);
        }                   
        else{
                Music(temp[1]+2);                         //播报:“0”
                while(!bus);
        }
        if(temp2!=0){          
                Music(14);                                        //播报:“点”
                while(!bus);
                Music(temp[2]+2);                                //播报:“小数位”
                while(!bus);
                Music(29);                                //播报:“度”
            while(!bus);       
        }
        Music(29);                                //播报:“度”
        while(!bus);       
}

void MscAlarm()
{
        Music(23);                                        //播报:“危险”
        while(!bus);
}

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:334749 发表于 2019-12-6 09:33 | 显示全部楼层
有办法做到不阻塞吗?
回复

使用道具 举报

ID:425175 发表于 2019-12-6 14:08 | 显示全部楼层
老农要进城 发表于 2019-12-6 09:33
有办法做到不阻塞吗?

我顶多算个新手,关于阻塞问题,不太懂
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表