这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » DS12887 DS12887的问题

共2条 1/1 1 跳转至

DS12887 DS12887的问题

院士
2006-09-17 18:14:16     打赏
DS12887 DS12887的问题



关键词: DS12887     问题    

院士
2006-12-22 22:43:00     打赏
2楼
问 最近用到DS12887,根据资料编了自己的程序,也用了一些网上公布的程序,可惜老是出错:DS12887不走,或者秒钟有100,但是分钟不变,或者初始值送不进DS12887,请各位指点DS12887的使用方法。
我只需读时间就行了,不需要里面的任何中断。谢谢! 1: Selectable between Motorola and Intel busSelectable between Motorola and Intel bus
timing
PIN 1 选择 2: 12887以下的程序就是读时间和led显示
#include <reg52.h>
#include <absacc.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define DS128870 XBYTE[0x2000]
#define DS128871 XBYTE[0x2001]
#define DS128872 XBYTE[0x2002]
#define DS128873 XBYTE[0x2003]
#define DS128874 XBYTE[0x2004]
#define DS128875 XBYTE[0x2005]
#define DS128876 XBYTE[0x2006]
#define DS128877 XBYTE[0x2007]
#define DS128878 XBYTE[0x2008]
#define DS128879 XBYTE[0x2009]
#define DS12887A XBYTE[0x200a]
#define DS12887B XBYTE[0x200b]
#define DS12887C XBYTE[0x200c]
#define DS12887D XBYTE[0x200d]
#define RAM1 XBYTE[0x0050]
#define RAM2 XBYTE[0x0051]

/**********显示设置******************/
unsigned char checksum,count3;
bit           read_flag=0;
sbit DISP_CLK=P1^0;    //the CLK of the LED display
sbit DISP_DO=P1^1;
uchar rcv_buffer[16],event;
uchar error,int_timers,code disp_table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint count;
/*******************************************************************/
void send_byte(uchar x)    //跟12887无关
{
    uchar i;
     for(i=0;i<8;i++)
     {
         DISP_CLK=0;
         DISP_DO=(bit)(x&0x80);
        x=x<<1;
        DISP_CLK=1;
    }
}
/*                        Ds12887&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;                            */
/*******************************************************************/

void initstat (void)      /*12887&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;*/  
{
     DS12887B=0x16;//&Iacute;&pound;&Ouml;&sup1;&cedil;ü&ETH;&Acirc;&pound;&not;&Ntilde;&iexcl;BCD&Acirc;&euml;&pound;&not;24&ETH;&iexcl;&Ecirc;±&Ouml;&AElig;
     DS12887A=0xa0;//&acute;ò&iquest;&ordf;&frac34;§&Otilde;&ntilde;&sup2;&cent;&Ocirc;&Ecirc;&ETH;íRTC&frac14;&AElig;&Ecirc;±
}

void wDS12887(void)
{
     int i;
     DS12887B=0x96;  
     DS128870=30;  //秒
     DS128872=21;  //分
     DS128874=8;   //时
     DS128871=0xff;DS128873=0xff;DS128875=0xff;
     DS128877=0x15;DS128878=0x02;DS128879=0x4;
     DS12887B=0x16;//&Atilde;&iquest;&Atilde;&euml;&frac14;&AElig;&Ecirc;±×&szlig;&Ograve;&raquo;&acute;&Icirc;&pound;&not;24&ETH;&iexcl;&Ecirc;±&Ouml;&AElig;
}

/***************&Ograve;&raquo;&cedil;&ouml;10ms&Ntilde;&Oacute;&Ecirc;±&sup3;&Igrave;&ETH;ò************************/
void delay10ms(unsigned char time)     //跟12887无关
{
    unsigned char i;
    unsigned int j;
    for (i=0;i<time;i++)
    {
        for(j=0;j<0x10;j++)
        {

        }
        }
}


