Reading and Setting the Date and Alarm using BIOS in DOS, Study notes of System Programming

Code examples for reading and setting the date and alarm using bios functions in dos. The first example reads the current date and displays it on the screen. The second example takes user input for the new date and sets it using the bios service 1ah/0ah. The third example sets the alarm using the bios function 1ah/06h and intercepts the interrupt 4ah to display a character 'a' on the screen. The fourth example sets the alarm by taking user input for the hours, minutes, and seconds and writing the bcd values to the rtc.

Typology: Study notes

2011/2012

Uploaded on 08/07/2012

anishay
anishay 🇮🇳

4.2

(25)

118 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture # 19
Reading the Date
#include <bios.h>
#include <dos.h>
void main ()
{unsigned int cen,yrs,mons,days;
_AH =4;
geninterrupt(0x1a);
cen=_CH;
yrs=_CL;
mons=_DH;
days=_DL;
cen = cen <<4;
*((unsigned char *)(&cen)) =
(*((unsigned char *)(&cen))) >>4;
cen = cen + 0x3030;
mons = mons <<4;
*((unsigned char *)(&mons)) =
(*((unsigned char *)(&mons))) >>4;
mons = mons + 0x3030;
yrs = yrs <<4;
*((unsigned char *)(&yrs)) =
(*((unsigned char *)(&yrs))) >>4;
yrs = yrs + 0x3030;
days = days <<4;
*((unsigned char *)(&days)) =
(*((unsigned char *)(&days))) >>4;
days = days + 0x3030;
clrscr();
docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Reading and Setting the Date and Alarm using BIOS in DOS and more Study notes System Programming in PDF only on Docsity!

Lecture # 19

Reading the Date

#include <bios.h> #include <dos.h> void main () { unsigned int cen,yrs,mons,days; _AH =4; geninterrupt(0x1a); cen=_CH; yrs=_CL; mons=_DH; days=_DL; cen = cen <<4; *((unsigned char )(&cen)) = (((unsigned char *)(&cen))) >>4; cen = cen + 0x3030;

mons = mons <<4; *((unsigned char )(&mons)) = (((unsigned char *)(&mons))) >>4; mons = mons + 0x3030;

yrs = yrs <<4; *((unsigned char )(&yrs)) = (((unsigned char *)(&yrs))) >>4; yrs = yrs + 0x3030;

days = days <<4; *((unsigned char )(&days)) = (((unsigned char *)(&days))) >>4; days = days + 0x3030;

clrscr();

printf("%c%c-%c%c-%c%c%c%c", (((unsigned char)(&days))+1), ((unsigned char)(&days)), (((unsigned char)(&mons))+1), ((unsigned char)(&mons)), (((unsigned char)(&cen))+1), ((unsigned char)(&cen)), (((unsigned char)(&yrs))+1), ((unsigned char)(&yrs))); getch(); }

Setting the Date

unsigned char ASCIItoBCD(char hi, char lo) { hi = hi - 0x30; lo = lo - 0x30; hi = hi << 4; hi = hi | lo; return hi; } void main () { unsigned char yrs,mons,days,cen; char ch1, ch2; puts("\nEnter the century to update: "); ch1=getche(); ch2=getche(); cen = ASCIItoBCD(ch1, ch2);

Another way to set Alarm

#include <bios.h> #include <dos.h> void interrupt newint70(); void interrupt (*oldint70)(); unsigned int far *scr = (unsigned int far *)0xb8000000; unsigned char ASCIItoBCD(char hi, char lo) { hi = hi - 0x30; lo = lo - 0x30; hi = hi << 4; hi = hi | lo; return hi; }

void main (void) { int temp; 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);

outportb(0x70,1); outportb(0x71,secs); outportb(0x70,3);

outportb(0x71,mins); outportb(0x70,5);

outportb(0x71,hrs); outportb(0x70,0x0b);

temp = inport(0x71); temp = temp | 0x70; outportb(0x70,0x0b); outportb(0x71,temp);

oldint70 = getvect(0x70); setvect(0x70, newint70); keep(0,1000); } void interrupt newint70() { outportb(0x70,0x0c); if (( inport(0x71) & 0x20) == 0x20) sound(0x21ff); scr=0x7041; (oldint70)(); }

This program takes the time of alarm as ASCII input which is firstly converted into BCD.

This BCD time is placed in the 64 byte RAM at the bytes which hold the alarm time.

Once the alarm time is loaded the register is accessed to enable the interrupts such that

other bits are not disturbed. Whenever the RTC generates an interrupt, the reason of the

interrupt needs to be established. This can be done by checking the value of status

register C, if the 5

th

bit of register C is set it indicates that the interrupt was generated

because the alarm time has been reached. The reason of interrupt generation is

established in the function newint70(). If the interrupt was generated because of alarm

then speaker is turned on by the sound() function and a character ‘A’ is displayed on the

upper left corner of the screen.

Determining Systems Information

INT 11H

INT 12H

INT 11H

used to get hardware environment info.

On Entry

call 11H

On Exit

AX = System Info.

Determining Systems Information

Interrupt 11H is used to determine the systems information. On return this service returns

the systems info in AX register. The detail of the information in AX register is shown in

the slide above.