求助各位高手们 谁能帮我呀
帮忙看看我的这个程序锉刀什么地方了 再次谢谢给位高手了{:smile:} {:smile:}#include<reg52.h>
#include<intrins.h> //包含_nop_()函数定义的头文件
#define uchar unsigned char
#define uint unsigned int
/* 函数申明 -----------------------------------------------*/
void Set_RTC(void);
void Read_RTC(void);
uchar Read_Ds1302 ( uchar address );
void Write_Ds1302( uchar address,uchar dat );
void Write_Ds1302_Byte(unsignedchar temp);
void senddata(void);
void init_ds1302(void);
void out(void);
void Init_Timer0(void); //定时器初始化子程序
void delay(uint z);
/* 变量定义 -----------------------------------------------*/
sbit SCK=P3^6; //时钟
sbit SDA=P3^4; //数据
sbit RST=P3^5;// DS1302复位
unsigned char m;
unsigned char flag;
unsigned int count;
uchar l_tmpdate={0,25,16,3,8,11,20};//秒分时日月周年2011-07-14 12:00:00
uchar l_tmpdisplay;
code uchar write_rtc_address={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; //秒分时日月周年 最低位读写位
code uchar read_rtc_address={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
unsigned char code fseg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //数码管段选
unsigned char code segbit[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; //数码管位选
unsigned chardisbuf={0,0,0,0,0,0,0,0};
void main(void)
{
init_ds1302();
// Set_RTC(); //写入时钟值,如果使用备用电池时候,不需要没每次上电写入,此程序应该屏蔽
while(1)
{
Read_RTC();
{
l_tmpdisplay=l_tmpdate/16;//数据的转换,因我们采用数码管0~9的显示,将数据分开
l_tmpdisplay=l_tmpdate&0x0f;
l_tmpdisplay=10; //加入"-"
l_tmpdisplay=l_tmpdate/16;
l_tmpdisplay=l_tmpdate&0x0f;
l_tmpdisplay=10;
l_tmpdisplay=l_tmpdate/16;
l_tmpdisplay=l_tmpdate&0x0f;
senddata();
out();
}
}
}
/*
********************************************************************************
** 函数名称 : out(void)
** 函数功能 : 数据输出
********************************************************************************
*/
void out(void)
{ R_CLKa=0;
delay(30);
R_CLKa=1;
}
/*
********************************************************************************
** 函数名称 : senddata (void)
** 函数功能 : 数据传输
********************************************************************************
*/
void senddata (void)
{unsigned char b,c,num;
if(b==0)
{
b++;
num=segbit;
for(c=0;c<8;c++)
{S_CLKa=0;
MOSIO=num&0x80;
num<<=1;
S_CLKa=1;
}
}
if(b==1)
{
b--;
if(m==2||m==5)
{num=0xbf;}
else
{
//num=fseg];
num=fseg];
}
for(c=0;c<8;c++)
{S_CLKa=0;
MOSIO=num&0x80;
num<<=1;
S_CLKa=1;
}
}
m++;
if(m==8)
{m=0;
}
}
/*
********************************************************************************
** 函数名称 : Write_Ds1302_Byte(unsignedchar temp)
** 函数功能 : 写一个字节
********************************************************************************
*/
void Write_Ds1302_Byte(unsignedchar temp)
{
uchar i;
for (i=0;i<8;i++) //循环8次 写入数据
{
SCK=0;
SDA=temp&0x01; //每次传输低字节
temp>>=1; //右移一位 从左往右一次降低
SCK=1;
}
}
/*
********************************************************************************
** 函数名称 : Write_Ds1302( uchar address,uchar dat )
** 函数功能 : 写入DS1302
********************************************************************************
*/
void Write_Ds1302( uchar address,uchar dat )
{
RST=0;
_nop_();
SCK=0;
_nop_();
RST=1;
_nop_(); //启动
Write_Ds1302_Byte(address); //发送地址
Write_Ds1302_Byte(dat); //发送数据
RST=0;
_nop_(); //恢复
}
/*
********************************************************************************
** 函数名称 : Read_Ds1302 ( uchar address )
** 函数功能 : 读出DS1302数据
********************************************************************************
*/
uchar Read_Ds1302 ( uchar address )
{
uchar i,temp=0x00;
RST=0;
_nop_();
_nop_();
SCK=0;
_nop_();
_nop_();
RST=1;
_nop_();
_nop_();
Write_Ds1302_Byte(address);
for (i=0;i<8;i++) //循环8次 读取数据
{
if(SDA)
temp|=0x80; //每次传输低字节
SCK=0;
temp>>=1; //右移一位
_nop_();
_nop_();
_nop_();
SCK=1;
}
RST=0;
_nop_(); //以下为DS1302复位的稳定时间
_nop_();
RST=0;
SCK=0;
_nop_();
_nop_();
_nop_();
_nop_();
SCK=1;
_nop_();
_nop_();
SDA=0;
_nop_();
_nop_();
SDA=1;
_nop_();
_nop_();
return (temp); //返回
}
/*
********************************************************************************
** 函数名称 : Read_RTC(void)
** 函数功能 : 读时钟数据
********************************************************************************
*/
void Read_RTC(void) //读取 日历
{
uchar i,*p;
p=read_rtc_address; //地址传递
for(i=0;i<7;i++) //分7次读取 秒分时日月周年
{
l_tmpdate=Read_Ds1302(*p);
p++;
}
}
/*
********************************************************************************
** 函数名称 : Set_RTC(void)
** 函数功能 : 设定时钟数据
********************************************************************************
*/
void Set_RTC(void) //设定 日历
{
uchar i,*p,tmp;
Write_Ds1302(0x8E,0X00);
for(i=0;i<7;i++)
{ //BCD处理
tmp=l_tmpdate/10;
l_tmpdate=l_tmpdate%10;
l_tmpdate=l_tmpdate+tmp*16;
}
p=write_rtc_address; //传地址
for(i=0;i<7;i++) //7次写入 秒分时日月周年
{
Write_Ds1302(*p,l_tmpdate);
p++;
}
Write_Ds1302(0x8E,0x80);
}
/*
********************************************************************************
** 函数名称 :delay(uint z)
** 函数功能 : 延时函数 延时0.1ms个单位
********************************************************************************
*/
void delay(uint z)
{{ while(z--);
}
}
/**********************************************************/
// 初始化DS1302
/**********************************************************/
void init_ds1302()
{
RST=0;
SCK=0;
Write_Ds1302(0x80,0x00);
Write_Ds1302(0x90,0x5c); //禁止充电
Write_Ds1302(0x8e,0x80); //写保护控制字,禁止写
}
编译一下就知道了
Rebuild target 'Target 1'
assembling STARTUP.A51...
compiling test.c...
test.c(81): error C202: 'R_CLKa': undefined identifier
test.c(83): error C202: 'R_CLKa': undefined identifier
test.c(100): error C202: 'S_CLKa': undefined identifier
test.c(101): error C202: 'MOSIO': undefined identifier
test.c(103): error C202: 'S_CLKa': undefined identifier
test.c(121): error C202: 'S_CLKa': undefined identifier
test.c(122): error C202: 'MOSIO': undefined identifier
test.c(124): error C202: 'S_CLKa': undefined identifier
Target not created 还是弄不出来呀
页:
[1]