找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

這是一個溫控系統(tǒng)的的程序,有錯誤一個,,,實在不知道錯在哪了,跪求大神!。!

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:70508 發(fā)表于 2014-12-15 17:01 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include<reg52.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
sbit ds=P2^6;    //ζè′«¸DÆ÷DÅoÅÏß
sbit smg=P0;     //êyÂë1üÏÔê¾
sbit smg1=P2;
sbit jdq=P1^7;    //¼ìμçÆ÷′®¿ú
uint temp;       //¶¨òåÕûDÎμÄζèêy¾Y
float f_temp;     //¶¨ò帡μãDíμÄζèêy¾Y

unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x6d,0x7d,0x07,0x7f,0x6f,  //′øD¡êyμãμÄ12òõ0~9±àÂë
                            0xbf,0x86,0xdb,0xcf,0xe6,0xfd,0x87,0xff,0xef,};//2»′øD¡êyμãμÄ
void delay(uint z)   
{
        uint x,y;
        for (x=z;x>0;x--)
             for(y=110;y>0;y--);
}
void dsreset()   //DS18B20μĸ′룬3õê¼»ˉoˉêy
{
        uint i;
        ds=0;
        i=103;
        while(i>0)
                i--;
        ds=1;
   i=4;
while(i>0)
    i--;       
}
bit tempreadbit()   //¶á1λêy¾Yoˉêy
{
        uint i;
        bit dat;
        ds=0;i++;        //Ñóê±×÷óÃ
        dat=ds;
        i=8;
        while(i>0)
                i--;
                return(dat);
       
}
uchar tempreda()   //¶áò»¸ö×Ö½úêy¾Yoˉêy
{
        uchar i,j,dat;
        dat=0;
        for(i=1;i<=8;i++)
        {
                j=tempreadbit();
                dat=(j<<7)|(dat>>1);   //¶á3öμÄêy¾Y×îμíλÔú×îÇ°Ãæ£¬ÕaÑù¸ÕoÃò»¸ö×Ö½úÔúdatàïÃæ
}
        return(dat);
        }
void tempwritebyte(uchar dat)    //ÏòDS18B20D′ò»¸ö×Ö½úêy¾Yoˉêy
{
        uint i;
        uchar j;
        bit testb;
        for(j=1;j<=8;j++)
        {
                testb=dat&0x01;
                dat=dat>>1;
                if(testb)
                {
                        ds=0;
                        i++;
                        i++;
                        ds=1;
                        i=8;
                        while(i>0)i--;
                }
                        else
                        {
                                ds=0;
                                i=8;
                                while(i>0)i--;
                                ds=1;
                                i++;i++;
                }
        }
}
void tempchange(void)      //DS18B20¿aê¼»ñè¡Î¶è2¢×a»»
{
        dsreset();
        delay(1);
         void tempwritebyte(0xcc);
         tempwritebyte(0x44);
}
uint get_temp()
{
        uchar a,b;
        dsreset();
        delay(1);
        tempwritebyte(0xcc);
        tempwritebyte(0xbe);
        a=tempread();
        b=tempread();
        temp=b;
        temp<<=8;
        temp=temp|a;
        f_temp=temp*0.0625;
        temp=_f_temp*10+0.5;
        f_temp=f_temp+0.05;
        return temp;
}
void display(uchar num,uchar dat)
{
        uchar i;
        P0=0;
        P0=table[dat];
        P2=0;
        i=0xff;
        i=i&(~((0x01)<<(num)));
        P0=i;
        P2=0;
        delay(1);
       
}
void dis_temp(uint i)
{
        uchar i;
        i=1/100;
        display(0,1);
        i=t%100/10;
        display(1,i+10);
        i=t%100%10;
        display(2,i);
       
}
void deal(uint t)
{
        if(t<=11)
                P1^7=1;
               
}

void main()
{
        uchar buff[4],i;
        while(1)
        {
                tempchange();
                for(i=10;i>0i--);
                {
                        dis_temp(get_temp());
                       
        }
                deal(temp);
                sprintf(buff,"%f",f_temp);
                for(i=10;i>0;i--)
                {
                        distemp(get_temp());
        }
}
}

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

使用道具 舉報

沙發(fā)
ID:69862 發(fā)表于 2014-12-15 18:56 | 只看該作者
首先你應(yīng)該說明一下,是在什么地方有錯誤。
回復(fù)

使用道具 舉報

板凳
ID:70508 發(fā)表于 2014-12-16 09:15 | 只看該作者
xiao_yp2014 發(fā)表于 2014-12-15 18:56
首先你應(yīng)該說明一下,是在什么地方有錯誤。

kile顯示說就在void tempchange(void) 函數(shù)的void tempwritebyte(0xcc);附近有錯誤,但我實在是找不出來在哪啊?你有kile的話可以復(fù)制在上面看一下,謝謝啦,,,,
回復(fù)

使用道具 舉報

地板
ID:69862 發(fā)表于 2014-12-16 09:45 | 只看該作者
菜鳥一個666 發(fā)表于 2014-12-16 09:15
kile顯示說就在void tempchange(void) 函數(shù)的void tempwritebyte(0xcc);附近有錯誤,但我實在是找不出來 ...

