You are on page 1of 5

CONSTRUCTION

Experimental Understanding about I/O,


MUDIT AGARWAL

EM TESTED
EM TESTED

Counters/Timers and Interrupts of AT89C52 EM TES


TED

Dr. D.G.Vyas

The AT89C52 is a popular 8-bit microcontroller. An This circuit is designed and developed particularly
experimental understanding is presented by few for the educational purpose. By these experiments,
experiments about Input/Output, Counters/Timers the students can understand microcontroller
and Interrupts of microcontroller AT89C52. These fundamentals and its applications. The AT89C52
experiments are designed and developed to has four ports. Here Port-0 and Port-2 are used to
understand the concepts of microcontroller illuminate 6-FNDs and 2-LEDs. Common anode
AT89C52. This novel experiments are useful to type LT542 FNDs are used. The single FND can be
clear the basic doubts of the microcontroller activated by providing low logic on its
AT89C52. The input can be given by the switches. corresponding Port pin of Port-0 and its
Large number of software based experiments can corresponding special code on Port-2. When low
be setup on this hardware. Many projects can also logic is given at the base of PNP transistor BC557
be done on this hardware like, the clock, running through 10KΩ resistor, then the transistor comes
numerical display, stopwatch, blinking display, into saturation. The saturated transistor provides
square wave generator etc. In the present +5 volt at the anode of its corresponding FND.
experimental setup the output can be obtain in the Fig.-2 shows the P.C.B. layout and Fig.-3 shows the
form of Light, Sound and an Electrical waves. The Component Layout. All straight line segments in the
present work is useful particularly for the students overlay layer show the jumper wires in the P.C.B. and
and industrial learners. other shapes show the dimensions of the
components. The pullup resistors are needed for
Introduction port-0. The ladder contains pull-up resistors R6 to
This hardware module is especially designed to R13 of 10KΩ, means all resistors are having same
learn the fundamentals of the AT89C52. The output 10KΩ value. The eight PNP transistors BC 557 (T1
can be seen on FNDs and LEDs. The data can be to T8) are doing switching action to supply +5V at
entered by using four switches. The output light can FNDs, LEDs . Eight current limiting resistors R22 to
be seen on FNDs and LEDs. Many companies like R29 of 220Ω each are used with a buffer IC 74245.
Renesas, Freescale, Atmel, Intel, National, Fig.-2 shows that the same track is not connected
Motorola, Philips, Zilog, etc. are manufacturing with the same segments in two consecutive FNDs.
many models of micro-controllers. The designer The segments are the same for the same track in
can choose the company of the microcontroller and FND-0, FND-2 and FND-4. Similarly, the segments
a model as per the requirement of Port pins, are the same for the same track in FND-1, FND-3
Timer/Counter, RAM, ROM, etc. The cost of the and FND-5. By this logic in P.C.B. drawing, the
system is an important aspect in system design. single sided P.C.B. needs to develop. The Port-2
Software written for some small practical needs to send different data to display the same on
application is enough to get stored in most of these two consecutive FNDs. The Port pins of Port-2 are
microcontrollers. The microcontroller AT89C52 connected with the FND segments through the
has internal EPROM, RAM, Decoder, Ports, Timer buffer IC 74245 and eight 220Ω current limiting
/Counter etc. resistors R22 to R29. The Port pins P2.7, P2.6, P2.5,
Circuit Understanding P2.4, P2.3, P2.2, P2.1 and P2.0 are connected with
The schematic circuit diagram of this experimental FND segments g, f, a, b, h, c, d and e respectively in
hardware module is shown in Fig.-1. The +5 Volt is FND-0, FND-2 and FND-4. Similarly, The Port pins
supplied to this circuit by the external power supply. P2.7, P2.6, P2.5, P2.4, P2.3, P2.2, P2.1 and P2.0
C C1 +5V

R11

R13
R12
R10
R9
R8
R7
R6
R
1 40
P1.0 VCC
2 39
P1.1 P0.0
3 38
P1.2 P0.1
4 P0.2 37
5 P1.3 36
P0.3
6 P1.4 P0.4 35
7 P1.5 P0.5 34
R1 P1.6
8 P0.6 33
R2 9 P1.7 P0.7 32
10 RESET IC1 31
R3 P3.0
11 EA 30
R4 12 P3.1 ALE 29
R21
R20
R14

R19
R18
R17
R16
R15

13 P3.2 PSEN 28

Fig. 1 Circuit Diagram of AT89C52 Experimental Board


S3
14 P3.3 P2.6 27
15 P3.4 P2.7 26
S2 16 P3.5 P2.5 25
17 P3.6 P2.4 24
18 P3.7 P2.3 23
S1 19 X1 P2.2 22 T1
20 X2 P2.1 21 T2
GND P2.0 Buzzer
S0 T3
T4
CONSTRUCTION

