Timing using non-volatile memory and microcontroller-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 ("Enter 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 ("Yr 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 ("% 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 ("Press a key or Esc to exit") ; if (_getkey () == 0x1b) return;} if (! (j% 16)) printf ("% bx% 04x", (uchar) AD16, j); printf ("% 02.bx", (uchar ) XBYTE [j]); if (j == 0xffff) break;} if (MAXADD == 0xffff) {printf ("Press a key or Esc to exit"); if (_getkey () == 0x1b) return; AD16 = 1; for (j = 0; j <= MAXADD; j ++) if (j! = 0 &&! (J% 256)) {printf ("Press a key or Esc to exit"); if (_getkey () = = 0x1b) break;} if (! (J% 16)) printf ("% 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 ("1) DS1644 or 2) DS1646?"); i = _getkey (); if (i == '1') MAXADD = 0x7FFF; if (i == '2') MAXADD = 0xFFFF; while (1) {printf ("DS1644 / 6 build 100"); printf ("CI Init clock CR Read Time"); printf ("R RAM Fill RR RAM Read "); printf (" T Toggle FT "); printf (" Enter Menu Selection: "); M = _getkey (); switch (M) {case 'C': case 'c': printf (" Enter 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 ("Fill 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

Rotary Switches

Rotary Switches

The Rotary Switches, different with Key Switches, Metal Switches, Toggle Switches and Automotive Switches, is mainly installed on liquid and gas pipelines to regulate the flow and pressure of liquids and gases. When used, turn the handle to drive the adjusting nut to rotate, and connect the left-hand thread of the valve through the left-hand thread. Drive the valve to move right or left to change the cross-sectional area of the right hole passage in the valve body cavity, so as to adjust the liquid and gas in the upper outlet pipe.


Rotary Switches


The Electrical Rotary Switch is a switch that controls the opening and closing of the main contact by rotating the handle.There are two types of rotary switches, namely a unipolar unit structure and a multi-pole multi-position structure. Unipolar unit rotary switches are often used in conjunction with rotary potentiometers in applications, while multi-pole multi-position rotary switches are often used for switching of operating line.

Multi Position Rotary Switch, because of its use, the overall use of sealed structure, there is a certain degree of waterproof effect, the basic can reach the IP67 waterproof level.At the same time need to use a more rigid and durable metal material, there are two or three files in the gear difference.


Electrical Rotary Switch

Rotary Switches,Rotary Switch 4 Position,Rotary Switch Types,Rotary Potentiometer Switch

YESWITCH ELECTRONICS CO., LTD. , https://www.yeswitches.com

Posted on