久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 2305|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

哪位大神可以幫個(gè)忙詳細(xì)解讀一下這個(gè)程序,小白不太明白怎么個(gè)運(yùn)行,求幫助

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:655075 發(fā)表于 2019-12-8 18:40 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
50黑幣
#include<reg52.h>
#include<math.h>
#define uint unsigned int
#define uchar unsigned char
#define lcddata P0
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
sbit DQ=P2^3;
sbit key=P3^7;
uchar temp1[]={"T :       "};
uchar temp2[]={"T :       "};
/*uchar temp3[9]={"T3:      "};
uchar temp4[9]={"T4:      "};
uchar temp5[9]={"T5:      "};
uchar temp6[9]={"Ta:      "};*/
uchar code ds_rom1[]={0x28,0x22,0x22,0x22,0x00,0x00,0x00,0xca};//U2ROM
uchar code ds_rom2[]={0x28,0x33,0x33,0x33,0x00,0x00,0x00,0xa0};//U3ROM
uchar code ds_rom3[]={0x28,0x44,0x44,0x44,0x00,0x00,0x00,0xAF};//U4ROM
uchar code ds_rom4[]={0x28,0x55,0x55,0x55,0x00,0x00,0x00,0xC5};//U5ROM
uchar code ds_rom5[]={0x28,0x66,0x66,0x66,0x00,0x00,0x00,0x7B};//U6ROM
int temp;//溫度
bit temp_flag,value_flag;//正負(fù)標(biāo)志位
int t1,t2,t3,t4,t5,num=1;


/*1602LCD函數(shù)*/
void delay(uint x)
{
        uint a,b;
        for(a=x;a>0;a--)
                for(b=110;b>0;b--);
}


void writelcd(uchar dat,bit x)//寫(xiě)操作
{
        e=0;
        lcddata=dat;
        rs=x;          //0指令,1數(shù)據(jù)
        rw=0;
        e=1;
        delay(1);
        e=0;
}


void initlcd()
{
        writelcd(0x38,0);        // 設(shè)置為8-bit接口,2行顯示,5x8文字大小
        writelcd(0x0c,0);   // 設(shè)置為開(kāi)顯示,光標(biāo)不顯示,不閃爍
        writelcd(0x06,0);   // 設(shè)置為完成一個(gè)字符碼傳送后,AC自動(dòng)加1,,右移位
        writelcd(0x01,0);        // 清顯示
}
/*DS18B20*/
void delayus(uchar x)//        延時(shí)1us
{
        while(--x);
}


bit init_DS18B20()//初始化
{
        bit Status_DS18B20;
        DQ=1;
        DQ=0;
        delayus(250);
        DQ=1;
        delayus(20);
        if(!DQ)
                Status_DS18B20=0;
        else
                Status_DS18B20=1;
        delayus(250);
        DQ=1;
        return Status_DS18B20;


}


uchar read_DS18B20()//讀數(shù)據(jù)
{
        uchar i=0,dat=0;
        for(i=0;i<8;i++)
        {
                DQ=1;
                DQ=0;
                dat>>=1;                   //八位全部都是0,向右移一位后,仍然全是0
                DQ=1;
                if(DQ)                      //如果DQ為1,readat進(jìn)行或運(yùn)算,如果為0,則子語(yǔ)句不執(zhí)行,直接for循環(huán)此時(shí)采集的數(shù)據(jù)是0
                        dat|=0x80;          //此時(shí)最高位為1,然后再進(jìn)行for循環(huán) 最高位成為第七位,依次往復(fù)
                DQ=1;
                delayus(25);
        }
        return(dat);
}


void write_DS18B20(uchar dat)//寫(xiě)數(shù)據(jù)
{
        uchar i;
        for(i=0;i<8;i++)
        {
                DQ=1;
                dat>>=1;
                DQ=0;
                DQ=CY;
                delayus(25);
                DQ=1;
        }
}


