標(biāo)題: 基于stm32單片機(jī)的智能垃圾桶程序與Proteus仿真圖 [打印本頁(yè)]

作者: taisenfag    時(shí)間: 2023-1-5 18:50
標(biāo)題: 基于stm32單片機(jī)的智能垃圾桶程序與Proteus仿真圖
仿真原理圖如下(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打開(kāi)  \r\n");
  56.                                                         motor_back1(3,4);
  57.                                                 
  58.                                                 
  59.                                                 
  60.                                                 }
  61.                                                 else
  62.                                                 {
  63.                                                                 printf("垃圾桶2打開(kāi) \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)





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1