標(biāo)題: keil4編程總是顯示有錯誤,求大神解答 [打印本頁]

作者: 1903394084    時間: 2018-3-28 13:45
標(biāo)題: keil4編程總是顯示有錯誤,求大神解答
本帖最后由 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();這一行總顯示有錯誤
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;
}

作者: 冰純    時間: 2018-3-28 20:08
第四行最后多寫一個uchar
作者: hpshhh    時間: 2018-3-28 20:10
定義uchar出錯了,在上面的定義中#ifndef uchar
#define uchar unsigned char
#endif
改成這樣就可以了
作者: tstzyk    時間: 2018-3-28 21:07
#define uchar unsigned char
#endif
作者: 1903394084    時間: 2018-3-29 16:38
謝謝!




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1