R5
T5
X1
T6
C3 C4
C2 T7
T8

CE GND
19 19
VCC
1 S/R 20
A7 B7 R29
9 11
A6 B6 R28
8 12
A5 IC2 B5 R27
7 13
A4 B4 R26
6 14
A3 B3 R25
5 15
A2 B2 R24
4 16 L1 L0
A1 B1 R23
3 17
A0 B0 R22
2 18
FND5 FND4 FND3 FND2 FND1 FND0
CONSTRUCTION

are connected with FND segments b, a, f, g, e, d, c pressing as shown in Table-2.


and h respectively in FND-1, FND-3 and FND-5. Assembly Code for Experiment-1
START EQU 0600H
The special codes to see the digit on FNDs are ORG 0000H
different for FND-0 and FND-1. The codes remain LJMP START
ORG START
same for FND-0, FND-2 and FND-4, and same for MOV P0,#00H
;TO INITIALIZE PORT-0 AS OUTPUT PORT
TABLE-1 : FND CODE FOR DISPLAY
MOV P2,#00H
To see on FND Special codes for Special codes for ;TO INITIALIZE PORT-2 AS OUTPUT PORT
FND-0,FND-2 & FND-4 FND-1,FND-3 & FND-5
MOV P3,#0FFH
0 88H 11H
;TO INITIALIZE PORT-3 AS INPUT PORT
1 EBH 7DH
2 4CH 23H AGAIN: MOV A,#0FH
3 49H 29H ANL A,P3
4 2BH DH CJNE A,#0EH,FND1;1110
5 19H 89H FND0: MOV P0,#7FH ;TO ACTIVATE FND0
6 18H 81H MOV P2,#88H ;TO DISPLAY 0 ON FND0
7 CBH 3DH JMP AGAIN
8 08H 01H FND1: CJNE A,#0DH,FND2 ;1101
9 09H 09H MOV P0,#0BFH ;TO ACTIVATE FND1
A 0AH 05H MOV P2,#11H
B 38H C1H JMP AGAIN
C 9CH 93H FND2: CJNE A,#0BH,FND3;1011
D 68H 61H MOV P0,#0DFH ;TO ACTIVATE FND2
E 1CH 83H
MOV P2,#88H
F 1EH 87H
JMP AGAIN
Blank FFH FFH
FND3: CJNE A,#07H,FND4;0111
T 3CH C3H
R 7EH E7H MOV P0,#0EFH ;TO ACTIVATE FND3
N 7AH E5H MOV P2,#11H
JMP AGAIN
FND-1, FND-3 and FND-5. These special codes FND4: CJNE A,#0CH,FND5;1100
MOV P0,#0F7H ;TO ACTIVATE FND4
are shown in Table-1. MOV P2,#88H
The R and C are used to reset the microcontroller at JMP AGAIN
starting. The four pushbutton keys S0, S1, S2 and FND5: CJNE A,#03H,LED0_1;0011
MOV P0,#0FBH ;TO ACTIVATE FND5
S3 are connected between ground and Port-3 pins MOV P2,#11H
P3.0, P3.1, P3.2 and P3.3 respectively. The four JMP AGAIN
LED0_1: CJNE A,#00H,OFF_ALL ;0000
10KΩ resistors R1 to R4 are connected between MOV P0,#0FDH ;TO ACTIVATE LED0 AND LED1
+5 Volt and Port-3 pins P3.0, P3.1, P3.2 and P3.3. MOV P2,#00H
JMP AGAIN
This arrangement provides low logic at port pin OFF_ALL: MOV P0,#0FFH ;TO CUTOFF ALL TRANSISTORS
when the key is pressed, and high when key remains JMP AGAIN
unpressed or released. The 12MHz crystal is END

connected between pins X1 and X2 of AT89C52.


Two 33pf capacitors C3 and C4 are connected
Experiment-2
between pins X2 and X1(respectively) and ground. Develop the program to activate FND-0 and FND-
Other capacitors C1 and C2 of 10pf are for the 1 one by one and the delay set by Timer-0.
better performance of the circuit. The buzzer is
connected through emitter of the PNP transistor T8 Assembly Code for Experiment-2
START EQU 1700H
and 1KΩ current limiting resistor R5. TIMER_0 EQU 000BH
TI_0 EQU 0100H

Experiment-1 ORG 0000H


