/* RTC_TST.C * * Dallas Real-Time Clock Example Program * * This program requires that the RUN.EXE firmware be installed. * */ #include #include main() { union REGS inregs, outregs; int month,date,yr,hr,min,sec, n; printf("Set time? (y/n): "); if(toupper(getch()) == 'Y') { printf("\nEnter date (mm/dd/yyyy): "); scanf("%x/%x/%x", &month, &date, &yr); inregs.h.ah = 5; /* Function 05h (set date) */ inregs.x.cx = yr; /* set year */ inregs.h.dh = (unsigned char) month; /* set month */ inregs.h.dl = (unsigned char) date; /* set date */ int86(0x1A, &inregs, &outregs); printf("\n\nEnter time (hh:mm:ss): "); scanf("%x:%x:%x", &hr,&min,&sec); inregs.h.ah = 3; /* Function 03h (set time)*/ inregs.h.ch = (unsigned char) hr; /* set hours */ inregs.h.cl = (unsigned char) min; /* set minutes */ inregs.h.dh = (unsigned char) sec; /* set seconds */ int86(0x1A, &inregs, &outregs); } printf("\n\nCurrent time\n"); for(;;) { inregs.h.ah =2; /* read time */ int86(0x1A, &inregs, &outregs); printf("time=%02x:%02x:%02x ", outregs.h.ch, outregs.h.cl, outregs.h.dh); inregs.h.ah =4; /* read date */ int86(0x1A, &inregs, &outregs); printf("date=%02x/%02x/%02x%02x\r", outregs.h.dh, outregs.h.dl, outregs.h.ch, outregs.h.cl); if (kbhit()) break; for (n=0; n<0x1000; n++); } getch(); }