|
有干、濕、有害、可回收四個分類
電路原理圖如下:
51hei.png (90.27 KB, 下載次數(shù): 63)
下載附件
2022-7-31 19:10 上傳
單片機(jī)源程序如下:
- #include "sys.h"
-
- u8 Target1=0;//舵機(jī)控制時間
- u8 Target2=0;
- u8 Target3=0;
- u8 Target4=0;
- u8 Open_Time=0;//開垃圾桶單位時間
- u8 WakeUp_Flag=0;//喚醒標(biāo)志位
- int main(void)
- {
- SystemInit(); //參數(shù)為向量表的偏移地址
- 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;//喚醒詞標(biāo)志位置位
- 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);//時間到關(guān)閉
- 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);//時間到關(guān)閉
- 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);//時間到關(guān)閉
- 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);//時間到關(guān)閉
- Target4 = 0;
- YHGUI_DispString(0,48,"可回收物 ",16,1);
- }
- }
- }
-
- }
- }
復(fù)制代碼
Keil代碼下載:
代碼.7z
(269.06 KB, 下載次數(shù): 55)
2022-7-31 19:12 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|