Real-Time Clock Using 8253
Real-Time Clock Using 8253
Objectives
The aim of this LAB experiments is to interface the 8253 Programmable Interval Timer
(PIT) chip to our microcomputer system and program it to implement a real-time clock.
10.1 Background
The 8253 is programmable interval timer/counter ; specifically designed for use with the
Intel microcomputer systems. The 8253 solves one of the most common problems in any
microcomputer system ; the generation of accurate time delays under software control. Instead of setting up timing loops in systems software, the programmer configures the 8253 to
match his requirements, initializes one of the counters of the 8253 with the desired quantity,
then upon command the 8253 will count out the delay and interrupt the CPU when it has
completed its tasks. It is easy to see that the software overhead is minimal and that multiple
delays can easily be maintained by assignment of priority levels.
92
Chip Select(CS)
Data transfer with the CPU is enabled when this pin is at low level. When at high level,
the data bus (D0 through D7) is switched to high impedance state where neither writing
nor reading can be executed. Internal registers, however, remain unchanged.
Clock Input(CLK0-2)
Supply of three clock signals to the three counters incorporated in 8253.
Gate Input(GATE0-2)
Control of starting, interruption, and restarting of counting in the three respective counters
in accordance with the set control word contents.
Counter Output(OUT0-2)
Output of counter output waveform in accordance with the set mode and count value.
93
10.1 Background
94
95
10.1 Background
D7
D6
S C 1
S C 0
S e le c t C o u n te r
S C 1
0
0
1
1
S C 0
0
1
0
1
R L 1
0
0
1
1
R L 0
0
1
0
1
M 2
0
0
X
X
1
1
M 1
0
0
1
1
0
0
D5
D4
R L 1
R L 0
R e a d /L o a d
D3
M 2
C o u
C o u
C o u
Ille g
C o
R e
R e
R e
u n
a d
a d
a d
te
in
in
in
M 0
0
1
0
1
0
1
r L
g /L
g /L
g /L
a tc
o a
o a
o a
h O
d in
d in
d in
B C D
0
1
M o d
M o d
M o d
M o d
M o d
M o d
p e
g o
g o
g o
ra
f L
f M
f L
e 0 (
e 1 (
e 2 (
e 3 (
e 4 (
e 5 (
In te
P ro
R a t
S q u
S o f
H a r
F
n te
n te
n te
a l
D2
M 1
M o d e
u n
r 0
r 1
r 2
C o
c t
S
S
S
m
F u n c
tio n
e a s t S
o s t S
S B F o
rru p
g ra m
e G e
a re
tw a r
d w a
io n
e le
e le
e le
b in
D1
M 0
c tio
c tio
c tio
a tio
n
n
B C D
D0
B C D
n
n
tio n
ig n ific a n t B y te (L S B )
ig n ific a n t B y te (M S B )
llo w e d b y M S B
F u n c tio
t o n T e rm
m a b le O
n e ra to r)
W a v e G e
e T r ig g e r
r e T r ig g e
in a l C o u n t)
n e -S h o t)
n e ra to r)
e d S tro b e )
re d S tro b e )
F u n c tio n
B in a r y C o u n t (1 6 -b it B in a r y )
B C D ( 4 - d e c a d e B C D)
Device
1 5
1 4
1 3
1 2
1 1
8 2 5 5 A
0
0
0
0
0
0
0
0
1
1
1
0
0
0
0
1
0
0
IC W
IC W
0 4 H
C o u n t er 1
0 A H
C o n tr o l
0 E H
C o u n t er 2
1
0
0 2 H
0 6 H
0 0 H
C o n tr o l
C o u n t er 0
0
P o r t
A d d r es s
0
1
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
P o r t
N a m e
1 0
8 2 5 3
8 2 5 9 A
A d d r es s L in es
0 8 H
0 C H
1 , O C W 2 -3
2 -4 , O C W
1 0 H
1 2 H
Figure 10.5 The I/O mapping of the 8255A, 8253 and 8259A peripherals.
96
97
98
Figure 10.9 Interfacing the output of Counter 0 to the NMI input of the 8086
microprocessor.
Figure 10.10 Properties of the DCLOCK connected to the CLK0 pin of the
8253.
Figure 10.11 Properties of the DPULSE connected to the GATE0 pin of the
8253.
99
100
next:
main ENDP
nmisr PROC FAR
CMP cnt, 49
JAE inc_sec
INC cnt
JMP done
inc_sec:
MOV cnt, 0
CMP sec, 59h
JAE inc_min
MOV AL, sec
ADD AL, 01h
DAA
MOV sec, AL
OUT 04h, AL
JMP done
inc_min:
MOV sec, 00h
MOV AL, 00h
OUT 04h, AL
CMP min, 59h
JAE inc_hrs
MOV AL, min
ADD AL, 01h
DAA
MOV min, AL
OUT 02h, AL
JMP done
inc_hrs:
MOV min, 00h
MOV AL, 00h
OTU 02h, AL
CMP hrs, 23h
JAE inc_dys
MOV AL, hrs
ADD AL, 01h
DAA
MOV hrs, AL
OUT 00h, AL
JMP done
inc_dys:
MOV hrs, 00h
OUT 00h, AL
done:
IRET
nmisr ENDP
.EXIT
END
101