You are on page 1of 5

ELECTRONICS FOR YOU JULY 2001

C O N S T R U C T I O N
R
U
P
A
N
J
A
N
A
Nl080008180lll88$l0
$0800l 1lNl8
U.B. MUJUMDAR
T
he basi c requi rements of a real -
ti me programmabl e ti mer gener-
al l y used i n school s and col l eges
for soundi ng the bel l on ti me are:
Preci se ti me base for ti me keep-
i ng.
Read/wri te memory for stori ng the
bel l ti mi ngs.
LCD or LED di spl ay for di spl ay-
i ng real ti me as wel l as other data to
make the i nstrument user-fri endl y.
Keys for data entry.
El ectromechani cal rel ay to oper-
ate the bel l .
We are descri bi ng here a sophi sti -
cated, yet economi cal , school ti mer
bas ed on Motor ol as 20-pi n
MC68HC705J1A mi cr ocontr ol l er .
0080flll0
The pi n assi gnments and mai n features
of the mi cr ocontr ol l er ar e shown i n
Fi g.1 and the Box, r especti vel y. The
compl ete system i s di vi ded i nto four
secti ons, namel y, the ti me keepi ng sec-
ti on, the i nput secti on (keyboard), the
output (di spl ay, i ndi cator s, and r el ay
dri vi ng) secti on, and power suppl y and
battery backup.
The ti me-keepi ng secti on. Accu-
r ate ti me-k eepi n g depen ds on th e
accuracy of ti me base used for dri vi ng
the mi crocontrol l er. I n thi s project, the
mi crocontrol l er i s dri ven by AT-cut par-
al l el resonant crystal osci l l ator that i s
expected to provi de a very stabl e cl ock.
A 3.2768MHz cr ystal pr ovi des a ti me
base to the contr ol l er . The fr equency
(f
osc
) of the osci l l ator i s i nter nal l y di -
vi ded by 2 to get the oper ati ng fr e-
quency (f
op
). Thi s hi gh-fr equency cl ock
source i s used to control the sequenc-
i ng of CPU i nstructi ons.
Timer. The basi c functi on of a ti mer
i s th e meas u r emen t or gen er ati on
of ti me-dependant events. Ti mers usu-
al l y measure ti me rel ati ve to the i nter-
nal cl ock of the mi cr ocontr ol l er . The
MC68HC705J1A has a 15-stage ri ppl e
counter preceeded by a pre-scal er that
di vi des the i nternal cl ock si gnal by 4.
Thi s provi des the ti mi ng reference for
ti mer functi ons.
The programmabl e ti mer status and
control regi ster (TSCR) i s used for de-
ci di ng the i nterrupt rate. I t can be pro-
grammed to gi ve i nterrupts after every
16,384, 3,2768, 65,536, or 131,072 cl ock
cycl es. I n Tabl e I , the control word i s
set to provi de the i nterrupts after ev-
er y 16,384 cycl es. For a 32,768MHz
cr y s tal , th e i n ter r u pt per i od wi l l
be 10 ms. Thus, ti mer i nterrupts wi l l
be gener ated after ever y 10 ms (100
Hz). That i s, 100 i nterrupts wi l l make
1 second.
Now ti me-k eepi ng becomes ver y
si mpl e. As we ar e havi ng a pr eci se
1-second ti me count, a real -ti me cl ock
can be easi l y bui l t.
The MC68HC705J1A has a 64 byte
RAM that i s used for data storage. Real
ti me (i n ter ms of seconds, mi nutes,
PARTS LIST
Semiconductors:
I C1 - 68HC705JI ACP
mi crocontrol l er
I C2 - CD4532 8-bi t pri ori ty
encoder
I C3 - 74LS138 3-l i ne to 8-l i ne
decoder
I C4 - 74LS47 BCD-to-7-segment
decoder/dri ver
T1-T3 - BC547/BC147 npn
transi stor
T4-T7 - 2N2907 pnp transi stor
D1- D7 - 1N4007 di ode
ZD1 - 5.6V, 0.5watt zener
Resistors (-watt, 5% carbon, unless stated
otherwise)
R1 - 210-ohm, 0.5 watt
R2 - 27-ohm
R3, R12-R14,
R24-R27 - 1-ki l o-ohm
R4-R8 - 100-ki l o-ohm
R9 -R11,
R23,R29 - 10-ki l o-ohm
R15-R22 - 47-ohm
R28 - 10-mega-ohm
Capacitors:
C1 - 350F, 25V el ectrol yti c
C2, C3 - 1F, 16V el ectrol yti c
C4, C5 - 27pF cerami c di sk
C6 - 0.1F cerami c di sk
Miscellaneous:
S1-S5 - Push-to-on swi tch (key)
S6 - On/off swi tch
PZ1 - Pi ezo buzzer
RL1 - Rel ay 12V, 300-ohm, 1C/O
XTAL - 3.2768MHz AT-cut crystal
X1 - 230V AC pri mary to 12V-
0-12V, 500mA secondar y
transformer
DI S.1-DI S.4 - LTS542 common-anode
di spl ay
- 4 x 1.2V Ni -Cd cel l s
Fig. 1: MC68HC705J1A pin assignment
Main features of MC68H705J IA
14 bi di recti onal i nput/output (I /O) l i nes.
(Al l the bi di recti onal port pi ns are programmabl e as i nputs or outputs.)
10mA si nk capabi l i ty on four I /O pi ns (PA0-PA3).
1,240 bytes of OTPROM, i ncl udi ng ei ght bytes for user vectors.
64 bytes of user RAM.
Memory-mapped I /O regi sters.
Ful l y stati c operati on wi th no mi ni mum cl ock speed.
Power-savi ng stop, hal t, wai t, and data-retenti on modes.
I l l egal address reset.
A wi de suppl y vol tage range from 0.3 to 7 vol ts.
Up to 4.0MHz i nternal operati ng frequency at 5 vol ts.
15-stage mul ti functi on ti mer, consi sti ng of an 8-bi t ti mer wi th 7-bi t pre-scal er.
On-chi p osci l l ator connecti ons for crystal , cerami c resonator, and external cl ock.
ELECTRONICS FOR YOU JULY 2001
C O N S T R U C T I O N
hours, days of a month, and months)
i s stored i n thi s RAM. Thus an accu-
rate real -ti me cl ock i s generated.
The i nput secti on. For setti ng the
real -ti me cl ock and stori ng operati ng
ti mes, the ti mer r equi r es to be pr o-
gr ammed exter nal l y. Data i s fed us-
i ng the keyboard.
Pr ess-to-on type keys ar e i nter -
faced to the mi crocontrol l er usi ng an
8-bi t pri ori ty encoder CD4532. Thi s en-
coder detects the key-press operati on
and generates the equi val ent 3-bi t bi -
nary data. I ts truth tabl e i s shown i n
Tabl e I I . The pr i or i ty encoder i s i n-
ter faced to por t A of th e
mi cr ocontr ol l er .
Var i ous keys used i n the ti mer ,
al ong wi th thei r functi ons, ar e de-
scri bed bel ow:
Ti me (4): For setti ng real ti me i n
mi nutes and hours.
Bel l (5): For setti ng the bel l s op-
erati ng ti mi ngs.
Di gi t Advance (6): Data setti ng i s
done di gi twi se (hour s di gi t fol l owed
by mi nutes di gi t). The Di gi t Advance
key shi fts the deci mal poi nt to the
r i ght.
Store (7): For stori ng the data (real
ti me or bel l ti me).
Del ete (3): For del eti ng a parti cu-
l ar bel l ti mi ng.
Here, the fi gures wi thi n parenthe-
ses i ndi cate the deci mal equi val ents
of 3-bi t bi nary data from the keyboard.
Set and run modes. Data setti ng
i s possi bl e onl y i n set mode. Set mode
or run mode can be sel ected by toggl e
swi tch S6. By usi ng a l ock swi tch for
S6, the ti mer can be pr otected fr om
unauthori sed data entry/storage.
I n run mode i f you press Bel l key
once, the di spl ay shows the bel l s vari -
ous oper ati ng ti mi ngs one after the
other , i n the same or der i n whi ch
these had been previ ousl y stored. I n
case you want to di sconti nue seei ng
al l the bel l ti mi ngs, you may pr ess
Ti me key at any stage to revert back
to the di spl ay of real ti me.
The output secti on. Seven-seg- F
i
g
.