void disp_led(uchar buffer,uchar control)   //跟12887无关
{
    uchar i,temp[6];
    uint tempcount;
    switch(control)
    {
        case 0:
        {
            for(i=0;i<11;i++)
            send_byte(disp_table[buffer%10]);
            break;
        }
        case 1:
        {
            tempcount=count;
            for(i=0;i<6;i++)
            {
                temp[i]=tempcount%10;
                tempcount/=10;
            }
            send_byte(disp_table[buffer/10]);
            send_byte(disp_table[buffer%10]);
            send_byte(0x00);
            send_byte(disp_table[0]);
            send_byte(disp_table[0]);
            for(i=0;i<6;i++)
            send_byte(disp_table[temp[5-i]]);
            break;
        }
    }
    DISP_DO=1;
}
main()
{
     unsigned i;
     disp_led(0,0);
     for(i=0;i<10;i++)
     delay10ms(1000);
     initstat();
     //wDS12887();
    //RAM1=5;
    // RAM2=4;
     while(1)
     {
         //delay10ms(500);
         if(DS128870!=count)
         {
             delay10ms(2);
             send_byte(disp_table[RAM1/10]);
             send_byte(disp_table[RAM1%10]);
             send_byte(0);
             send_byte(disp_table[DS128874/10]);
             send_byte(disp_table[DS128874%10]);
             send_byte(0x40);
             send_byte(disp_table[DS128872/10]);
             send_byte(disp_table[DS128872%10]);
             send_byte(0x40);
             send_byte(disp_table[DS128870/10]);
             send_byte(disp_table[DS128870%10]);
             delay10ms(1);
           }
         count=DS128870;


     }
}
3: 上面的太反了,把一些没用的去掉上面的太反了,把一些没用的去掉
#include <reg52.h>
#include <absacc.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define DS128870 XBYTE[0x2000]
#define DS128871 XBYTE[0x2001]
#define DS128872 XBYTE[0x2002]
#define DS128873 XBYTE[0x2003]
#define DS128874 XBYTE[0x2004]
#define DS128875 XBYTE[0x2005]
#define DS128876 XBYTE[0x2006]
#define DS128877 XBYTE[0x2007]
#define DS128878 XBYTE[0x2008]
#define DS128879 XBYTE[0x2009]
#define DS12887A XBYTE[0x200a]
#define DS12887B XBYTE[0x200b]
#define DS12887C XBYTE[0x200c]
#define DS12887D XBYTE[0x200d]
#define RAM1 XBYTE[0x0050]  
#define RAM2 XBYTE[0x0051]



void initstat (void) //初始12887     
{
     DS12887B=0x16;
     DS12887A=0xa0;
}

void wDS12887(void)  //设置12887时间
{
     int i;
     DS12887B=0x96;
     DS128870=30;
     DS128872=21;
     DS128874=8;
     DS128871=0xff;DS128873=0xff;DS128875=0xff;
     DS128877=0x15;DS128878=0x02;DS128879=0x4;
     DS12887B=0x16;
}

/***************延时************************/
void delay10ms(unsigned char time)
{
    unsigned char i;
    unsigned int j;
    for (i=0;i<time;i++)
    {
        for(j=0;j<0x10;j++)
        {

        }
        }
}


main()
{
     initstat();
     //wDS12887();
    //RAM1=5;
    // RAM2=4;
     while(1)      //下面是显示出时间的程序
     {
         delay10ms(500);
         if(DS128870!=count)
         {
             delay10ms(2);
             send_byte(disp_table[RAM1/10]);   
             send_byte(disp_table[RAM1%10]);
             send_byte(0);
             send_byte(disp_table[DS128874/10]);//直接显示12887时间
             send_byte(disp_table[DS128874%10]);
             send_byte(0x40);
             send_byte(disp_table[DS128872/10]);
             send_byte(disp_table[DS128872%10]);
             send_byte(0x40);
             send_byte(disp_table[DS128870/10]);
             send_byte(disp_table[DS128870%10]);
             delay10ms(1);
           }
         count=DS128870;


     }
}
4: 你要确定好时序呀首先你要确定总线,硬件连接来选择
网上有经典程序,你最好看一下,直接就能用

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]