共2条
1/1 1 跳转至页
DS12887 DS12887的问题
问
最近用到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³õʼ»¯ */
/*******************************************************************/
void initstat (void) /*12887³õʼ»¯*/
{
DS12887B=0x16;//Í£Ö¹¸üУ¬Ñ¡BCDÂ룬24СʱÖÆ
DS12887A=0xa0;//´ò¿ª¾§Õñ²¢ÔÊÐíRTC¼Æʱ
}
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;//ÿÃë¼Æʱ×ßÒ»´Î£¬24СʱÖÆ
}
/***************Ò»¸ö10msÑÓʱ³ÌÐò************************/
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: 你要确定好时序呀首先你要确定总线,硬件连接来选择
网上有经典程序,你最好看一下,直接就能用
我只需读时间就行了,不需要里面的任何中断。谢谢! 答 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³õʼ»¯ */
/*******************************************************************/
void initstat (void) /*12887³õʼ»¯*/
{
DS12887B=0x16;//Í£Ö¹¸üУ¬Ñ¡BCDÂ룬24СʱÖÆ
DS12887A=0xa0;//´ò¿ª¾§Õñ²¢ÔÊÐíRTC¼Æʱ
}
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;//ÿÃë¼Æʱ×ßÒ»´Î£¬24СʱÖÆ
}
/***************Ò»¸ö10msÑÓʱ³ÌÐò************************/
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 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图四被打赏50分 | |
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 |