abstract: this application note shows an example of how to interface a phantom real-time clock (rtc) to a microcontroller. this note includes a schematic and example code.
pin assignment
descriptionthe phantom clocks and smartwatch sockets provide battery-backed nv sram or nv sram control, respectively, and add timekeeping information. the timekeeping data is accessed without using any of the sram data space. access of the timekeeping data is accomplished by writing a unique 64-bit sequence to the controller. the controller then inhibits access to the sram for the next 64 reads or writes. in this example, a ds1216c, ds1216e, ds1243y, or ds1244y is connected to a ds2250. the ds2250 microcontroller is compatible with the industry standard 8051 architecture. larger densities could be supported by using bank-switching techniques. some memory expansion techniques are discussed in application note 81, memory expansion with the high-speed microcontroller family.
a smartwatch/phantom clock schematic of the circuit is shown in figure 1. software is shown in ds1216/ds1244 code.
more detailed image
figure 1. smartwatch/phantom clock schematic of the circuit.
ds1216/ds1244 code/************************************************************************/
/* ds1216an.c - access ds1216 or ds1244 using phantomdemo circuit */
/************************************************************************/
/* for smartwatch/rom sockets, input d (input) is connected to a0, */
/* the q (output) is connected to d7 (data bit 7 of the data bus) and */
/* /we connected to a2. on the smartwatch/ram sockets, dq is connected */
/* to d0, and /we is connected to /wr. for both, /oe is connected to */
/* /rd and /ce is connected to a15. access requires use of xbyte */
/* function. all other sram/rom address and data pins are connected to */
/* their respective processor pins. the example is intended to show */
/* how to access the clock only. not all memory configurations will */
/* work with this setup. note that smartwatch sockets must be mapped */
/* to data, not program memory space. program memory fetches would */
/* interrupt the access protocol sequence. if /rst is connected to an */
/* address, the /rst bit must always be written to a 1. otherwise, */
/* access to the clock will be lost. this program is for example only */
/* is not supported by dallas semiconductor maxim */
/************************************************************************/
#include /* prototypes for i/o functions */
#include /* register declarations for ds5000 */
#include /* needed to define xdata addresses */
/************************* bit definitions ******************************/
/***************************** defines **********************************/
/************************* global variables *****************************/
uchar mode = 0, yr = 0x01, mn=0x03, dt=0x30, dy=0x26, hr=0x14, min=0x15, sec=0x16;
#define rdaddr xbyte[0x0000] /* i/o is on d0 for smartwatch/ram */
#define wraddr xbyte[0x0000]
#define rdaddrrom xbyte[0x0004] /* /we is on a2 for smartwatch/rom */
#define wr1addr xbyte[0x0001] /* d (data input) on a0 for /rom */
#define wr0addr xbyte[0x0000]
/*********************** function prototypes ****************************/
void ds1216_wr();
void ds1216_rd();
void test();
void ds1216_close();
void ds1216_open();
void entry();
uchar rbyte();
void wbyte(uchar);
void ds1216_open() /* ----- send open protocol to rtc on 1216 ------- */
{
uchar a = 0xc5, inc;
ds1216_close();
for(inc = 0; inc > 4) | (a << 4); /* generate next pattern byte */
} /* repeat until 8 bytes sent */
}
void ds1216_close() /* ----- make sure clock is not in access mode ----- */
{
uchar i; /* read from the part at least 64 times to make sure */
for (i=0; i<9; i++) /* the clock is not being accessed */
{
rbyte();
}
}
uchar rbyte() /* ------ read one byte from the clock and return ------- */
{
uchar savbyte = 0, getbyte;
uchar i;
for (i = 0; i < 8; i++)
{
if(mode) /* rom: /we is on a2, and must be high to read */
{
getbyte = rdaddrrom & 1; /* data bit output (q) is in d0 */
}
else /* ram: /we is on /wr (ds5000) */
{
getbyte = rdaddr & 1; /* dq is d0 */
}
getbyte <= 1;
}
else /* ram: /we and /ce toggle low to write */
{
wraddr = (dat & 1); /* write dq0 */
dat >>= 1;
}
}
}
void ds1216_rd() /* -------- read rtc on 1216 ---------- */
{
int inc;
ds1216_close(); /* make sure rtc is not already in access mode */
ds1216_open(); /* now send the protocol to open the rtc */
printf(\n);
for(inc = 0; inc < 8; inc++)
{
printf(%bx , rbyte());
}
printf(\n);
}
void ds1216_wr() /* -------- write time/date info to 1216 rtc ------ */
{
ds1216_close(); /* make sure rtc is not already in access mode */
ds1216_open(); /* now send the protocol to open the rtc */
wbyte(0); /* 100th seconds */
wbyte(sec); /* seconds */
wbyte(min); /* minutes */
wbyte(hr); /* hrs */
wbyte(dy); /* day */
wbyte(dt); /* date */
wbyte(mn); /* month */
wbyte(yr); /* year */
}
void entry() /* -------- time/date info to load into the clock ------- */
{
printf(\nenter the year (0-99): );
scanf(%bx, &yr);
printf(\nenter the month (1-12): );
scanf(%bx, &mn);
printf(\nenter the date (1-31): );
scanf(%bx, &dt);
printf(\nenter the day (1-7): );
scanf(%bx, &dy);
dy = dy | 0x10; /* make sure _rst bit is high */
printf(\nenter the hour (1-24): );
scanf(%bx, &hr);
/* hr = hr & 0x3f; /* force clock to 24 hour mode */
printf(\nenter the minute (0-59): );
scanf(%bx, &min);
printf(\nenter the second (0-59): );
scanf(%bx, &sec);
}
void test() /* ------- loop read and display once per second ------- */
{
int prv_sec = 0x99, inc;
while(!ri) /* read & display clock registers */
{
ds1216_close();
ds1216_open();
rbyte(); /* throw away fractional seconds */
sec = rbyte(); /* get the time from rtc on ds2250t */
min = rbyte();
hr = rbyte();
dy = rbyte();
dt = rbyte();
mn = rbyte();
yr = rbyte();
if(sec != prv_sec) /* display every time seconds change */
{
printf(\n yr mon dte day hr:mn:sec);
printf(\n %02.bx %02.bx %02.bx %02.bx, yr, mn, dt, dy);
printf( %02.bx:%02.bx:%02.bx, hr, min, sec);
}
prv_sec = sec;
}
ri = 0; /* swallow keypress to exit loop */
int main(void) /*-------------------------------------------------------*/
{
uchar m;
/* on entry, the clock could be open for access. this could happen if power
goes away right after the 64-bit pattern match is complete. on power
up, the next 64 bits would be directed to the clock instead of ram.
to keep from writing garbage to the clock, the first 64 ram accesses
should be reads. */
ds1216_close(); /* make sure that we are not already in the clock */
while(1)
{
printf(ds1216 demo build 109 mode = );
if(mode)
printf(rom);
else
printf(ram);
printf(\n(t)oggle ram/rom mode (i)nit clock (r)ead clock (l)oop
read);
printf(\n:);
m = _getkey();
printf(%c,m);
switch(m)
{
case 'i':
case 'i': entry(); ds1216_wr(); break;
case 'l':
case 'l': test(); break;
case 'r':
case 'r': ds1216_rd(); break;
case 't':
case 't': printf(\n1=rom, 0=ram: );
scanf(%bx, &mode); break;
}
}
}
aigo国民好物固态硬盘P3000 高性价比的国货分享
射频通信、电磁波等无线基础知识科普
调研:65%不推荐选AI专业,推荐仅占35%
Elektron将客户定制设计和咨询服务引入中国
岩土工程中振弦类采集仪的完整解决方案案例
使用SmartWatch /幻影时钟与微控制器-Using
中科驭数正式加入北京金融科技产业联盟
理论与现实,机器人“活着”比你想象要困难
为谷歌代工Pixel本是华为:无奈谈崩了
如何实现建机装备接入基于Modbus的传感信号
工地扬尘在线监测系统是如何测量颗粒物浓度的
Redmi K30 5G正式发布 售价1999元起
云化网络如何利用人工智能变得更加智能化
CAN总线的同步有何奥秘
禾赛宣布获得哪吒汽车新车型激光雷达量产定点
生物敏感器件,生物敏感器件结构原理是什么?
我的眼里只有你——-虹膜酷客测评体验
生成对抗网络与其他生成模型之间的权衡取舍是什么?
LiDAR传感器自动驾驶技术正朝我们走得越来越近
骨灰级音响发烧友如何打造随身DAC兼耳扩?