180 likes | 265 Vues
NFC-IET-2011. System Programming. Lecture-17 Real Time Clock Dated: May 31, 2011 By Somia Razzaq Note: Some slides and images of following lecture are taken from VU. Status Register A. 7 6 5 4 3 2 1 0. Interrupt frequency. Time frequency.
E N D
NFC-IET-2011 System Programming Lecture-17 Real Time Clock Dated: May 31, 2011 By Somia Razzaq Note: Some slides and images of following lecture are taken from VU
Status Register A 7 6 5 4 3 2 1 0 Interrupt frequency Time frequency 0 = Time is not updated 1 = Time is updated
Status Register B 7 6 5 4 3 2 1 0 0 = Daylight saving time Update time 24/12 – hour counter 0 = 12 hour format 1 = 24 hour format Call periodic interrupt Call Alarm interrupt Call interrupt on time update Time & date format 0 = BCD 1 = Binary Block generator
Status Register C 7 6 5 4 3 2 1 0 1 = Time update complete 1 = Alarm time reached 1 = Periodic interrupt call
Status Register D 7 6 5 4 3 2 1 0 0 = Battery Died
// Get Time using BIOS servicevoid main (){ unsigned int hours, months, seconds; _AH =2;geninterrupt(0x1a); hours = _CH; minutes = _CL; seconds = _DH; hours = hours <<4; *((unsigned char *)(& hours)) = (*((unsigned char *) (& hours))) >>4; hours = hours + 0x3030; seconds = seconds <<4; *((unsigned char *)(& seconds)) = (*((unsigned char *)(& seconds))) >>4; seconds = seconds + 0x3030;
minutes = minutes <<4; *((unsigned char *)(& minutes)) = (*((unsigned char *)(& minutes))) >>4; minutes = minutes + 0x3030; clrscr(); printf("%c%c-%c%c-%c%c%c%c", *(((unsigned char*)(&hours))+1), *((unsigned char*)(&hours)), *(((unsigned char*)(&minutes))+1), *((unsigned char*)(&minutes)), *(((unsigned char*)(&seconds))+1), *((unsigned char*)(&seconds)), getch();}
//Get Time using RTC Registers (direct I/O)#include <bios.h>#include <dos.h>void main (){inthrs,mins,secs; char temp; do {outportb(0x70,0x0a); temp=inportb(0x71); }while ((temp & 0x80) == 0);outportb(0x70,0);secs=inport(0x71);outportb(0x70,2);mins=inport(0x71);outportb(0x70,4); hrs=inport(0x71);
hrs = hrs <<4; *((unsigned char *)(&hrs)) = (*((unsigned char *)(&hrs))) >>4; hrs = hrs + 0x3030; mins = mins <<4; *((unsigned char *)(&mins)) = (*((unsigned char *)(&mins))) >>4; mins = mins + 0x3030; secs = secs <<4; *((unsigned char *)(&secs)) = (*((unsigned char *)(&secs))) >>4; secs = secs + 0x3030; clrscr();
printf("%c%c:%c%c:%c%c", *(((unsigned char*)(&hrs))+1), *((unsigned char*)(&hrs)), *(((unsigned char*)(&mins))+1), *((unsigned char*)(&mins)), *(((unsigned char*)(&secs))+1), *((unsigned char*)(&secs))); getch();}
// Set Time using BIOS service#include <bios.h>#include <dos.h>unsigned char ASCIItoBCD(char hi, char lo){ hi = hi - 0x30; lo = lo - 0x30; hi = hi << 4; hi = hi | lo; return hi;}unsigned long int far *tm = (unsigned long int far *)0x0040006c;
void main (){ unsigned char hrs,mins,secs; char ch1, ch2; puts("\nEnter the hours to update: "); ch1=getche(); ch2=getch(); hrs = ASCIItoBCD(ch1, ch2); puts("\nEnter the minutes to update: "); ch1=getche(); ch2=getch(); mins = ASCIItoBCD(ch1, ch2);
puts("\nEnter the seconds to update: "); ch1=getche(); ch2=getch();secs = ASCIItoBCD(ch1, ch2); *tm = 0; _CH = hrs; _CL=mins; _DH= secs; _DL=0; _AH =3;geninterrupt(0x1a); puts("Time Updated");}
// Set Time using RTC Registers (direct I/O)#include <bios.h>#include <dos.h>unsigned char ASCIItoBCD (unsigned char hi, unsigned char lo){ hi = hi - 0x30; lo = lo - 0x30; hi = hi << 4; hi = hi | lo; return hi;}void main (){ unsigned inthrs,mins,secs; char ch1, ch2;int temp;
puts("\nEnter the hours to update: "); ch1=getche(); ch2=getche(); hrs = ASCIItoBCD(ch1, ch2); puts("\nEnter the minutes to update: "); ch1=getche(); ch2=getche();mins = ASCIItoBCD(ch1, ch2); puts("\nEnter the seconds to update: "); ch1=getche(); ch2=getche();secs = ASCIItoBCD(ch1, ch2);outportb(0x70,0x0b); //To stop the clock use staus register B msb temp = inport(0x71);
temp = temp | 0x80;outportb(0x70,0x0b);outportb(0x71,temp); outport (0x70,0);outport (0x71,secs);outport (0x70,2);outport (0x71,mins);outport (0x70,4);outport (0x71,hrs);outportb(0x70,0x0b); temp = inport(0x71); temp = temp & 0x7f;outportb(0x70,0x0b);outportb(0x71,temp);
delay (30000); //milli seconds do {outportb(0x70,0x0a); temp=inportb(0x71); }while ((temp & 0x80) == 0); outportb(0x70,0);secs=inport(0x71);outportb(0x70,2);mins=inport(0x71);outportb(0x70,4); hrs=inport(0x71); hrs = hrs <<4; *((unsigned char *)(&hrs)) = (*((unsigned char *)(&hrs))) >>4; hrs = hrs + 0x3030;
mins = mins <<4; *((unsigned char *)(&mins)) = (*((unsigned char *)(&mins))) >>4;mins = mins + 0x3030; secs = secs <<4; *((unsigned char *)(&secs)) = (*((unsigned char *)(&secs))) >>4;secs = secs + 0x3030;printf("\nUpdated time is = %c%c:%c%c:%c%c", *(((unsigned char*)(&hrs))+1), *((unsigned char*)(&hrs)), *(((unsigned char*)(&mins))+1), *((unsigned char*)(&mins)), *(((unsigned char*)(&secs))+1), *((unsigned char*)(&secs)));getch();}