计时使用非易失性内存和微控制器-Using a Nonvol

abstract: this application note describes how to use a nonvolatile timekeeping ram with an 8051-type microcontroller. an example schematic is provided. source code provides an example of how to read and write the real-time clock (rtc) registers.
introductionthe nonvolatile timekeeping family of real-time clock (rtc) products provide battery-backed nv sram as well as time and date. the clock registers are accessed identically to the sram. table 1 shows a list of products in the nonvolatile timekeeping family. the ds174_ series are identical to the ds164_, with the addition of a century bit and optional 3.3v operation.
table 1. nonvolatile timekeeping products part ram density vcc (v)
ds1642 2k × 8 5
ds1643 8k × 8 5
ds1644 32k × 8 5
ds1646 128k × 8 5
ds1647 512k × 8 5
ds1742 2k × 8 3.3 or 5
ds1743 8k × 8 3.3 or 5
ds1744 32k × 8 3.3 or 5
ds1746 128k × 8 3.3 or 5
ds1747 512k × 8 3.3 or 5
pin configurations
in the following example, a ds1644 or ds1646 is connected to a ds87c320. the ds87c320 high-speed microcontroller is compatible with the industry-standard 8051 architecture. other nv ram densities could be supported with appropriate changes to the circuit. for related application notes, please refer to the quick view data sheets for the ds87c320 and ds1644. a reference rtc clock shematic follows the code.
ds1644/ds1646 code/**********************************************************************/ /* ds1644.c - access ds1644/6, ds1744/6 using reference rtc circuit */ /* this program if for example only and is not supported by dallas */ /* semiconductor maxim. */ /**********************************************************************/ #include /* prototypes for i/o functions */ #include /* register declarations for ds5000 */ #include /* needed to define xdata addresses */ #include /************************* bit definitions ****************************/ /***************************** defines ********************************/ /************************* global variables ***************************/ uchar yr, mn, dt, dy, hr, min, sec, day; unsigned int maxadd; sbit rstb = p2^7; sbit irqb = p2^6; sbit ad16 = p1^5; sbit ad17 = p1^6; sbit ad18 = p1^7; /*********************** function prototypes **************************/ void writereg(); void init_rtc(); void disp_clk_regs(); void ramread(); void ramwrite(); void toggle_ft(); void init_rtc() /* ------------ set the time and date ----------------- */ /* note: no error checking is done on the user entries! */ { uchar tmp; printf(\nenter the year (0-99): ); scanf(%bx, &yr); printf(enter the month (1-12): ); scanf(%bx, &mn); printf(enter the date (1-31): ); scanf(%bx, &dt); printf(enter the day (1-7): ); scanf(%bx, &dy); printf(enter the hour (1-23): ); scanf(%bx, &hr); printf(enter the minute (0-59): ); scanf(%bx, &min); printf(enter the second (0-59): ); scanf(%bx, &sec); ad16 = ad17 = ad18 = 1; xbyte[0xfff8] = 0x80; /* set write bit for write */ xbyte[0xfff9] = sec; xbyte[0xfffa] = min; xbyte[0xfffb] = hr; xbyte[0xfffc] = dy; xbyte[0xfffd] = dt; xbyte[0xfffe] = mn; xbyte[0xffff] = yr; xbyte[0xfff8] = 0; /* clear write bit to allow update */ } void disp_clk_regs() /* ----------------------------------------- */ { uchar msec, sec, prv_sec = 99, min, hrs, dte, mon, day, yr; ad16 = ad17 = ad18 = 1; printf(\nyr mn dt dy hr:mn:sec); while(!ri) /* read & display clock registers */ { xbyte[0xfff8] = 0x40; /* set read bit to stop updates */ sec = xbyte[0xfff9]; min = xbyte[0xfffa]; hrs = xbyte[0xfffb]; day = xbyte[0xfffc]; dte = xbyte[0xfffd]; mon = xbyte[0xfffe]; yr = xbyte[0xffff]; xbyte[0xfff8] = 0; /* clear read bit to resume updates */ delay(3); /* must allow time for transfer to occur */ if(sec != prv_sec) /* display every time seconds change */ { printf(\n%02.bx %02.bx %02.bx %02.bx, yr, mon, dte, day); printf( %02.bx:%02.bx:%02.bx, hrs, min, sec); } prv_sec = sec; } ri = 0; /* swallow keypress to exit loop */ } void ramread() /* ------------ read ram ------------- */ { unsigned int j; ad16 = ad17 = ad18 = 0; for (j = 0; j <= maxadd; j++) { if(j != 0 && !(j % 256) ) { printf(\npress a key or esc to exit ); if( _getkey() == 0x1b) return; } if(!(j % 16)) printf(\n%bx%04x , (uchar) ad16, j); printf(%02.bx , (uchar) xbyte[j]); if (j == 0xffff) break; } if(maxadd == 0xffff) { printf(\npress a key or esc to exit ); if( _getkey() == 0x1b) return; ad16 = 1; for (j = 0; j <= maxadd; j++) if(j != 0 && !(j % 256) ) { printf(\npress a key or esc to exit ); if( _getkey() == 0x1b) break; } if(!(j % 16)) printf(\n%bx%04x , (uchar) ad16, j); printf(%02.bx , (uchar) xbyte[j]); if (j == 0xffff) break; } } } void ramwrite() /* ------------- write with incrementing data ------------- */ { unsigned int j; uchar offset = 0; if(maxadd == 0xffff) { ad16 = ad17 = ad18 = 0; for (j = 0; j <= maxadd; j++) { xbyte[j] = (uchar) ( (j & 0xff) + offset); if( (j & 0xff) == 0xff) offset++; if(j == 0xffff) break; } } ad16 = 1; offset = 0; for (j = 0; j < (maxadd - 7); j++) { xbyte[j] = (uchar) ( (j & 0xff) + offset); if( (j & 0xff) == 0xff) offset++; } } void ramfill(uchar dat) /* ------------- fill with fixed data ------------- */ { unsigned int j; if(maxadd == 0xffff) { ad16 = ad17 = ad18 = 0; for (j = 0; j <= maxadd; j++) { if(j & 0x100) xbyte[j] = dat ^ 0xff; else xbyte[j] = dat; if(j == 0xffff) break; } } ad16 = 1; for (j = 0; j < (maxadd - 7); j++) /* don't disturb time & date */ { if(j & 0x100) xbyte[j] = dat ^ 0xff; else xbyte[j] = dat; } } void toggle_ft() /* -------- toggle the frequency test bit --------- */ { uchar creg; ad16=1; creg = xbyte[0xfffc]; if( (creg & 0x40) ) /* check ft bit */ { xbyte[0xfff8] = 0x80; /* set write bit for write */ xbyte[0xfffc] = (creg & 0xbf); /* clear ft bit */ xbyte[0xfff8] = 0; /* clear write bit */ } else { xbyte[0xfff8] = 0x80; /* set write bit for write */ xbyte[0xfffc] = (creg | 0x40); /* set ft bit */ xbyte[0xfff8] = 0; /* clear write bit */ } } main (void) /* ----------------------------------------------------- */ { uchar i, m, m1; rstb = 1; printf(\n1) ds1644 or 2) ds1646 ? ); i = _getkey(); if (i == '1') maxadd = 0x7fff; if (i == '2') maxadd = 0xffff; while (1) { printf(\nds1644/6 build 100\n); printf(ci init clock cr read time\n); printf(r ram fill rr ram read\n); printf(t toggle ft); printf(\nenter menu selection:); m = _getkey(); switch(m) { case 'c': case 'c': printf(\renter clock routine to run: c); m1 = _getkey(); switch(m1) { case 'i': case 'i': init_rtc(); break; case 'r': case 'r': disp_clk_regs(); break; } break; case 'r': case 'r': printf(\rfill ram a)a, 5)5, i)nc data or r)ead: ); m1 = _getkey(); switch(m1) { case '5': ramfill(0x55); break; case 'a': case 'a': ramfill(0xaa); break; case 'r': case 'r': ramread(); break; case 'i': case 'i': ramwrite(); break; } break; case 't': case 't': toggle_ft(); break; } } }
more detailed image
more detailed image

ClassB放大器的基本概念
马斯克的人体实验被FDA拒了!Neuralink大脑植入计划再推迟
无铅焊的介绍
fpga在通信方面的应用_怎么用FPGA做算法
上汽大众插混“双雄”来了 驾驶品质得到了显著的提升
计时使用非易失性内存和微控制器-Using a Nonvol
薄膜质量在线检测系统的工作原理是怎样的
图扑软件携手华为云再创合作共赢新局面
Fitbit推出两款防水健身追踪器 外观设计大改变
压力传感器的误差分析
火花塞参数大全与使用
Unit 24:2020年物联网威胁报告
磁悬浮列车是怎么转向变道的
机器人助力垃圾处理新技术 推动环保事业新发展
亮亮视野AR智能维修系统助力北京地铁高效运营
世界首台±1100千伏换流变压器到达±1100千伏昌吉换流站
万向A123进阶“协奏曲” 万向快速成长背后的原因是什么?
三大运营商营收净利双降,积极布局物联网等新业务
5G对对LNA性能的要求及解决方案
三大因素齐发力,国产半导体设备迎发展良机