欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: 51單片機(jī)仿真寵物投食系統(tǒng)程序 Proteus工程 [打印本頁]

作者: Youth8023    時(shí)間: 2022-8-2 16:55
標(biāo)題: 51單片機(jī)仿真寵物投食系統(tǒng)程序 Proteus工程
包括C語言程序和proteus仿真
具有顯示時(shí)間 檢測溫度 重量檢測 聲光報(bào)警 以及電機(jī)控制等功能

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)



單片機(jī)源程序如下:
  1. #include "reg52.h"               
  2. #include "ds1302.h"       
  3. #include "lcd.h"
  4. #include "temp.h"
  5. #include "intrins.h"
  6. /*對數(shù)據(jù)類型進(jìn)行聲明定義*/
  7. typedef unsigned int u16;          
  8. typedef unsigned char u8;
  9. #define ulong unsigned long
  10. #define GPIO_MOTOR P1

  11. /****I/O口定義****/
  12. sbit KEY1 = P3^0;
  13. sbit KEY2 = P3^1;
  14. sbit KEY3 = P3^2;

  15. sbit BEEP = P2^7;
  16. sbit LED1  = P3^3;


  17. sbit DOUT=P3^4;        //定義2543數(shù)據(jù)讀取口
  18. sbit DIN =P3^5;        //定義2543數(shù)據(jù)寫入口
  19. sbit CS  =P3^6;        //定義2543片選信號(hào)口
  20. sbit CLK =P3^7;        //定義時(shí)鐘信號(hào)口

  21. /****變量定義****/
  22. bit adjust;//調(diào)節(jié)標(biāo)志位  0-1
  23. u8 num;//鬧鐘調(diào)節(jié)位
  24. u8 hour_shi, hour_ge, minute_shi, minute_ge;//鬧鐘調(diào)節(jié)
  25. ulong Volt;//測量的電壓值
  26. ulong AD_Volt;//測量的電壓值
  27. ulong quality;//檢測重量
  28. ulong quality_set=2000;//設(shè)置的重量閾值200克

  29. unsigned char code FFW_X[8]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09}; //X反轉(zhuǎn)順序

  30. unsigned char code FFZ_X[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1}; //X正轉(zhuǎn)順序

  31. unsigned char Direction,stop=0;

  32. void delay30ms(void)   //誤差 0us
  33. {
  34.     unsigned char a,b;
  35.     for(b=101;b>0;b--)
  36.         for(a=147;a>0;a--);
  37. }

  38. void Delay(unsigned int t)
  39. {
  40. unsigned int k;
  41. while(t--)
  42. {
  43. for(k=0; k<80; k++)
  44. { }
  45. }
  46. }



  47. void Motor()
  48. {
  49.         unsigned char a=30;
  50. unsigned char i;
  51. for(i=0;i<8;i++)
  52. {

  53.   if(Direction==1&&stop==0)                 //正轉(zhuǎn)電機(jī)&電機(jī)沒按下停止

  54. GPIO_MOTOR = FFW_X[i]&0x0F;//取數(shù)據(jù)

  55. if(Direction==2&&stop==0)                 //反轉(zhuǎn)&X電機(jī)&電機(jī)沒按下停止

  56. GPIO_MOTOR = FFZ_X[i]&0x0F;

  57.   Delay(a);
  58.   }
  59. }

  60. void Read2543(uchar addr)
  61. {
  62.         uint ad=0;
  63.         uchar i;
  64.         CLK=0;
  65.         CS=0;//片選段,啟動(dòng)2543
  66.         addr<<=4;//對地址位預(yù)處理
  67.         for(i=0;i<12;i++) //12個(gè)時(shí)鐘走完,完成一次讀取測量
  68.         {
  69.                 if(DOUT==1)
  70.                         ad=ad|0x01;//單片機(jī)讀取ad數(shù)據(jù)
  71.                 DIN=addr&0x80;//2543讀取測量地址位
  72.                 CLK=1;
  73.                 ;;;//很短的延時(shí)
  74.                 CLK=0;//產(chǎn)生下降沿,產(chǎn)生時(shí)鐘信號(hào)
  75.                 ;;;
  76.                 addr<<=1;
  77.                 ad<<=1;//將數(shù)據(jù)移位準(zhǔn)備下一位的讀寫
  78.         }
  79.         CS=1;//關(guān)2543
  80.         ad>>=1;
  81.         Volt=ad;//取走轉(zhuǎn)換結(jié)果
  82.         //Volt=Volt*1221;//例子的滿量程為5V,轉(zhuǎn)換分辯率為12位(2的12次方=4096) 。即最大值是255,5/4096=1221mV,即例子中的1V代表實(shí)際1221mV
  83.   
  84.         Volt=Volt*5000/4095;
  85.         quality=(Volt/5.12+40)*10/4;//計(jì)算壓力
  86.         //Pressure=(Volt/5.41+40)*10/4;
  87.                
  88. }



  89. void KEY_Control()//按鍵調(diào)節(jié)
  90. {
  91.         if(KEY1==0)
  92.         {
  93.                 delay30ms();
  94.                 if(KEY1==0)
  95.                 {
  96.                   stop=0;
  97.                          Direction=1;       
  98.                 }
  99.         }
  100.         if(KEY2==0)
  101.         {
  102.                 delay30ms();
  103.                 if(KEY2==0)
  104.                 {
  105.                 stop=0;
  106.                          Direction=2;       
  107.                 }
  108.         }
  109.         if(KEY3==0)
  110.         {
  111.                 delay30ms();
  112.                 if(KEY3==0)
  113.                 {
  114.                
  115.                  stop=1;       
  116.                 }
  117.         }
  118.        
  119. }

  120. void show_quality(void)//顯示重量
  121. {
  122.         quality=quality-30;
  123.                 DisplayOneChar(11,0,(char)(quality/1000+'0'));
  124.           DisplayOneChar(12,0,(char)(quality%1000/100+'0'));
  125.           DisplayOneChar(13,0,(char)((quality%100)/10+'0'));
  126.        
  127.         if( quality <= quality_set )
  128.         {
  129.                 stop=0;
  130.                 Direction=1;
  131.                 BEEP=0;
  132.                 LED1=0;
  133.                 Delay(200);
  134.                 BEEP=1;
  135.                 LED1=1;
  136.                 Delay(300);
  137.         }
  138.        
  139.         if( quality > quality_set )
  140.         {
  141.                 stop=1;
  142.                
  143.                 BEEP=1;
  144.                 LED1=1;
  145.                
  146.         }
  147. }



  148. void main()//主函數(shù)
  149. {       
  150.        
  151.         LcdInit();

  152.         DisplayOneChar(0,0,'2'); DisplayOneChar(1,0,'0'); DisplayOneChar(4,0,'-'); DisplayOneChar(7,0,'-');//2022-05-05  6
  153.         DisplayOneChar(2,1,':'); DisplayOneChar(5,1,':'); DisplayOneChar(2,1,':');//13:39:40       
  154.         DisplayListChar(9,1,"T:"); DisplayOneChar(13,1,'.'); DisplayOneChar(15,1,'C');//T:23.5C
  155.         DisplayOneChar(15,0,'g');
  156.         while(1)
  157.         {
  158.                
  159.                 KEY_Control();//按鍵控制
  160.                 Motor();//步進(jìn)電機(jī)控制
  161.                        
  162.                 Read2543(0);//檢測重量
  163.                 show_quality();//顯示重量
  164.                
  165.                
  166.                
  167.                 ReadTemperature();//讀取溫度       
  168.                 DisplayTemp();//顯示溫度
  169.                
  170.                        
  171.                 Ds1302ReadTime();//讀取時(shí)間
  172.                 DisplayTime();//顯示時(shí)間
  173.                        
  174.                
  175.         }
  176. }
復(fù)制代碼

Keil代碼與Proteus8.8仿真下載:
寵物投食系統(tǒng).zip (201 KB, 下載次數(shù): 88)




作者: mhwgo555    時(shí)間: 2022-12-13 23:38
附件里面沒有dsn文件嗎
作者: heicad    時(shí)間: 2022-12-13 23:42
mhwgo555 發(fā)表于 2022-12-13 23:38
附件里面沒有dsn文件嗎

作者說了是Proteus8.8的仿真,要安裝Proteus8.8才能打開.pdsprj工程的
dsn都是7.5很老的版本了,現(xiàn)在很少有人使用Proteus7.5了




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