搜索
bottom↓
回复: 2

求助各位高手们 谁能帮我呀

[复制链接]

出0入0汤圆

发表于 2012-8-25 22:06:21 | 显示全部楼层 |阅读模式
帮忙看看我的这个程序锉刀什么地方了   再次谢谢给位高手了


#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(unsigned  char 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[7]={0,25,16,3,8,11,20};//秒分时日月周年2011-07-14 12:00:00
uchar l_tmpdisplay[8];
code uchar write_rtc_address[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; //秒分时日月周年 最低位读写位
code uchar read_rtc_address[7]={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 char  disbuf[8]={0,0,0,0,0,0,0,0};






void main(void)   
{
        init_ds1302();

//         Set_RTC();             //写入时钟值,如果使用备用电池时候,不需要没每次上电写入,此程序应该屏蔽
        while(1)
        {
       
       
                Read_RTC();
        {                               
                        l_tmpdisplay[7]=l_tmpdate[2]/16;//数据的转换,因我们采用数码管0~9的显示,将数据分开
                        l_tmpdisplay[6]=l_tmpdate[2]&0x0f;
                        l_tmpdisplay[5]=10;                                                    //加入"-"
                        l_tmpdisplay[4]=l_tmpdate[1]/16;
                        l_tmpdisplay[3]=l_tmpdate[1]&0x0f;
                        l_tmpdisplay[2]=10;
                        l_tmpdisplay[1]=l_tmpdate[0]/16;
                    l_tmpdisplay[0]=l_tmpdate[0]&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[m];
         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[disbuf[m]];
                        num=fseg[l_tmpdisplay[m]];
           }

                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(unsigned  char temp)
** 函数功能 : 写一个字节
********************************************************************************
*/

void Write_Ds1302_Byte(unsigned  char 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[i]=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[i]/10;
                l_tmpdate[i]=l_tmpdate[i]%10;
                l_tmpdate[i]=l_tmpdate[i]+tmp*16;
        }  
       
       
        p=write_rtc_address;        //传地址       
        for(i=0;i<7;i++)                //7次写入 秒分时日月周年
        {
                  Write_Ds1302(*p,l_tmpdate[i]);
                  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); //写保护控制字,禁止写
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2012-8-25 22:29:15 | 显示全部楼层
编译一下就知道了

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

出0入0汤圆

 楼主| 发表于 2012-8-30 14:01:14 | 显示全部楼层
还是弄不出来呀
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 00:23

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表