找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 2487|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

基于stm32單片機(jī)的智能垃圾桶程序與Proteus仿真圖

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "lcd.h"
  6. #include "usart.h"         
  7. #include "adc.h"
  8. #include "motor.h"



  9. int main(void)
  10. {        
  11. int key=0;         
  12.   u16 adcx=0;
  13.          int i;
  14.         int str=0;
  15.         //float temp;
  16.         delay_init();                     //延時(shí)函數(shù)初始化         
  17.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設(shè)置中斷優(yōu)先級(jí)分組為組2:2位搶占優(yōu)先級(jí),2位響應(yīng)優(yōu)先級(jí)
  18.         uart_init(115200);                 //串口初始化為115200
  19.          Adc_Init();                                  //ADC初始化
  20.   motor_init();
  21.         KEY_Init(); //IO初始化
  22.         while(1)
  23.         {
  24.                
  25.                
  26. //                key=Remote_Scan();        
  27. //         // printf("發(fā)送消息\n");
  28. //                //printf("%d\n",adcx);
  29. //                adcx=Get_Adc_Average(ADC_Channel_1,10);
  30. //                switch(key)
  31. //                        {
  32. //                                
  33. //                                case 104:str=1;break;                  
  34. //                                case 152:str=2;break;           
  35. //                                case 176:str=3;break;            
  36. //                                case 48:str=4;break;                    
  37. //                                case 24:str=5;break;                    
  38. //                                case 122:str=6;break;                  
  39. //                                case 16:str=7;break;                                                                  
  40. //                                case 56:str=8;break;         
  41. //                                case 90:str=9;break;
  42. //                                case 66:str=0;break;
  43. //                        }
  44. //                adcx=4096-adcx;
  45. //                printf("\n     %d/n",adcx);
  46. ////                i=adcx/1000;
  47.                 //if(PAin(3)==0)//黑色指示燈亮,代表0
  48.                         if(PAin(3)==0)

  49.                         {
  50.                                                 delay_ms(20);
  51.                                         if(PAin(3)==0)
  52.                                         {
  53.                                                 if(PAin(5)==0)
  54.                                                 {
  55.                                                                 printf("垃圾桶1打開  \r\n");
  56.                                                         motor_back1(3,4);
  57.                                                 
  58.                                                 
  59.                                                 
  60.                                                 }
  61.                                                 else
  62.                                                 {
  63.                                                                 printf("垃圾桶2打開 \r\n");
  64.                                                 motor_back2(3,4);
  65.                                                 }
  66.                                                         while(1)
  67.                                                         {
  68.                                                         if(PAin(3)==1)
  69.                                                         {     
  70.                                                                        delay_ms(20);
  71.                                                       if(PAin(3)==1)
  72.                                                                                                 {
  73.                                                                                                 break;
  74.                                                                                                 }
  75.                                                         
  76.                                                         }
  77.                                                 }
  78.                                                         if(PAin(5)==0)
  79.                                                         motor_front1(3,4);
  80.                                                 else
  81.                                                         motor_front2(3,4);
  82.                                                         
  83.                                         }
  84.                         }
  85.                         
  86.                         

  87.         }
  88. }
復(fù)制代碼
本人初學(xué),僅供參考,存在錯(cuò)誤和不足之處,請(qǐng)大家回帖多多指教,切勿照搬,文件下載:
Keil代碼與Proteus8.13仿真下載:
基于stm32智能垃圾桶.7z (284.31 KB, 下載次數(shù): 60)

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表