51單片機,智能垃圾桶,超聲破測距,語音提示
Altium Designer畫的原理圖和PCB圖如下:(51hei附件中可下載工程文件)
0.png (48.98 KB, 下載次數: 113)
下載附件
2019-7-14 00:58 上傳
0.png (40.62 KB, 下載次數: 115)
下載附件
2019-7-14 00:58 上傳
0.png (9 KB, 下載次數: 103)
下載附件
2019-7-14 00:59 上傳
單片機源程序如下:
- #include <STC89C5xRC.H>
- #include <intrins.h>
- #include <stdio.h>
- #include "HC_SR04.h"
- #include "usart1.h"
- #include "WT588D.h"
- #include "StepMotor.h"
- void Delay50ms() //@11.0592MHz
- {
- unsigned char i, j;
- i = 90;
- j = 163;
- do
- {
- while (--j);
- } while (--i);
- }
- char xdata buff[128];
- unsigned int dis=420;
- char flg=0,flg2=0,flg3=0;
- unsigned int cnt=0;
- // may everything go well for you who will graduate in front of the screen.
- // but how about learning more in the future, tough girl?
- //Have bought a ticket to xiangtan, you look at it, I changed the code in the train station。
- void main()
- {
- HC_SR04_Init();//超聲波初始化
- GoBackSM();//步進電機初始化,尋找垃圾箱蓋子關閉的地方
- while(1)
- {
-
- dis=getdis();//超聲波測距把距離賦給dis
- if(dis<20)//設置垃圾箱蓋子打開時的距離
- {
- if(flg==1)//判斷標志位
- {
- cnt=0;
- P25=1;//關消毒燈
- flg=0;
- flg2=0;
- if(P20==1)Send_threelines(0);//播放垃圾放置請分類
- Go90A();//轉90°
- while(getdis()<30)//如果上面的距離改了,這里也要改
- {
- Delay50ms();//丟垃圾啊丟垃圾,屏幕前的你在丟垃圾
- }
- }
- }
- else//垃圾丟完,人走了
- {
- GoBackSM();//垃圾丟完了,垃圾蓋歸位
- if(P20==0)//檢測垃圾桶滿了沒,滿了進入if內執行任務
- {
- if(flg3==0)
- {
- flg3=1;
- Send_threelines(1);//播報垃圾已滿,鏟屎的,該倒垃圾了
- }
- }
- else//垃圾箱沒滿
- flg3=0;//復位標志位
-
- if(flg2==0)//判斷第二個標志位是否為0
- {
- cnt++;//開始計算消毒時間
- P25=0;//消毒開始,只有在垃圾箱盒子合上才會動作
- }
- if(cnt>=1200)//消毒時間到
- {
- flg2=1;//置為第二個標志位
- P25=1;//關閉消毒指示
- }
-
- flg=1;//置為第一個標志位
- }
-
- Delay50ms();//單次循環50ms
- }
- }
復制代碼
所有資料51hei提供下載:
資料合集垃圾箱.zip
(1.85 MB, 下載次數: 370)
2019-7-13 22:29 上傳
點擊文件名下載附件
程序及pcb 下載積分: 黑幣 -5
|