Академический Документы
Профессиональный Документы
Культура Документы
Cs609@vu.edu.pk
Lecture # 17
Sample Program
#include <dos.h>
#include <bios.h>
char ch1,ch2;
void main ( )
{
initialize(0x3f8);
while (1)
{
if ( ((inport(0x3fd)&0x20)==0x20) && (kbhit()))
{ ch1=getche();
outport(0x3f8,ch1);
}
if (( (inport(0x3fd)&0x01)==1))
{ ch2= inport(0x3f8);
putch(ch2);
}
if (( ch1==27) || (ch2==27))
break;
}
}
This program is same functionally as one of the previous programs which used BIOS
services to get the input data and send the output data. The only difference is that in this
case it does the same directly accessing the ports.
Virtual University of Pakistan 138
System Programming Course Code: CS609
Cs609@vu.edu.pk
Only two or three of the lines are being used to send receive data rest of the lines are
being used for flow control. The cost of these lines can be reduced by reducing the lines
used to flow control and incorporating software oriented flow control rather than
hardware oriented flow control as show in the slide below.
The DTR, DSR, RTS and CTS lines have been eliminated to reduce cost but in this flow
control will be performed in a software oriented manner.
XON whenever received indicates the start of communication and XOFF whenever
received indicates a temporary pause in the communication.
Following is a pseudo code which can be used to implement the software oriented flow
control.
while (1)
{
receivedchar = readchar (com);
if (receivedchar == XON)
{ ReadStatus = TRUE;
continue;
}
if (receivedchar == XOFF)
{ ReadStatus = FALSE;
continue;
}
if (ReadStatus == TRUE)
Buf [i++] = receivedchar;
}
the received character is firstly analysed for XON or XOFF character. If XON is received
the status is set to TRUE and if XOFF is received the status is set to FALSE. The
characters will only be received if the status is TRUE otherwise they will be discarded.
Real time clock is a device incorporated into the PC to update time even if the computer
is off. It has the characteristics shown in the slide above which enables it to update time
even if the computer is off.
The BIOS interrupt 0x1Ah can be used to configure this clock as shown in the slide
below it has various service for getting/setting time/date and alarm.
AL = 1 if Midnight passed
AL = 0 if Midnight not passed
Set Clock Counter 1AH/01
ON ENTRY
AH = 01
CX = Clock count (Hi word)
DX = Clock count (Low word)
RTC internals
7FH
The RTC internally has an array of registers which can be used to access the 64 byte
battery powered CMOS RAM.
Internal Ports
70 – 7FH (16 ports)
Only 70 & 71H are important from
programming point of view
The following slide shows the function of some of the bytes in the battery powered RAM
used to store the units of time and date.
Week Day
01H = Sunday
02H = Monday
03H = Tuesday
04H = Wednesday
05H = Thursday
06H = Friday
07H = Saturday
The value in the days of the week byte indicates the day according to slide shown above.
Generally BCD values are used to represent the units of time and date.
Year
No of Century and Year are in BCD.
Following slide shown a fragment of code that can be used to read or write onto any byte
within the 64 byte battery powered RAM.
Status Register A
7 6 5 4 3 2 1 0
Interrupt
frequency
Time
frequency
The lower 4 bits of this register stores a code indicating the frequency with which the
RTC hardware interrupt can interrupt the processor. The next field is used to specify the
time frequency i.e. the frequency with the time is sampled and hence updated. The most
significant bit indicates that after time sampling if the time has been updated in to the 64
byte RAM or not.