1 / 18

System Programming

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.

willis
Télécharger la présentation

System Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Status Register A 7 6 5 4 3 2 1 0 Interrupt frequency Time frequency 0 = Time is not updated 1 = Time is updated

  3. 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

  4. Status Register C 7 6 5 4 3 2 1 0 1 = Time update complete 1 = Alarm time reached 1 = Periodic interrupt call

  5. Status Register D 7 6 5 4 3 2 1 0 0 = Battery Died

  6. // 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;

  7. 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();}

  8. //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);

  9. 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();

  10. 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();}

  11. // 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;

  12. 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);

  13. 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");}

  14. // 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;

  15. 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);

  16. 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);

  17. 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;

  18. 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();}

More Related