100% found this document useful (1 vote)
100 views9 pages

Lecture # 19: System Programming Course Code: CS609 Cs609@vu - Edu.pk

The document discusses several methods for reading and setting the system date and time on DOS systems using BIOS interrupts. It explains how to read the current date by calling interrupt 0x1A/04h and how to set the date by calling interrupt 0x1A/05h. It also discusses two methods for setting alarms - by calling interrupt 0x1A/06h and directly writing to the RTC registers. The document provides sample code demonstrating how to get user input for the date/time values, convert them to BCD format, and set the date, time or alarm values.

Uploaded by

api-3812413
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
100 views9 pages

Lecture # 19: System Programming Course Code: CS609 Cs609@vu - Edu.pk

The document discusses several methods for reading and setting the system date and time on DOS systems using BIOS interrupts. It explains how to read the current date by calling interrupt 0x1A/04h and how to set the date by calling interrupt 0x1A/05h. It also discusses two methods for setting alarms - by calling interrupt 0x1A/06h and directly writing to the RTC registers. The document provides sample code demonstrating how to get user input for the date/time values, convert them to BCD format, and set the date, time or alarm values.

Uploaded by

api-3812413
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

System Programming Course Code: CS609

[email protected]

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

Virtual University of Pakistan 160


System Programming Course Code: CS609
[email protected]

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

Virtual University of Pakistan 161


System Programming Course Code: CS609
[email protected]

puts("\nEnter the yrs to update: ");


ch1=getche();
ch2=getche();
yrs = ASCIItoBCD(ch1, ch2);
puts("\nEnter the month to update: ");
ch1=getche();
ch2=getche();
mons = ASCIItoBCD(ch1, ch2);
puts("\nEnter the days to update: ");
ch1=getche();
ch2=getche();
days = ASCIItoBCD(ch1, ch2);
_CH = cen;_CL=yrs;_DH= mons;
_DL=days; _AH =5;
geninterrupt(0x1a);
puts("Date Updated");
}

The above sample program takes ASCII input from the user for the new date. After taking
all the date units as input the program sets the new date using the BIOS service 1Ah/05H.

Setting the Alarm

void interrupt (*oldint)();


void interrupt newint();
unsigned int far * scr = (unsigned int far *)0xb8000000;
void main ()
{ oldint = getvect(0x4a);
setvect(0x4a, newint);
_AH=6;
_CH =0x23;
_CL=0x50;
_DH=0;
geninterrupt(0x1a);
keep(0,1000);
}
void interrupt newint()
{ *scr=0x7041;
sound(0x21ff);
}

The alarm can be set using BIOS function 1Ah/06h. Once the alarm is set BIOS will
generate the interrupt 4Ah when the alarm time is reached. The above program intercepts
the interrupt 4Ah such that newint() function is invoked at the time of alarm. The
newint() function will just display a character ‘A’ on the upper left corner of the screen.
But this program may not work in the presence of DOS or Windows drivers.

Virtual University of Pakistan 162


System Programming Course Code: CS609
[email protected]

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

Virtual University of Pakistan 163


System Programming Course Code: CS609
[email protected]

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 5th 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

Virtual University of Pakistan 164


System Programming Course Code: CS609
[email protected]

then speaker is turned on by the sound() function and a character ‘A’ is displayed on the
upper left corner of the screen.

Other Configuration Bytes of Battery Powered RAM

Virtual University of Pakistan 165


System Programming Course Code: CS609
[email protected]

Virtual University of Pakistan 166


System Programming Course Code: CS609
[email protected]

Determining Systems Information

Determining Systems Information

INT 11H
INT 12H
INT 11H
used to get hardware environment info.
On Entry
call 11H
On Exit
AX = System Info.

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.

Virtual University of Pakistan 167


System Programming Course Code: CS609
[email protected]

Determining Systems Information


INT 12H
used for memory interfaced.
INT 15H/88H

Returns = No. of KB above 1MB mark.

Int 12H is used to determine the amount of conventional memory interfaced with the
processor in kilobytes. The amount of memory above conventional memory (extended
memory) can be determined using the service 15H/88H.

Virtual University of Pakistan 168

You might also like