参考普中单片机编写的一个时钟程序,
编译的时候显示ds1302文件报错如下,搞了半天没闹明白,请问各位大神哪里出了问题。。。
ds1302.h文件
#ifndef _DS1302_H_
#define _DS1302_H_
#include "reg52.h"
#include "intrins.h"
#ifndef uint
#define uint unsigned int
#endif
#ifndef uchar
#define uchar unsighed uchar
#endif
sbit DSIO=P3^4;
sbit RST=P3^5;
sbit SCLK=P3^6;
void Ds1302Write(uchar addr,uchar dat);
uchar Ds1302Read(uchar addr);
void Ds1302Init();
void Ds1302ReadTime();
extern uchar TIME[7]; //??????
#endif
ds1302.c文件
#include "ds1302.h"
uchar TIME[7]=(0,0,0X12,0X07,0X05,0X06,0X16); //????????16??????????5??7??
uchar code READ_RTC_ADDR[7]=(0X81;0X83,0X85,0X87,0X89,0X8b,0X8d); //???????д????????1λ???1
uchar code WRITE_RTC_ADDR[7]=(0x90,0x82,0x84,0x86,0x88,0x8a,0x8c);
void Ds1302Write(uchar addr,uchar dat)
{
uchar n;
RST=0;
_nop_();
SCLK=0;
_nop_();
RST=1;
_nop_();
for(n=0;n<8;n++) //??????
{
DSIO=addr&0x01;
addr>>=1;
SCLK=1; //????????????
_nop_();
SCLK=0;
_nop_();
}
for(n=0;n<8;n++) //????????
{
DSIO=dat&0x01;
dat>>=1;
SCLK=1;
_nop_();
SCLK=0;
_nop_();
}
RST=0; //???????????
_nop_();
}
uchar Ds1302Read(uchar addr)
{
uchar n, dat, dat1;
RST=0;
_nop_();
SCLK=0;
_nop_();
RST=1; //CE????
_nop_();
for(n=0;n<8;n++)
{
DSIO=addr&0x01; //??????λ??????
addr>>=1;
SCLK=1; // ????????????
_nop_();
SCLK=0; //????????????
_nop_();
}
_nop_();
for(n=0;n<8;n++)
{
dat1=DSIO;
dat=(dat>>1)|(dat1<<7); //dat?????λ??dat1?????λ
SCLK=1; // ????????????
_nop_();
SCLK=0; //????????????
_nop_();
}
RST=0;
_nop_(); //δDS1302??λ????????????????
SCLK=1;
_nop_();
DSIO=0;
_nop_();
DSIO=1;
_nop_();
return dat;
}
void Ds1302Init()
{
uchar n;
Ds1302Write(0x8E,0x00); //???д?????????д????????
for(n=0;n<7;n++)
{
Ds1302Write(WRITE_RTC_ADDR[n],TIME[n]); //д??7????????????
}
Ds1302Write(0x8E,0x80); //??д????????
}
void Ds1302ReadTime()
{
uchar n;
for(n=0;n<7;n++)
{
TIME[n]=Ds1302Read(READ_RTC_ADDR[n]);
}
}
主文件
#include "reg52.h"
#include "ds1302.h"
typedef unsigned int u16;
typedef unsigned char u8;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
u8 code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
u8 DisplayData[8];
void delay(u16 i)
{
while(i--);
}
void datapros()
{
Ds1302ReadTime();
DisplayData[0]=smgduan[TIME[2]/16]; //??? ??????????????????
DisplayData[1]=smgduan[TIME[2]&0X0f];
DisplayData[2]=0x40; //?????
DisplayData[3]=smgduan[TIME[1]/16]; //??
DisplayData[4]=smgduan[TIME[1]&0X0f];
DisplayData[5]=0x40;
DisplayData[6]=smgduan[TIME[0]/16]; //??
DisplayData[7]=smgduan[TIME[0]&0x0f];
}
void DigDisplay()
{
u8 i;
for(i=0;i<8;i++)
{ switch(i)
{ case(0):
LSA=0;LSB=0;LSC=0;break; //?????0λ,??????
case(1):
LSA=1;LSB=0;LSC=0;break;
case(2):
LSA=0;LSB=1;LSC=0;break;
case(3):
LSA=1;LSB=1;LSC=0;break;
case(4):
LSA=0;LSB=0;LSC=1;break;
case(5):
LSA=1;LSB=0;LSC=1;break;
case(6):
LSA=1;LSB=1;LSC=0;break;
case(7):
LSA=1;LSB=1;LSC=1;break;
}
P0=DisplayData[7-i];
delay(100);
P0=0x00;
}
}
void main()
{
Ds1302Init();
while(1)
{
datapros();
DigDisplay();
}
}
|