找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3761|回復(fù): 4
收起左側(cè)

keil4編程總是顯示有錯(cuò)誤,求大神解答

[復(fù)制鏈接]
ID:294964 發(fā)表于 2018-3-28 13:45 | 顯示全部樓層 |閱讀模式
1黑幣
本帖最后由 1903394084 于 2018-3-28 14:25 編輯

這是頭文件
#ifndef _temp_H_
#define _temp_H_
#ifndef uchar
#define uchar unsigned char uchar
#endif
#ifndef uint
#define uint unsigned int
#endif
sbit DQ=P3^7;
uchar DSB20INIT();這一行總顯示有錯(cuò)誤
int READTIME();
void DSB20COM();
void DSB20CH();
void DSB20R();
void DSB20W();
void delayms(uint y);

#endif


這是c文件
#include"reg52.h"
#include"temp.h"
void delayms(uint y)
{
    uint x;
    for(;y>0;y--)
    {
        for(x=110;x>0;x--);
    }   
}
uchar DSB20INIT()
{
    uchar i;
    DQ=0;
    i=70;
    while(i--);
    DQ=1;
    i=0;
    while(DQ)
    {
        delayms(1);
        i++;
        if(i>5)
        {
            return 0;
        }
    }  
    return 1;
}
void DSB20W(uchar dat)
{
    uint i,j;
    for(j=0;j<8;j++)
    {
        DQ=0;
        i++;
        DQ=dat&0x01;
        i=6;
        while(i--);
        DQ=1;
        dat>>=1;
    }
}
void DSB20R(uchar byte)
{
    uint i,j;
    uchar bi;
    for(j=0;j<8;j++);
    {
        DQ=0;
        i++;
        DQ=1;
        i++;
        i++;
        bi=DQ;
        byte=(byte>>=1)|(bi<<=7)
        i=6;
        while(i--);
    }
    return byte;
}
void DSB20CH()
{
    DSB20INIT();
    delayms(1);
    DSB20W(0xcc);
    DSB20W(0x44);
}
void DSB20COM()
{
    DSB20INIT();
    delayms(1);
    DSB20W(0xcc);
    DSB20W(0xbe);   
}
int READTIME()
{
    int temp=0;
    uchar tml,tmh;
    DSB20CH();
    DSB20COM();
    tml=DSB20R();
    tmh=DSB20R();
    temp=tmh;
    temp<<=8;
    temp=temp|tml;
    return temp;
}

回復(fù)

使用道具 舉報(bào)

ID:261288 發(fā)表于 2018-3-28 20:08 | 顯示全部樓層
第四行最后多寫一個(gè)uchar
回復(fù)

使用道具 舉報(bào)

ID:298530 發(fā)表于 2018-3-28 20:10 | 顯示全部樓層
定義uchar出錯(cuò)了,在上面的定義中#ifndef uchar
#define uchar unsigned char
#endif
改成這樣就可以了
回復(fù)

使用道具 舉報(bào)

ID:297224 發(fā)表于 2018-3-28 21:07 | 顯示全部樓層
#define uchar unsigned char
#endif
回復(fù)

使用道具 舉報(bào)

ID:294964 發(fā)表于 2018-3-29 16:38 | 顯示全部樓層
謝謝!
回復(fù)

使用道具 舉報(bào)

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

本版積分規(guī)則

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

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

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