有干、湿、有害、可回收四个分类
电路原理图如下:
单片机源程序如下:
- #include "sys.h"
-
- u8 Target1=0;//舵机控制时间
- u8 Target2=0;
- u8 Target3=0;
- u8 Target4=0;
- u8 Open_Time=0;//开垃圾桶单位时间
- u8 WakeUp_Flag=0;//唤醒标志位
- int main(void)
- {
- SystemInit(); //参数为向量表的偏移地址
- delay_init();
- gpio_Init();
- MP3_Init();//初始化MP3语音播报模块
- Voice_Init(); //初始化语音识别模块
- SysTick_Init();//初始化多功能定时器
- PWM_Init();//初始化PWM
- YHGUI_Config();
- YHGUI_DispString(0,0,"厨余垃圾",16,1);
- YHGUI_DispString(0,16,"其它垃圾",16,1);
- YHGUI_DispString(0,32,"有害垃圾",16,1);
- YHGUI_DispString(0,48,"可回收物",16,1);
-
- while(1)
- {
- if((Infrared1 == 0)||(Infrared2 == 0)||(Infrared3 == 0)||(Infrared4 == 0))
- {
- delay_ms(1);
- if((Infrared1 == 0)||(Infrared2 == 0)||(Infrared3 == 0)||(Infrared4 == 0))
- {
- if(Infrared1 == 0)
- {
- BEEP = 1;
- YHGUI_DispString(106,0,"满",16,1);
- }
- else
- {
- YHGUI_DispString(106,0," ",16,1);
- }
-
- if(Infrared2 == 0)
- {
- BEEP = 1;
- YHGUI_DispString(106,16,"满",16,1);
- }
- else
- {
- YHGUI_DispString(106,16," ",16,1);
- }
-
- if(Infrared3 == 0)
- {
- BEEP = 1;
- YHGUI_DispString(106,32,"满",16,1);
- }
- else
- {
- YHGUI_DispString(106,32," ",16,1);
- }
-
- if(Infrared4 == 0)
- {
- BEEP = 1;
- YHGUI_DispString(106,48,"满",16,1);
- }
- else
- {
- YHGUI_DispString(106,48," ",16,1);
- }
- }
- }
- else
- {
- BEEP = 0;
-
- }
- if(Voice_RX_STA == 1)//收到语音指令
- {
- if(MP3_State() == 0)
- {
- if(Voice_RX_CMD==49 || Voice_RX_CMD==50)//唤醒
- {
- WakeUp_Flag = 1;//唤醒词标志位置位
- MP3_Star(5);
- }
- else if(WakeUp_Flag == 1)
- {
-
- if(Voice_RX_CMD%4 == 1)//厨余垃圾
- {
- MP3_Star(1);
- Target1 = 1;
- }
- else if(Voice_RX_CMD%4 == 2)//其他垃圾
- {
- MP3_Star(2);
- Target2 = 1;
- }
- else if(Voice_RX_CMD%4 == 3)//有害垃圾
- {
- MP3_Star(3);
- Target3 = 1;
- }
- else//可回收物
- {
- MP3_Star(4);
- Target4 = 1;
- }
- }
- }
- Voice_RX_STA = 0;
- }
-
- if(SysTick_JumpEdge(&Open_Time, &SysTickBit.Time1s)==1)//开垃圾桶单位时间到
- {
- if(Target1 != 0)//厨余垃圾桶打开
- {
- YHGUI_DispString(0,0,"厨余垃圾 开启",16,1);
-
- Target1++;
- TIM_SetCompare1(TIM4,1000);//打开
- if(Target1>6)
- {
- TIM_SetCompare1(TIM4,400);//时间到关闭
- Target1 = 0;
- YHGUI_DispString(0,0,"厨余垃圾 ",16,1);
- }
- }
- if(Target2 != 0)//其他垃圾桶打开
- {
- YHGUI_DispString(0,16,"其它垃圾 开启",16,1);
-
- Target2++;
- TIM_SetCompare2(TIM4,1000);//打开
- if(Target2>6)
- {
- TIM_SetCompare2(TIM4,400);//时间到关闭
- Target2 = 0;
- YHGUI_DispString(0,16,"其它垃圾 ",16,1);
- }
- }
- if(Target3 != 0)//有害垃圾桶打开
- {
- YHGUI_DispString(0,32,"有害垃圾 开启",16,1);
-
- Target3++;
- TIM_SetCompare3(TIM4,1000);//打开
- if(Target3>6)
- {
- TIM_SetCompare3(TIM4,400);//时间到关闭
- Target3 = 0;
- YHGUI_DispString(0,32,"有害垃圾 ",16,1);
- }
- }
- if(Target4 != 0)//可回收物桶打开
- {
- YHGUI_DispString(0,48,"可回收物 开启",16,1);
-
- Target4++;
- TIM_SetCompare4(TIM4,1000);//打开
- if(Target4>6)
- {
- TIM_SetCompare4(TIM4,400);//时间到关闭
- Target4 = 0;
- YHGUI_DispString(0,48,"可回收物 ",16,1);
- }
- }
- }
-
- }
- }
复制代码
Keil代码下载:
代码.7z
(269.06 KB, 下载次数: 55)
|