Tutorial Microcontroller MCS-51 ATMEL ISP

Microcontroller Kits
Programmer and Target 89s51

Simple Mikrokontroller 89s51 Trainer


Standart
Mikrokontroller 89s51 Trainer


Super Mikrokontroller Trainer 89s51

+

All Item Include

Programmer
Via USB

 

 

BACK

Micro-C Library Extension for DS1202 Real-time Clock
W. Sirichote

 

An 8-pin RTC chip, DS1202 provides an accurate digital clock for real-time applications. Example circuit shown above requires 3-pin for interfacing with 8051 chip, P1.3, P1.4 and P1.5. For the DS1202 chip, backup supply, +V requires a signal diode, say 1N914 to switch between normal supply and +3V lithium battery. Newer version DS1302 has an internal switching diode, +3V battery supply can then be connected directly. My friend, Santi Hankla, wrote me the library extension for DS1202, DS1202.ASM. The library extension is used with Micro-C Compiler written in Assembly. To use the extension, you have to add the name and label of the DS1202.ASM in the TINY.LIB. He also provides me the example C program, REALTIME.C, sending real-time clock to terminal every second.

 

/*
DS1202/1302 RTC example program
send reading every 1000 ms
original source program was written by S.HANKRA
require DS1202 Library:
wrds1202(int) write data to DS1202
char rdds1202(char) read data from DS1202
/RST P1.3
I/O P1.4
SCLK P1.5
*/

#include c:\mc\8051io.h
#include c:\mc\8051reg.h


#define rdsec 0x81
#define rdmin 0x83
#define rdhour 0x85
#define rddate 0x87
#define rdmonth 0x89
#define rdyear 0x8d
#define secu 0x8e
#define wrdate 0x86
#define wrmonth 0x88
#define wryear 0x8c
#define wrhour 0x84
#define wrmin 0x82
#define wrsec 0x80
#define unlock 0
#define lock 0x80
/* ---------------------------------------------------- */
writertc(a,b)
char a,b;
{
int i;
i = a;
i <<= 8;
i |= b;
wrds1202(i);
}
/* ------------------------------------------------------- */
printdate()
{
printf("%02x/%02x/%02x\n",rdds1202(rddate),
rdds1202(rdmonth),rdds1202(rdyear));
}
/* ----------------------------------------------------------- */
printtime()
{
printf("%02x:%02x:%02x\n",rdds1202(rdhour),
rdds1202(rdmin),rdds1202(rdsec));
}
/* ----------------------------------------------------------- */
setdate()
{
writertc(secu,unlock);
writertc(wrdate,0x08);
writertc(wrmonth,0x12);
writertc(wryear,0x99);
writertc(secu,lock);
}
/* ----------------------------------------------------------- */
settime()
{
writertc(secu,unlock);
writertc(wrhour,0x12);
writertc(wrmin,0);
writertc(wrsec,0);
writertc(secu,lock);
}
/* ----------------------------------------------------------- */

main()
{
setdate();
settime();
serinit(9600);
while(1){
printdate();
printtime();
delay(1000);
}
}

);
while(1){
printdate();
printtime();
delay(1000);
}
}

Comments, questions and discussion about this topic

BACK