51-MP3-语音识别分类垃圾桶
立即下载
资源介绍:
51-MP3——语音识别分类垃圾桶
#include
#include "delay.h"
#include "servo.h"
#include "uart.h"
#include "timer.h"
#include "voice.h"
/*主函数入口*/
void main(void)
{
//angle与对应角度关系
//4 5 6 ...... 19 20
//0 11 22 ...... 166 177
uart_Init();
timer0_Init();
while(1)
{
switch(comFlag)
{
case 0:
TIM0_OFF;
voiceAck();//语音播报:我在
delay600ms();
comFlag = 10;
MP30 = 1;
break;
//干垃圾
case 1:
openTrash(); //开垃圾桶
voiceOpenGan();//语音播报:这个是干垃圾
delay2s(); //延时2s
voiceCloseGan();
closeTrash(); //关垃圾桶
break;
//湿垃圾
case 2:
openTrash(); //开垃圾桶
voiceOpenShi();//语音播报:这个是干垃圾
delay2s(); //延时2s
voiceCloseShi();
closeTrash(); //关垃圾桶
break;
//有害垃圾
case 3:
openTrash(); //开垃圾桶
voiceOpenYou();//语音播报:这个是有害垃圾
delay2s(); //延时2s
voiceCloseYou();
closeTrash(); //关垃圾桶
break;
//可回收垃圾
case 4:
openTrash(); //开垃圾桶
voiceOpenKe(); //语音播报:这个是可回收垃圾
delay2s(); //延时2s
voiceCloseKe();
closeTrash(); //关垃圾桶
break;
default:
TIM0_OFF;
break;
}
}
}
/*串口通信中断处理函数*/
void uartDispose() interrupt 4
{
unsigned char command; //存放命令
command = SBUF;
switch(command)
{
case 'e': comFlag = 0; break;
case 'g': comFlag = 1; break;
case 'G': comFlag = 1; break;
case 's': comFlag = 2; break;
case 'S': comFlag = 2; break;
case 'y': comFlag = 3; break;
case 'Y': comFlag = 3; break;
case 'k': comFlag = 4; break;
case 'K': comFlag = 4; break;
default : comFlag = 10; break;
}
while(!RI);
RI = 0;
}
/*定时器0中断处理函数*/
void Timer0Dispose() interrupt 1
{
TL0 = 0xA4; //设置定时初值
TH0 = 0xFF; //设置定时初值
switch(comFlag)
{
case 1:
{
if(count < angle) //判断次数是否小于角度标识
pwmg=1; //确实小于,PWM输出高电平
else
pwmg=0;
break;
}
case 2:
{
if(count < angle) //判断次数是否小于角度标识
pwms=1; //确实小于,PWM输出高电平
else
pwms=0;
break;
}
case 3:
{
if(count < angle) //判断次数是否小于角度标识
pwmy=1; //确实小于,PWM输出高电平
else
pwmy=0;
break;
}
case 4:
{
if(count < angle) //判断次数是否小于角度标识
pwmk=1; //确实小于,PWM输出高电平
else
pwmk=0;
break;
}
default: break;
} //大于则输出低电平
count=(count+1); //0.1ms次数加1
count=count%160; //保持周期为20ms,普通51单片机定时100us有误差,经示波器测量约为50Hz
}