JMP START
TABLE 2 ORG TIMER_0
Observation no. Key Pressed Output on FND or LED JMP TI_0
ORG TI_0
1 S0 0 on FND-0
2 S1 0 on FND-1
DJNZ R2,NEXT
3 S2 0 on FND-2 MOV R2,#20H
4 S3 0 on FND-3 NEXT:CJNE R2,#10H,CARRY_CHK
5 S0 & S1 0 on FND-4 CARRY_CHK: JC FND0
6 S2 & S3 0 on FND-5 MOV P0,#0BFH
7 S0 & S1 & S2 & S3 Both LEDs are illuminated. MOV P2,#11H
SJMP END_T0
Develop the program to understand the I/O FND0:MOV P0,#7FH
MOV P2,#88H
function in the AT89C52 by developing the proper END_T0: SETB TR0
software to see the output for proper input key RETI
CONSTRUCTION

ORG START
MOV P0,#00H interrupt-0 (by Pressing S2) and display 2 on FND-0
MOV P2,#00H by falling edge triggered interrupt-1 (by Pressing
MOV TL0,#00H
MOV TH0,#00H
S3).
MOV TMOD,#81H
MOV IE,#82H Assembly Code for Experiment-4
MOV R2,#20H
START EQU 1700H
SETB TR0
INT_0 EQU 0003H
HERE:SJMP HERE
INT_1 EQU 0013H
END
I_0 EQU 0100H
I_1 EQU 0200H
ORG 0000H
Experiment-3 JMP START
Develop the program for the decade counter using ORG INT_0
JMP I_0
Timer-0 on FND-0. ORG INT_1
JMP I_1
ORG I_0
Assembly Code for Experiment-3 MOV P2,#0EBH
START EQU 1700H RETI
TIMER_0 EQU 000BH ORG I_1
TI_0 EQU 0100H MOV P2,#4CH
FND024 EQU 0200H RETI
ORG 0000H ORG START
JMP START MOV SP,#30H
ORG TIMER_0 MOV TCON,#04H
JMP TI_0 MOV P0,#00H
ORG TI_0 MOV P2,#00H
INC R2 MOV IE,#85H
CJNE R2,#10H,END_T0 MOV P0,#7FH
MOV R2,#00H MOV P2,#88H
MOV A,R0 HERE: SJMP HERE
MOVC A,@A+DPTR END
MOV P2,A
INC R0
CJNE R0,#0AH,END_T0
MOV R0,#00H
Experiment-5
END_T0: SETB TR0 Develop the program to hear some sound on the
RETI Buzzer.
ORG FND024
DB 88H
DB 0EBH Assembly Code for Experiment-5
DB 4CH ORG 0000H
DB 49H MOV P0,#00H
DB 2BH MOV P2,#00H
DB 19H MOV P0,#0FFH
DB 18H HERE: CPL P0.0
DB 0CBH CALL DELAY
DB 08H SJMP HERE
DB 09H
ORG START DELAY: MOV R0,#0FFH
MOV P0,#00H LOOP1: DJNZ R0,LOOP1
MOV P2,#00H RET
MOV TL0,#00H END
MOV TH0,#00H
MOV TMOD,#81H COMPONENT LIST
MOV IE,#82H SEMICONDUCTOR DEVICES
MOV R0,#00H IC1 At89c52
IC2 74245
MOV R2,#00H FND0 to FND5 Common Anode FNDs LT542
MOV DPTR,#FND024 L0 & L1 Red LEDs
T1 to T8 BC557 PNP Transistors
MOV P0,#7FH
MOV P2,#0FFH CAPACITORS
C 10µf
SETB TR0 C1 & C2- 0.1uf
HERE: C3 & C4- 33pf
SJMP HERE RESISTOR
END R, R1 to R4, R14 to R21 10KΩ
R6 to R13 10KΩ
R5 1KΩ
R22-R29 220 ohm
Experiment-4 MISCELLANEOUS
Develop the program to understand both the X1
Buzzer
12MHZ CRYSTAL
+5 volt operated buzzer
+5 volt/ 1 Amp. D.C. Regulated Power supply
external interrupts. Initially display 0 on FND-0. A Computer with Programmer

Display 1 on FND-0 by low level triggered


CONSTRUCTION

Fig. 2. PCB Layout of AT89C52 Experimental Board

BUZZER FND5 FND4 FND3 FND2 FND1 FND0

T1 e T2 e T3 e T4 e T5 e T6 e T7 e T8
e

R5
R21 R20 R19 R18 R17 R16 R15 R14
C1
+ R6-R13 C2
+5V DC
1
+
C
R22
IC1 R23
R R24
IC2 R25
R1 R26
1 C3 R27
R2 C4 R28
R3 R29
X1
R4 S0 S1 S2 S3

Fig. 3.Component Layout of AT89C52 Experimental Board

You might also like