Вы находитесь на странице: 1из 13

System Programming Course Code: CS609

Cs609@vu.edu.pk

Lecture # 17
Sample Program

#include <dos.h>
#include <bios.h>
char ch1,ch2;

void initialize (unsigned int com)


{
outportb ( com+3, inport (com+3) | 0x80);
outportb ( com,0x80);
outportb( com +1, 0x01);
outportb ( com+3, 0x1b);
}

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

NULL Modem (Revisited)


CD 1 CD 1
RxD 2 RxD 2
TxD 3 TxD 3
DTR 4 DTR 4
GND 5 GND 5
DSR 6 DSR 6
RTS 7 RTS 7
CTS 8 CTS 8
RI 9 RI 9

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.

NULL Modem (Revisited)


CD 1 CD 1
RxD 2 RxD 2
TxD 3 TxD 3
DTR 4 DTR 4
GND 5 GND 5
DSR 6 DSR 6
RTS 7 RTS 7
CTS 8 CTS 8
RI 9 RI 9

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.

Virtual University of Pakistan 139


System Programming Course Code: CS609
Cs609@vu.edu.pk

Software Oriented Flow


Control

Makes use of Two Control characters.


– XON (^S)
– XOFF (^T)

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.

Virtual University of Pakistan 140


System Programming Course Code: CS609
Cs609@vu.edu.pk

Real Time Clock

Time Updation Through INT8


Real Time Clock Device
• Battery powered device
• Updates time even if PC is shutdown
• RTC has 64 byte battery powered RAM
• INT 1AH used to get/set time.

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.

Clock Counter 1AH/00


(hours*60*60 + min*60 + sec) * 18.2065
ON ENTRY
AH = 00
ON EXIT
AL = Midnight flag
CX = Clock count (Hi word)
DX = Clock count (Low word)
1573040 Times Increment
1573040/18.2065 = 86399.9121 sec
Whereas 86400 sec represent 24 hrs.

Virtual University of Pakistan 141


System Programming Course Code: CS609
Cs609@vu.edu.pk

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)

Read Time 1AH/02


ON ENTRY
AH = 02
ON EXIT
CH = Hours (BCD)
CL = Minutes (BCD)
DH = Seconds (BCD)

Virtual University of Pakistan 142


System Programming Course Code: CS609
Cs609@vu.edu.pk

Set Time 1AH/03


ON ENTRY
AH = 03
CH = Hours (BCD)
CL = Minutes (BCD)
DH = Seconds (BCD)
DL = Day Light saving = 1
Standard Time = 0

Read Date 1AH/04


ON ENTRY
AH = 04
ON EXIT
CH = Century (BCD)
CL = Year (BCD)
DH = Month (BCD)
DL = Day (BCD)

Virtual University of Pakistan 143


System Programming Course Code: CS609
Cs609@vu.edu.pk

Set Date 1AH/05


ON ENTRY
AH = 05
CH = Century (BCD)
CL = Year (BCD)
DH = Month (BCD)
DL = Day (BCD)

Set Alarm 1AH/06


ON ENTRY
AH = 06
CH = Hours (BCD)
CL = Minutes (BCD)
DH = Seconds (BCD)

Virtual University of Pakistan 144


System Programming Course Code: CS609
Cs609@vu.edu.pk

Disable Alarm 1AH/07


ON ENTRY
AH = 07

Read Alarm 1AH/09


ON ENTRY
AH = 09
ON EXIT
CH = Hours (BCD)
CL = Minutes (BCD)
DH = Seconds (BCD)
DL = Alarm Status (00 = Not Enable
01 = Enable)

Virtual University of Pakistan 145


System Programming Course Code: CS609
Cs609@vu.edu.pk

RTC internals

Real Time Clock

70H Clock and 64 Bytes


Logic Battery
circuitry Powered
Low power
71H
Control CMOS
::::::::::::
Circuitry RAM
::::::::::::
INT
::::::::::::

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

Virtual University of Pakistan 146


System Programming Course Code: CS609
Cs609@vu.edu.pk

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.

64 Byte Battery Powered RAM


00H = Current Second
01H = Alarm Second
02H = Current Minute
03H = Alarm Minute
04H = Current Hour
05H = Alarm Hour
06H = Day Of the Week
07H = Number Of Day

64 Byte Battery Powered RAM


08H = Month
09H = Year
0AH = Clock Status Register A
0BH = Clock Status Register B
0CH = Clock Status Register C
0DH = Clock Status Register D
32H = Century

Virtual University of Pakistan 147


System Programming Course Code: CS609
Cs609@vu.edu.pk

Day of the week

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.

Virtual University of Pakistan 148


System Programming Course Code: CS609
Cs609@vu.edu.pk

Accessing the Battery Powered RAM

Accessing the Battery Powered RAM

Battery Powered RAM is accessed in


two steps
• Specify the Byte no. in 70H port.
• Read/write port 71H to get/set the
value of specified byte.

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.

Accessing the Battery Powered RAM

outport (0x70, 0); outport (0x70, 4);


sec = inport (0x71); outport (0x71,hrs);

Virtual University of Pakistan 149


System Programming Course Code: CS609
Cs609@vu.edu.pk

Clock Status Registers

Status Register A
7 6 5 4 3 2 1 0

Interrupt
frequency
Time
frequency

0 = Time is not updated


1 = Time is updated

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.

Virtual University of Pakistan 150

Вам также может понравиться