找回密码
 注册

QQ登录

只需一步,快速开始

搜索

51单片机光强检测源码程序与Proteus仿真 可设置超上限报警

[复制链接]
eng 发表于 2021-7-6 15:54:55 | 显示全部楼层 |阅读模式
光强检测仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
160744xevcbc20zncz2aa1.png
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币)


您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-4-20 20:51

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表