MICROPROCESSORS AND MICROCONTROLLER
Program: To display two digits on a 7 segment displays
START: MVI A, 80 ; Control word 80H is stored in Acc
OUT CWR ; Control word is send to Control Word Reg. of 8255
LDA 4500 ; The data to be displayed is loaded in to Acc
DAA ; Decimal Adjust Accumulator to get the BCD values
OUT PORTA ; PA0-PA3 receives the BCD value of LSD and
HLT ; PA4-PA7 receives the BCD value of MSD.
;The corresponding digits are displayed in the 7-seg.disp.
DIGITAL CLOCK
A digital clock is a type of clock that displays the time digitally i.e. in
numerals as opposed to an analog clock. Also many microprocessor applications
would require, doing certain tasks at specific time of the day or would involve the
time of day in some other form. For example switching ON and OFF street lights
at specific time in the evening and following morning or punching entry time of
every worker for a shift, at a factory gate etc. A basic requirement of these types of
applications is a real time digital clock with a display of current time. A digital
clock can be implemented by using a dedicated hardware like MM5314 or by
software. The following program is used to implement a digital clock on an 8085
system.
The basic requirement of a digital clock is the seven segment displays to
show Hours, Minutes & Seconds. The seven segment displays are interfaced with
the 8085 processor through the ports of 8255 PPI available in the microprocessor
trainer Kit. The displays are driven by suitable seven segment decoder driver
(7447/7448). The main part of the digital clock program is the accurate generation
of 1 Hz frequency or 1 second time delay for reference.
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 6
MICROPROCESSORS AND MICROCONTROLLER
The 1Hz frequency or 1 second time delay can be produced exactly by using
a timer 8253 or by using a well designed delay subroutine.
Program Logic
Three CPU registers are used to count Hours, Minutes and Seconds. The
Seconds counter is incremented for every second, and its content checked for 60.
When it reaches 60, it is reset to 0 and the Minutes counter is incremented by one.
When the Minutes counter reaches 60, it is reset to zero and the Hour counter is
incremented by one. Similarly, when the Hours counter reaches 13 it is reset to 1.
The counter incrementing is done in decimal format. For every second the display
is updated by the Hours, Minutes and Seconds registers. The program works in a
continuous loop and displays time round the clock. The block diagram of the
digital clock, the flow chart and the program are shown below.
Digital Clock Basic Block Diagram
8255
D0-D7 PA4-A7 7447
Hr
PA0-A3
7447
RD’
7447
8085 WR’ PB4-B7 Min
PB0-B3 7447
ADDRESS
DECODER CS’ PC4-C7
7447
Sec
A0-A7 PC0-C3
7447
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 7
MICROPROCESSORS AND MICROCONTROLLER
FLOW CHART
START
INITIALIZE HR,MIN,SEC
COUNTERS
CALL DELAY SUBROUTINE
FOR 1 SEC
SEC SEC +1
SEC >59? Y
N
MIN MIN +1
SEC 0
Y
MIN >59?
N
HR HR +1
MIN 0
HR >12?
N
Y
HR1
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 8
MICROPROCESSORS AND MICROCONTROLLER
8255 Port Configuration:
Control word formation:
All the ports of 8255 are configured as output ports in Mode 0.
(i.e) Port A , Port B, Port C : output , Mode: Simple I/O
Therefore, the Control Word is: 80H
Port C : to send Seconds value to 7 segment displays
Port B: to send Minutes value to 7 segment displays
Port A: to send Hour value to 7 segment display
Program
Label Mnemonics Comment
Start: LXI D,HH00 ;(D) Hr
LXI B,MMSS ; (B) Min, (C) Sec
MVI A,80H ; (A) Control word for Port Conf.
OUT CWR ; Move the Control word to Control Register
of 8255 to configure the ports/
DISP: CALL DISPLAY ;Call display Subroutine to Display
Hr,Min,Sec values on the 7 segment display
DEL: CALL DELAY ; Call 1 sec Delay Subroutine
INR C ; Sec Sec +1
MOV A,C ;Mov Sec to Acc
CPI A,3C ; Is Sec >59 (ie) Sec =60?
JNZ DEL ; If No (ZF!=1) , Goto Label DISP
MVI C,00 ; if Yes, set Sec 00
INR B ; Min Min +1
MOV A,B ; Move Min value to Acc
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 9
MICROPROCESSORS AND MICROCONTROLLER
CPI 3C ; Is Min >59 (ie) Min = 60?
JNZ DEL ; If No (ZF!=1) , Goto Label DISP
MVI B,00 ; If Yes, set Min 00
INR D ;Hour Hour +1
MOV A,D ;Move Hour value to A
CPI 0D ; if Hour >13 ?
JNZ DEL ;If No (ZF!=1) , Goto Label DISP
MVI D,01 ; If Yes , set Hour 1
JMP DISP ; Jump to DISP
HLT ;HALT
Subroutine to Display Hour , Min, and Sec values
DISP: MOV A, D ; (A) Hour Value
DAA ; Get the BCD values
OUT PORT A ; Display Hour value
MOV A,B ; (A) Minute Value
DAA ; Get the BCD value
OUT PORTB ;Display Minute Value
MOV A, C ; (A) Seconds
DAA ;Get the BCD value
OUT PORTC ; Display Seconds value
RET ; Return
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 10