Lecture # 19: System Programming Course Code: CS609 Cs609@vu - Edu.pk
Lecture # 19: System Programming Course Code: CS609 Cs609@vu - Edu.pk
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;
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();
}
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.
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.
#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;
}
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
then speaker is turned on by the sound() function and a character ‘A’ is displayed on the
upper left corner of the screen.
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.
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.