void Match_rom(uchar a)         //匹配ROM
{
        uchar j;
        write_DS18B20(0x55);           //發(fā)送匹配ROM命令
        if(a==1)
        {
                for(j=0;j<8;j++)
                        write_DS18B20(ds_rom1[j]);                //發(fā)送18B20的序列號(hào),先發(fā)送低字節(jié)
        }
        if(a==2)
        {
                for(j=0;j<8;j++)
                        write_DS18B20(ds_rom2[j]);                //發(fā)送18B20的序列號(hào),先發(fā)送低字節(jié)
        }
        if(a==3)
        {
                for(j=0;j<8;j++)
                        write_DS18B20(ds_rom3[j]);                //發(fā)送18B20的序列號(hào),先發(fā)送低字節(jié)
        }
        if(a==4)
        {
                for(j=0;j<8;j++)
                        write_DS18B20(ds_rom4[j]);                //發(fā)送18B20的序列號(hào),先發(fā)送低字節(jié)
        }
        if(a==5)
        {
                for(j=0;j<8;j++)
                        write_DS18B20(ds_rom5[j]);                //發(fā)送18B20的序列號(hào),先發(fā)送低字節(jié)
        }


}

void gettemp(uchar z)/*讀取溫度值并轉(zhuǎn)換*/
{      
        uchar a,b;
        while(init_DS18B20());   
        if(z==1)
        {
                Match_rom(1);                 //匹配ROM 1
        }
        if(z==2)
        {
                Match_rom(2);                 //匹配ROM         2
        }
        if(z==3)
        {
                Match_rom(3);                 //匹配ROM         3
        }
        if(z==4)
        {
                Match_rom(4);                 //匹配ROM         4
        }
        if(z==5)
        {
                Match_rom(5);                 //匹配ROM         5
        }


        write_DS18B20(0x44);//*啟動(dòng)溫度轉(zhuǎn)換*/
        while(init_DS18B20());   
        if(z==1)
        {
                Match_rom(1);                            //匹配ROM 1
        }
        if(z==2)
        {
                Match_rom(2);                                //匹配ROM         2
        }
        if(z==3)
        {
                Match_rom(3);                 //匹配ROM         3
        }
        if(z==4)
        {
                Match_rom(4);                 //匹配ROM         4
        }
        if(z==5)
        {
                Match_rom(5);                 //匹配ROM         5
        }
        write_DS18B20(0xbe);//*讀取溫度*/
        a=read_DS18B20();
        b=read_DS18B20();
        temp=b;
        temp<<=8;
        temp=temp|a;
    if(b>=8)
        {
                temp=~temp+1;
            temp_flag=1;
        }
    else
    {      
                temp_flag=0;
        }
        if(temp_flag==1)
                temp=temp*0.625*-1;
        if(temp_flag==0)
                temp=temp*0.625;
        if(z==1)
        t1=temp;
        if(z==2)
        t2=temp;
        if(z==3)
        t3=temp;
        if(z==4)
        t4=temp;
        if(z==5)
        t5=temp;
}
void display(uchar i)//顯示函數(shù)
{
        char y,value;
        temp=abs(temp);
        if(i==1)
        {
                temp1[1]=i+0x30;
                if(temp<100)
                        temp1[4]=' ';
                else
                        temp1[4]=temp%1000/100+0x30;
                temp1[5]=temp%100/10+0x30;
                temp1[6]='.';
                temp1[7]=temp%10+0x30;
                temp1[8]=0xdf;
                temp1[9]='C';
                writelcd(0x80,0);
                for(y=0;y<10;y++)
                writelcd(temp1[y],1);
        }
        if(i==2)
        {
                temp2[1]=i+0x30;               
                if(temp<100)
                        temp2[4]=' ';
                else
                        temp2[4]=temp%1000/100+0x30;
                temp2[5]=temp%100/10+0x30;
                temp2[6]='.';
                temp2[7]=temp%10+0x30;
                temp2[8]=0xdf;
                temp2[9]='C';
                writelcd(0xc0,0);
                for(y=0;y<10;y++)
                writelcd(temp2[y],1);
        }
        if(i==3)
        {
                temp1[1]=i+0x30;
                if(temp<100)
                        temp1[4]=' ';
                else
                        temp1[4]=temp%1000/100+0x30;
                temp1[5]=temp%100/10+0x30;
                temp1[6]='.';
                temp1[7]=temp%10+0x30;
                temp1[8]=0xdf;
                temp1[9]='C';
                writelcd(0x80,0);
                for(y=0;y<10;y++)
                writelcd(temp1[y],1);
        }
        if(i==4)
        {
                temp2[1]=i+0x30;
                if(temp<100)
                        temp2[4]=' ';
                else
                        temp2[4]=temp%1000/100+0x30;
                temp2[5]=temp%100/10+0x30;
                temp2[6]='.';
                temp2[7]=temp%10+0x30;
                temp2[8]=0xdf;
                temp2[9]='C';
                writelcd(0xc0,0);
                for(y=0;y<10;y++)
                writelcd(temp2[y],1);
        }
        if(i==5)
        {
                temp1[1]=i+0x30;
                if(temp<100)
                        temp1[4]=' ';
                else
                        temp1[4]=temp%1000/100+0x30;
                temp1[5]=temp%100/10+0x30;
                temp1[6]='.';
                temp1[7]=temp%10+0x30;
                temp1[8]=0xdf;
                temp1[9]='C';
                writelcd(0x80,0);
                for(y=0;y<10;y++)
                writelcd(temp1[y],1);
        }
        if(i==6)
        {
                value=(t1+t2+t3+t4+t5)/5;
                if(value<0)
                {
                        value_flag=1;
                        value=value*-1;      
                }
                else
                        value_flag=0;
                if(value_flag==1)
                        temp2[3]='-';
                else
                        temp2[3]=' ';
                temp2[1]='a';      
                if(temp<100)
                        temp2[4]=' ';
                else
                        temp2[4]=value%1000/100+0x30;
                temp2[5]=value%100/10+0x30;
                temp2[6]='.';
                temp2[7]=value%10+0x30;
                temp2[8]=0xdf;
                temp2[9]='C';
                writelcd(0xc0,0);
                for(y=0;y<10;y++)
                writelcd(temp2[y],1);
        }
        if(temp_flag==1)
        {
                temp1[3]='-';
                temp2[3]='-';
      
        }
        else
        {
                temp1[3]=' ';
                temp2[3]=' ';
        }               
}


