标题: 单片机光强检测程序与Proteus仿真 可设置超上限报警 [打印本页]

作者: zcandnn    时间: 2021-6-29 16:09
标题: 单片机光强检测程序与Proteus仿真 可设置超上限报警
光强检测仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)



单片机光强检测源程序如下:
#include <reg52.h>
#include <display.h>

#define uint unsigned int
#define uchar unsigned char
#define Data_ADC0809 P1

sbit LED_light= P2^1;
sbit baojing= P2^5;
sbit DQ = P2^0;
sbit fs=P3^4;
sbit ST=P3^3;
sbit EOC=P3^6;
sbit OE=P3^2;
sbit Key1=P2^6;
sbit Key2=P2^7;
sbit Key3=P3^7;

signed char w;                                    
uint c;                                       
bit bdata flag=0;
uchar temp;
uchar yushe_wendu=50;
uchar yushe_light=100;
uchar Mode=0;

extern uchar ADC0809();
extern void Key();

void delay(uint z)
{
        uint i,j;
        for(i=0;i<z;i++)
        for(j=0;j<121;j++);
}



uchar ADC0809()
{
        uchar temp_=0x00;
      

        OE=0;
      
        ST=0;
      
        ST=1;
        ST=0;
      
        while(EOC==0)
   
        OE=1;
        temp_=Data_ADC0809;
        OE=0;
        return temp_;
}

void Key()
{

        if(Key1==0)
        {
                while(Key1==0);
                if(Mode>=2) Mode=0;
                else
                {
                           write_com(0x38);
                           write_com(0x0d);
                           write_com(0x06)
                        Mode++;
                        switch(Mode)
                        {
                                case 1:
                                {
                                        write_com(0x80+12)
                                        break;
                                }
                                case 2:
                                {
                                        write_com(0x38);
                                        write_com(0x0c);
                                        Mode=0;
                                        break;
                                }

                        }
                }
        }
        if(Key2==0&&Mode!=0)
        {
                while(Key2==0);
                switch(Mode)
                {

                        case 1:
                        {
                                yushe_light++;
                                if(yushe_light>=255)
                                yushe_light=255;
                                write_com(0x80+13);
                                write_data(0x30+yushe_light/100);
                                write_data(0x30+yushe_light%100/10);
                                write_data(0x30+yushe_light%10);
                                break;                                
                        }
                }
        }
        if(Key3==0&&Mode!=0)
        {
                while(Key3==0);
                switch(Mode)
                {
                        case 1:
                        {
                                yushe_light--;
                                if(yushe_light<=0)
                                yushe_light=0;
                                write_com(0x80+13);
                                write_data(0x30+yushe_light/100);
                                write_data(0x30+yushe_light%100/10);
                                write_data(0x30+yushe_light%10);
                                break;                                
                        }
                }
        }
        delay(200);
        write_com(0x38);
        write_com(0x0c);
}

void main()
{
        Init1602();         
        fs=0;
        while(1)
        {
                temp=ADC0809();
                Key();

                if(Mode==0)
                {
                        Display_1602(yushe_wendu,yushe_light,c,temp);
                        if(temp>=yushe_light)
                        {
                                LED_light=0;
                                baojing=0;
                                fs=1;
                        }
                        else
                        {
                                LED_light=1;
                        }

                        if(temp<yushe_light)
                        {
                                baojing=1;
                                fs=0;
                        }
                }
        }
}        
全部资料51hei下载地址:
光照强度检测程序5.20.2.rar (27.87 KB, 下载次数: 29)
光照强度检测proteus仿真.rar (98.23 KB, 下载次数: 34)


作者: 51hei团团    时间: 2021-7-2 16:00
好资料,51黑有你更精彩!!!




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1