2
:

S
c
h
e
m
a
t
i
c

d
i
a
g
r
a
m

o
f

t
h
e

m
i
c
r
o
c
o
n
t
r
o
l
l
e
r
-
b
a
s
e
d

s
c
h
o
o
l

t
i
m
e
r
ELECTRONICS FOR YOU JULY 2001
C O N S T R U C T I O N
ment di spl ays ar e used for data di s-
pl ay. As LEDs are bri ghter, these have
been used i n the system. There are two
techni ques for dri vi ng the di spl ays: (i )
dr i vi ng each di spl ay usi ng a separ ate
dri ver (l i ke 74LS47 or CD4511) and (i i )
usi ng mul ti pl exed di spl ays.
The fi rst techni que works wel l , but
practi cal l y i t has two probl ems: i t uses
a l arge number of I C packages and con-
sumes a fai rl y l arge amount of current.
By usi ng mul ti pl exed di spl ay both the
probl ems can be sol ved. I n mul ti pl ex-
i ng, onl y one i nput i s di spl ayed at any
gi ven i nstant. But i f you chop or al ter
i nputs fast enough, your eyes see the
r esul t as a conti nuous di spl ay. Wi th
LEDs, onl y one di gi t i s l i ghted up at a
ti me. Thi s saves a l ot of power and
al so components, maki ng the system
economi cal .
General l y, di spl ays are refreshed at
a frequency of 50 to 150 Hz. Here, di s-
pl ays ar e r efr eshed at a fr equency of
100 Hz (after ever y 10 ms). The di s-
pl ay-refreshi ng program i s an i nterrupt
servi ce routi ne program. BCD-to-7-seg-
ment decoder/dri ver 74LS47, al ong wi th
tr ansi stor 2N2907, and 3-l i ne-to-8-l i ne
decoder 74LS138 are used for dri vi ng
common-anode di spl ays.
I n mul ti pl exed di spl ay, the current
thr ough the segments i s doubl ed to
i n cr eas e th e di s pl ay s br i gh tn es s .
74LS47 i s rated for si nki ng a current
of up to 24 mA. As the current persi sts
for a ver y smal l ti me i n mul ti pl exed
di spl ay, i t i s peaky and can be as hi gh
as 40 mA per segment.
The deci mal poi nt i s contr ol l ed
i n di v i du al l y by tr an s i s tor BC547,
as 74LS47 does not support the deci -
mal poi nt. PA0 and PA1 bi ts of por t
A are used for control l i ng the el ectro-
mechani cal r el ay and buzzer , r espec-
ti vel y.
P ower suppl y
and battery backup.
The mi cr ocontr ol l er
and the associ ated I C
pack ages r equ i r e a
5V DC suppl y, whi l e
th e r el ay an d th e
buzzer r equi r e 12V
DC suppl y. A si mpl e
r ecti fi er al ong wi th
zener di ode-regul ated
power suppl y i s used.
The mi crocontrol l er i s
fed th r ou gh a bat-
ter y-backed power suppl y, so that i n
the case of power fai l ure the functi on-
i ng of the control l ers ti mer secti on i s
not affected. Duri ng power fai l ure the
ti mer i s tak en to l ow power mode
(cal l ed wai t mode). I n thi s mode the
control l er draws a very smal l current.
So smal l Ni -Cd batteri es can provi de a
good backup.
A si mpl e di ode-r esi stance (27-ohm,
1/4-watt) charger mai ntai ns the charge
of the battery at proper chargi ng rate.
$0llN8f0
Motorol a offers I ntegrated Devel opment
Envi r onment (I DE) softwar e for pr o-
grammi ng i ts mi crocontrol l er and com-
pl ete dev el opmen t of th e s y s tem.
The devel opment boar d comes wi th
Edi tor , Assembl er , and Pr ogr ammer
softwar e to suppor t Motor ol as devi ce
pr ogr ammer and softwar e si mul ator .
Th e I CS05JW i n -ci r cu i t s i mu l ator
al ong wi th devel opment boar d (pod)
for ms a compl ete s i mu l ator an d
non-r eal -ti me I /O emul ator for si mu-
l ati ng, pr ogr ammi ng, and debuggi ng
code for a MC68HC705J1A/KJ1 fami l y
devi ce.
When you connect the pod to your
host computer and tar get har dwar e,
you can use the actual i nputs and
outputs of the tar get system dur i ng
s i mu l ati on of th e code. You can
al so use the I SC05JW software to edi t
and assembl e the code i n standal one
mode, wi thout i nput/output to/from pod.
The pod (MC68HC705J1CS) can be i n-
terfaced to any Wi ndows 3.x- or Wi n-
dows 95-based I BM computer usi ng se-
ri al port.
The software for the ti mer has been
so devel oped that the system becomes
as user-fri endl y as possi bl e. The mai n
constrai nt i s read/wri te memory (RAM)
Fig. 3: Power supply circuit for the school timer
ELECTRONICS FOR YOU JULY 2001
C O N S T R U C T I O N
s pace. As men ti on ed ear l i er , th e
mi crocontrol l er has onl y 64 byte RAM.
About twenty bel l operati ng ti mi ngs are
requi red to be stored. So the effi ci ent
use of RAM becomes essenti al .
The softwar e r ou-
ti nes for the ti mer ,
al ong wi th thei r As-
s embl y l an gu age
codes, are l i sted i n a
fol der . (Note: Th i s
fol der , con tai n i n g
source code (.asm) and
l i sti ng fi l e (.l st) wi l l
form part of the EFY-
CD provi ded wi th the
August i ssue. As fi l es
ar e qui te l ar ge, i t i s
not feasi bl e to i ncl ude
them here.) Basi cal l y,
th e fol l owi n g fu n c-
ti ons ar e per for med
by the softwar e pr o-
gr am:
1. I ni ti al i sati on of
ports and the ti mer.
2. Readi ng of key-
pressed data.
3. Stor i ng of r eal
ti me and bel l ti mi ngs.
4. Compar i son of
r eal ti me an d bel l
ti me. I f th e two
match, the bel l ri ngs.
5. Di spl ay of data.
6. Ti me-keepi ng.
For a user-fri endl y
system, the associ ated
softwar e i s r equi r ed to per for m many
data mani pul ati on tr i cks and i nter nal
branchi ng. The operati on and l ogi c can
be understood from the Assembl y l an-
guage l i sti ngs. The software i s mai nl y
TABLE I
Timer Status and Control Register (TSCR)
Bi t 7 6 5 4 3 2 1 0
Si gnal TOF RTI F TOI E RTI E TOFR RTI FR RTI RTO
Reset 0 0 0 0 0 0 1 1
TOF: Ti mer overfl ow fl ag RTI F: Real -ti me i nterrupt fl ag
RTI E: Real -ti me i nterrupt enabl e RTI and RTO: Real -ti me i nterrupt sel ect bi t.
RTI RTO I nterrupt peri od
0 0 fop 2
14
For 3.2768MHz crystal
0 1 fop 2
15
Frequency of operati on (fop)
1 0 fop 2
16
= 3.2768x10
6
/2 = 1.638x10
6
MHz
1 1 fop 2
17
For RTI =RTO=0
I nterrupt peri od = 10ms (100Hz)
di vi ded i nto the fol l owi ng modul es:
Keyboard. When a key i s pressed,
CD4532 sends the correspondi ng data.
After r eadi ng the data, the contr ol l er
deci des on the acti on. Set/ Run key
(S6) i s connected to port PA4.
Bel l . Thi s par t of the pr ogr am i s
used for di spl ayi ng the bel l oper ati ng
ti mi ngs stored i n the RAM. The oper-
ati ng ti mi ngs are di spl ayed one by one
wi th a del ay of 5 seconds between two
consecuti ve ti mi ngs.
Set. The real ti me and bel l ti mi ngs
are stored usi ng thi s part of the soft-
ware. Data i s entered di gi twi se; for ex-
ampl e, 08:30 a.m. wi l l be stored as 0,
fol l owed by 8, fol l owed by 3, and fi nal l y
0. Data i s stored i n 24-hour format.
Data fed from the keyboard i s con-
verted i nto equi val ent hex and stored
i n RAM. Any parti cul ar operati ng ti m-
i ng can be del eted fr om the memor y
usi ng Del ete key, provi ded the ti mi ng
i s al ready stored i n the memory.
Run. Her e the r eal ti me i s com-
pared wi th bel l operati ng ti me. I f the
two match, the rel ay i s operated.
DataCon. Thi s part of the software
i s used for fi ndi ng out the deci mal
equ i v al en t of h ex data. Th e
mi cr ocontr ol l er mani pul ates the hex
data and converts i t i nto BCD format
for di spl ay.
Ti mer . Th e ti mer of th e
mi crocontrol l er i s i ni ti al i sed to gi ve an
i nter r upt after ever y 10 ms. A r eal -
ti me cl ock i s generated usi ng the i nter-
rupt. Al so the di spl ay i s refreshed dur-
i ng the i nterrupt servi ce routi ne.
For r eal -ti me s y s tems batter y
backup i s very essenti al , because power
fai l ure affects the ti me keepi ng. I n i n-
terrupt servi ce routi ne, the avai l abi l i ty
of power suppl y i s checked. I f the power
i s avai l abl e, di spl ays are refreshed and
the ti mer operates normal l y. However,
dur i ng the power -fai l ur e per i od, di s-
pl ays ar e off and system i s taken to
l ow power mode. I n thi s mode onl y
the ti mer par t of the mi cr ocontr ol l er
r emai ns acti vated whi l e oper ati ons of
al l other per i pher al s ar e suspended.
Fig. 4: Actual-size single-sided PCB for the circuits in Figs 1 and 2
ELECTRONICS FOR YOU JULY 2001
C O N S T R U C T I O N
Thi s consi der abl y r educes the power
consumpti on. When the suppl y gets re-
stor ed, the contr ol l er star ts oper ati ng
i n normal fashi on.
00f8ll f00000f0
When the power i s swi tched on, the
di spl ay shows 12.00. Two setti ngs are
requi red i n the ti mer: (a) setti ng of real
ti me and (b) setti ng of bel l oper ati ng
ti mi ngs. For setti ng r eal -ti me cl ock
Ti me key i s used, whi l e for setti ng
bel l ti mi ngs Bel l key i s used.
Stori ng of real ti me. To store real
ti me, say, 05:35 p.m., fl i p Run/Set
key (S6) to set mode. The di spl ay wi l l
show 0.000. Press Ti me key. Further
pr essi ng of Ti me key wi l l i ncr ement
the data, l i ke 0.000, 1.000, 2.000, and
ther eafter i t wi l l r epeat 0.000, etc.
To sel ect the di gi t, pr ess Di gi t Ad-
vance. Thi s stor es the pr esent di gi t
and the next di gi t i s sel ected as i ndi -
cated by the deci mal poi nter. Data i s
stored i n 24-hour format. The ti me to
be stored i s 17.35, of
whi ch the fi r st di gi t
wi l l be 1.000. Th e
s econ d, th i r d, an d
four th di gi ts can be
s tor ed i n s i mi l ar
fas h i on . After th e
fou r th di gi t, pr es s
Di gi t Advance k ey
once mor e. The di s-
pl ay wi l l show 1735
(wi th n o deci mal ).
Now pr ess Stor e to
store the data.
Stor i ng of bel l
ti mi ngs. The pr oce-
dure to store bel l op-
er ati n g ti mi n gs i s
si mi l ar to that of set-
ti ng r eal ti me. The
onl y di fference i s that
here data i s changed
by Bel l key i n pl ace
of Ti me k ey . An y
number of bel l ti m-
i n gs (<20) can be
stor ed i n the same
fashi on. I f the num-
ber of bel l operati ng
ti mi ngs exceeds 20,
the ti mer wi l l not ac-
cept an y n ew bel l
ti mi ng unti l one of
the previ ousl y stored ti mi ngs i s del eted.
Del eti on of bel l oper ati ng ti m-
i ngs. For del eti ng a parti cul ar ti mi ng,
fi r st stor e thi s ti mi ng usi ng the steps
gi ven above. Then press Del ete key to
del ete the speci fi c data from the memory.
Di spl ay of real ti me. I f Run/Set
key i s taken to r un mode, r eal ti me
wi l l be di spl ayed.
Checki ng of bel l operati ng ti mes.
For checki ng the bel l oper ati ng ti mes,
press bel l key i n Run mode onl y. The
stored bel l operati ng ti mi ngs wi l l be di s-
pl ayed one by one wi th a del ay of 5
seconds between two consecuti ve ti m-
i ngs.
Ff0f8MMl
Ther e ar e two ways to pr ogr am the
EPROM/OTPROM (one-ti me pr ogr am-
mabl e ROM):
1. Mani pul ate the control bi ts i n the
EPROM pr ogr ammi ng r egi ster to pr o-
gram the EPROM/OTPROM on a byte-
by-byte basi s.
2. Pr ogr am the EPROM/OTPROM
wi th Motorol as MC68HC705J i n-ci rcui t
si mul ator .
The author has used the second
method for programmi ng the OTPROM.
(EF Y note. Reader s wh o wi s h to
acqu i r e a Pod for 705KJ1/J1A
mi cr ocontr ol l er s, al ong wi th the r e-
qui r ed softwar e, may contact Vi nay
Chaddha at gvc@vsnl .com.)
An actual -si ze, si ngl e-si ded PCB
for the ci rcui ts i n Fi gs 2 and 3 i s shown
i n Fi g. 4, wi th i ts component l ayout
shown i n Fi g. 5.
Fig. 5: Component layout for the PCB
TABLE I I
Truth Table for Priority Encoder CD4532
Keys E1 D7 D6 D5 D4 D3 D2 D1 D0 Q2 Q1 Q0
Store 1 1 X X X X X X X 1 1 1
Di gi t Adv. 1 0 1 X X X X X X 1 1 0
Bel l 1 0 0 1 X X X X X 1 0 1
Ti me 1 0 0 0 1 X X X X 1 0 0
Del ete 1 0 0 0 0 1 X X X 0 1 1

You might also like