国产免费AV|泡泡玛特欧洲总部将设在伦敦|中文天堂网www新版资源在线|一本久道综合在线中文|国精产品一二三产区的使用方法|香蕉鱼在线观看|www.27eee

 找回密碼
 注冊
搜索

51單片機光強檢測源碼程序與Proteus仿真 可設置超上限報警

[復制鏈接]
樓主
eng 發表于 2021-7-6 15:54:55 | 只看該作者 |只看大圖 |倒序瀏覽 |閱讀模式
光強檢測仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51單片機光強檢測源碼程序與Proteus仿真 可設置超上限報警 160744xevcbc20zncz2aa1.png
51單片機光強檢測源碼程序與Proteus仿真 可設置超上限報警 155038jhkkdcu6u4ych0od.gif

單片機光強檢測源程序如下:完整程序見附件
  1. #include <reg52.h>
  2. #include <display.h>

  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. #define Data_ADC0809 P1

  6. sbit LED_light= P2^1;
  7. sbit baojing= P2^5;
  8. sbit DQ = P2^0;
  9. sbit fs=P3^4;
  10. sbit ST=P3^3;
  11. sbit EOC=P3^6;
  12. sbit OE=P3^2;
  13. sbit Key1=P2^6;
  14. sbit Key2=P2^7;
  15. sbit Key3=P3^7;

  16. signed char w;                                    
  17. uint c;                                       
  18. bit bdata flag=0;
  19. uchar temp;
  20. uchar yushe_wendu=50;
  21. uchar yushe_light=100;
  22. uchar Mode=0;

  23. extern uchar ADC0809();
  24. extern void Key();

  25. void delay(uint z)
  26. {
  27.         uint i,j;
  28.         for(i=0;i<z;i++)
  29.         for(j=0;j<121;j++);
  30. }



  31. uchar ADC0809()
  32. {
  33.         uchar temp_=0x00;
  34.       

  35.         OE=0;
  36.       
  37.         ST=0;
  38.       
  39.         ST=1;
  40.         ST=0;
  41.       
  42.         while(EOC==0)
  43.    
  44.         OE=1;
  45.         temp_=Data_ADC0809;
  46.         OE=0;
  47.         return temp_;
  48. }

  49. void Key()
  50. {

  51.         if(Key1==0)
  52.         {
  53.                 while(Key1==0);
  54.                 if(Mode>=2) Mode=0;
  55.                 else
  56.                 {
  57.                            write_com(0x38);
  58.                            write_com(0x0d);
  59.                            write_com(0x06)
  60.                         Mode++;
  61.                         switch(Mode)
  62.                         {
  63.                                 case 1:
  64.                                 {
  65.                                         write_com(0x80+12)
  66.                                         break;
  67.                                 }
  68.                                 case 2:
  69.                                 {
  70.                                         write_com(0x38);
  71.                                         write_com(0x0c);
  72.                                         Mode=0;
  73.                                         break;
  74.                                 }

  75.                         }
  76.                 }
  77.         }
  78.         if(Key2==0&&Mode!=0)
  79.         {
  80.                 while(Key2==0);
  81.                 switch(Mode)
  82.                 {

  83.                         case 1:
  84.                         {
  85.                                 yushe_light++;
  86.                                 if(yushe_light>=255)
  87.                                 yushe_light=255;
  88.                                 write_com(0x80+13);
  89.                                 write_data(0x30+yushe_light/100);
  90.                                 write_data(0x30+yushe_light%100/10);
  91.                                 write_data(0x30+yushe_light%10);
  92.                                 break;                                
  93.                         }
  94.                 }
  95.         }
  96.         if(Key3==0&&Mode!=0)
  97.         {
  98.                 while(Key3==0);
  99.                 switch(Mode)
  100.                 {
  101.                         case 1:
  102.                         {
  103.                                 yushe_light--;
  104.                                 if(yushe_light<=0)
  105.                                 yushe_light=0;
  106.                                 write_com(0x80+13);
  107.                                 write_data(0x30+yushe_light/100);
  108.                                 write_data(0x30+yushe_light%100/10);
  109.                                 write_data(0x30+yushe_light%10);
  110.                                 break;                                
  111.                         }
  112.                 }
  113.         }
  114.         delay(200);
  115.         write_com(0x38);
  116.         write_com(0x0c);
  117. }

  118. void main()
  119. {
  120.         Init1602();         
  121.         fs=0;
  122.         while(1)
  123.         {
  124.                 temp=ADC0809();
  125.                 Key();

  126.                 if(Mode==0)
  127.                 {
  128.                         Display_1602(yushe_wendu,yushe_light,c,temp);
  129.                         if(temp>=yushe_light)
  130.                         {
  131.                                 LED_light=0;
  132.                                 baojing=0;
  133.                                 fs=1;
  134.                         }
  135.                         else
  136.                         {
  137.                                 LED_light=1;
  138.                         }

  139.                         if(temp<yushe_light)
  140.                         {
  141.                                 baojing=1;
  142.                                 fs=0;
  143.                         }
  144.                 }
  145.         }
  146. }        
復制代碼
光照強度檢測程序5.20.2.rar (27.87 KB, 售價: 1 E幣) 光照強度檢測proteus仿真.rar (98.23 KB, 售價: 1 E幣)


您需要登錄后才可以回帖 登錄 | 注冊

本版積分規則

手機版|小黑屋|ELEOK |網站地圖

GMT+8, 2026-5-26 06:06

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回復 返回頂部 返回列表