void initT0()
{
        TMOD=0x01;
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        EA=1;
        ET0=1;
        TR0=1;
}


void keyscan()
{
        if(key==0)
        {
                delay(5);
                if(key==0)
                {
                        TR0=0;
                        while(!key);
                        TR0=1;
                }
        }
}










void main()
{
        initlcd();
        initT0();
        while(1)
        {
                keyscan();
                   if(num==1)//第一頁(yè)
                   {
                        gettemp(1);
                        display(1);
                        gettemp(2);
                        display(2);
                }
                if(num==2)//第二頁(yè)
                {
                        gettemp(3);
                        display(3);
                        gettemp(4);
                        display(4);
                }
                if(num==3)//第三頁(yè)
                {
                        gettemp(5);
                        display(5);
                        display(6);
                }
      
        }
      
}


void timer_0() interrupt 1
{
        uchar us,s;
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        us++;
        if(us==20)
        {
                us=0;
                s++;
                if(s==1)
                        num=1;
                if(s==2)
                        num=2;
                if(s==3)
                {
                        s=0;
                        num=3;
                }
        }      
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 久久精品中文字幕 | 羞羞的视频网站 | 国产精品久久二区 | 久久伊人久久 | 欧美日韩免费视频 | 欧美一卡二卡在线 | 国产精品激情小视频 | 国产精品成人一区二区三区 | 国产精品福利在线 | 成人免费小视频 | 激情av| 一级免费视频 | h小视频| 久草在线在线精品观看 | 久久精品久久综合 | 一级二级三级黄色 | 伊人色综合久久久天天蜜桃 | 欧美在线视频网站 | 精品日韩在线 | 久在线观看 | 91嫩草精品 | 亚洲综合资源 | 久久亚洲欧美日韩精品专区 | 亚洲第一福利视频 | 亚洲精品久久久久中文字幕二区 | 国产精品久久精品 | 国产精品美女久久久久久久网站 | 久久免费精品视频 | 国产精品亚洲综合 | 欧美美女爱爱视频 | 欧美一区精品 | 亚洲福利| 好好的日在线视频 | 2018国产大陆天天弄 | 久久久久久久久久一区 | 中文字幕亚洲欧美日韩在线不卡 | 欧美视频在线看 | 日韩精品久久久 | 超碰97免费在线 | 日本a级大片 | 欧美激情 一区 |