你的程序中不不止一個錯誤,有好幾個,我已經(jīng)給你改過來了,但是還是需要你自己去調(diào)試功能。
下次寫程序的時候,建議一定要寫規(guī)范一點,變量名要具有一定的特殊意義,比如說定義一個無符號字符型變量,這個就是用來存一個按鍵數(shù)值,可以這樣定義:unsigned char ucKeyNumber;
                                                                     unsigned  int  uiTimeCnt;
希望對你有幫助。。。。。。。。。。。。
回復(fù)

使用道具 舉報

5#
ID:69862 發(fā)表于 2014-12-16 09:47 | 只看該作者
xiao_yp2014 發(fā)表于 2014-12-16 09:45
你的程序中不不止一個錯誤,有好幾個,我已經(jīng)給你改過來了,但是還是需要你自己去調(diào)試功能。
下次寫程序 ...

#include<reg52.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int

sbit ds=P2^6;   
sbit smg=P0;   
sbit smg1=P2;
sbit jdq=P1^7;   

uint temp;      
float f_temp;     

unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x6d,0x7d,0x07,0x7f,0x6f,  //′?D?êyμ?μ?12ò?0~9±à??
                    
                                                0xbf,0x86,0xdb,0xcf,0xe6,0xfd,0x87,0xff,0xef,};//2?′?D?êyμ?μ?
void delay(uint z)   
{
        uint x,y;
        for (x=z;x>0;x--)
             for(y=110;y>0;y--);

}

void dsreset()   
{
        uint i;
        ds=0;
        i=103;
        while(i>0)
                i--;
        ds=1;
        i=4;
        while(i>0)
        i--;        
}

bit tempreadbit()   
{
        uint i;
        bit dat;
        ds=0;i++;      
        dat=ds;
        i=8;
        while(i>0)
        i--;
        return(dat);
        
}

uchar tempread()   
{
        uchar i,j,dat;
        dat=0;
        for(i=1;i<=8;i++)
        {
           j=tempreadbit();
           dat=(j<<7)|(dat>>1);  
        }
        return(dat);
}

void tempwritebyte(uchar dat)   
{
        uint i;
        uchar j;
        bit testb;
        for(j=1;j<=8;j++)
        {
                testb=dat&0x01;
                dat=dat>>1;
                if(testb)
                {
                        ds=0;
                        i++;
                        i++;
                        ds=1;
                        i=8;
                        while(i>0)i--;
                }
                                else
                                {
                                    ds=0;
                                    i=8;
                                    while(i>0)i--;
                                    ds=1;
                                    i++;i++;
                                }
        }
}

void tempchange(void)      
{
        dsreset();
        delay(1);
        tempwritebyte(0xcc);
        tempwritebyte(0x44);
}

uint get_temp()
{
        uchar a,b;
        float _f_temp;
        dsreset();
        delay(1);
        tempwritebyte(0xcc);
        tempwritebyte(0xbe);
        a=tempread();
        b=tempread();
        temp=b;
        temp<<=8;
        temp=temp|a;
        f_temp=temp*0.0625;
        temp=_f_temp*10+0.5;
        f_temp=f_temp+0.05;
        return temp;
}

void display(uchar num,uchar dat)
{
        uchar i;
        P0=0;
        P0=table[dat];
        P2=0;
        i=0xff;
        i=i&(~((0x01)<<(num)));
        P0=i;
        P2=0;
        delay(1);
        
}

void dis_temp(uint value)
{
        uchar dis_temp_value = value;
                unsigned char bai = 0;
                unsigned char shi = 0;
                unsigned char ge = 0;

        bai=dis_temp_value/100;
        display(0,1);
        shi=dis_temp_value%100/10;
        display(1,dis_temp_value+10);
        ge=dis_temp_value%100%10;
        display(2,dis_temp_value);
}

void deal(uint t)
{
        if(t<=11)
        P1 = 0x7f;
}

void main()
{
        
        while(1)
        {
               uchar buff[4],i;
                                tempchange();

                for(i=10;i>0;i--)
                {
                   dis_temp(get_temp());
                }

                deal(temp);
                sprintf(buff,"%f",f_temp);

                for(i=10;i>0;i--)
                {
                   dis_temp(get_temp());
                }
         }
}



修改后的程序。。。。。。。。。。
回復(fù)

使用道具 舉報

6#
ID:70508 發(fā)表于 2014-12-16 09:49 | 只看該作者
xiao_yp2014 發(fā)表于 2014-12-16 09:45
你的程序中不不止一個錯誤,有好幾個,我已經(jīng)給你改過來了,但是還是需要你自己去調(diào)試功能。
下次寫程序 ...

謝謝您的建議,一定會吸取和采納!謝謝!!
回復(fù)

使用道具 舉報

7#
ID:69862 發(fā)表于 2014-12-16 09:52 | 只看該作者
菜鳥一個666 發(fā)表于 2014-12-16 09:49
謝謝您的建議,一定會吸取和采納!謝謝!

希望對你有幫助,學(xué)習(xí)嘛,主要是為了傳播知識,讓更多的人受益。。。。。
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表