Sie sind auf Seite 1von 44

Abstract

Most of the quiz competitions which are held locally are


normally conducted manually such as the time given to the
participants to answer a question are set manually using an external
stopwatch as a timer and the participants are required to raise their in
order to compete to grab the chance of answering the given question
to get marks. This is not a very effective way of conducting a
competition especially in international level. Thus, our group has
decided to design and create an electronic quiz system or device
which helps to improve and eliminate the problems and weaknesses
of the traditional way of conducting a quiz competition.

The electronic quiz system consists of switches monitoring


system and a resettable countdown timer. This system can be used for
a maximum of 4 participants or teams in any general quiz competition.
The participants are just required to press a button to compete to get
the chance of answering a question instead of raising their hands.
Then, the timer can be set to countdown automatically for the time
given to answer the question. This system will be a more effective way
to conduct a quiz competition. The electronic quiz system can be
widely used in school, colleges and TV programs. During the quiz
contests, the question is thrown openly to all the teams or person. The
person who knows the answer will press the button first and then
answers the question within the time given.

Acknowledgement
Throughout this project, we have learnt more about the 8051 development system and
the assembly language. We would like to express our greatest gratitude and
appreciation to all the technicians that helped us throughout the process to finish this
mini project. Hereby, we would like to express our deepest appreciation to our lecturers
that guided us to successfully complete our project.

Introduction
This project can be used in any general quiz competition system. This circuit
can be used for maximum of 4 players who are involved in the quiz competition. The
circuit will have 4 Light Emitted Diode (LED) to indicate who has pressed the button first
and the number which represents the corresponding participant will be displayed on a 7
Segment. Then, for different quiz question, different time duration can be set and
displayed on another 7-Segement to be given to the particular participant to answer the
quiz. A switch (RESET Switch) can be pressed to start the countdown of the timer. If the
participant cannot answer the question within the time given, the circuit will be reset.
The reset switch can also be used to stop the countdown and reset the circuit as well as
the value displayed in the 7 Segment.
The main objective of this project is to design and create a general
electronic quiz system so that it can be used and utilized in any general quiz competition
globally. Most of the quiz competitions are conducted manually such as the candidates
have to compete among themselves by raising their hands to grab to chance of
answering the question to get marks and time given to each candidate to answer a
question is counted by using an external timer. Thus, we design a more effective
electronic quiz system to help to improve and eliminate the problems and weaknesses
of the way of the competitions are being conducted so that the competitions can be
conducted effectively and productively.

Objectives

To program the Microprocessor 8051 to create an electronic quiz system


To interface the Microprocessor 8051 with Keypad and 7-Segments Display.
To use the Keypad to set time for the timer for countdown.
To use the 7-Segments to display the output through Microprocessor 8051.
2

Literature Review
Based on the electronic quiz system which is designed developed by
the others had been found to have some weaknesses and lack of some important
features of the system. They designed the electronic quiz system by using a
microprocessor 8085 which is slower to read and run an assembly program code and
lack of internal timer compared to microprocessor 8051. Other than that, the system is
designed and developed without a countdown timer which is very important in
conducting a quiz competition so that the organizer can set a time given to the
participants to answer the questions.

Thus, our group has decided to design and create a more complete and
efficient quiz system for any general quiz competition. First of all, we have designed the
system for a maximum of 4 participants or teams to be involved in the competition.
When the first person presses the button, the representative number of the person will
be displayed on a 7 segment. Then, we add in a keypad for the design of the countdown
timer so that the organizer can set the time given to the participant to answer a
question. Other than that, a buzzer is connected to indicate when the button is pressed
or the time given is already over. A reset switch which is also the countdown switch has
been designed by using the same switch for the convenient of the organizer and it can
be used to start the countdown of the timer after the time given is set by using the
keypad and also reset the system to the beginning stage when the participant can
answer the given question within the time given. The system will reset automatically by
itself when the time given is over. A system which consist the above features will be
more effective and productive to conduct a quiz competition and it is also the
advantages of the system that we design and program.

Methodology
The circuit system is controlled and monitored by the Microprocessor 8051
and using of Ports of 8255. The microprocessor will be continuously monitoring the
circuit and the 4 switches. When one of the switches is pressed, the microprocessor will
check the switch and display the corresponding value on a 7 Segment display. A buzzer
will be triggered to indicate that one of the switches is pressed. Then, the keypad can be
used to set the time of the timer for countdown. A countdown switch (which is also the
RESET switch) can be pressed to start the countdown of the time given to the
participant who is answering the quiz. The buzzer will be triggered if the time is over and
the system will be automatically reset to the beginning state. Reset switch can also be
used to reset the system if the participant can answer the quiz within the time given.

Component List
Components/Equipment
8051 Development System
Light Emitted Diode (LED)
7-Segment Display
Mini Push Button Switch
Buzzer
Resistor (1 k)

Quantity
1
4
2
5
1
5

Microprocessor 8051
Use to run the programmes and process data.
Keypad
Used to key in the number that been choose.
7-Segment DISPLAY
Use to display the corresponding number and time given.
Buzzer
Use to buzz when its fit.
LED
Use to tell us which number it represents for.
Resistance
Use to reduce the current voltage and protect the hardware.

Block Diagram
To write the program for the electronic quiz system, the correct and
accurate circuit connection is required to prevent connection error
with the program running. A block diagram is drawn to ease the
understanding of the schematic circuit and the circuit design in the
form of rough sketch. The block diagram explains roughly about the
connection of 8051 development system with the computer, I/O
interfacing 8255, the mini push-button switches, reset switch, keypad,
light emitted diode (LED), 7-Segment displays and also the buzzer.

4 Switches

Reset Switch / Countdown Switch

8051

8255

Keypad
4 LEDs
7 - Segments
Buzzer

The figure above is the block diagram of the quiz system

HARDWARE DESCRIPTION
Keypad
Keypad was used in this project to set the time given to the participant to answer a quiz
question. The keypad we used was built up from switches which arranged in the form of 4X4
(Column X Row) matrix. Every button we press will generate 8 bit binary code itself. In order to
interpret data from keypad, all the three columns (C0-C2) have to connect to the output port C
from PC4 to PC6 and all the four rows (R0-R3) have to connect to the input port from PC0 to PC3.
The way to interpret the data from the keypad is through the key-switch scanning technic. Logic
1 will send in turns to the column and every row will be scan one by one to determine the
connection that is formed. Therefore logic 1 will be detected for the row and column that are
pressed. Finally, all the keys will represent by specify 8 bit binary codes.

Number
1
2
3
4
5
6
7
8
9
0
*
#

Binary Number
0001 0001
0010 0001
0100 0001
0001 0010
0010 0010
0100 0010
0001 0100
0010 0100
0100 0100
0010 1000
0001 1000
0100 1000

Hexadecimal Number
11H
21H
41H
12H
22H
42H
14H
24H
44H
28H
18H
48H

Binary and Hex codes for matrix keypad

7-segmen display
7-segment display always use with the digital electronic device to display the
information that related with a process. The common cathode 7-segment display was
used in this project. For common cathode, the particular segment will light up when logic
1 (5V) is supplied and will off when logic 0 is supplied (0). Therefore Table1 will
show the codes that are required to display the particular number for common cathode 7segment display.

Number

Common Cathode
g

Hexadecimal

3FH

06H

5BH

4FH

66H

6DH

7DH

07H

7FH

67H

Binary codes for common cathode 7-Segment Display

*The hexadecimal code is used in the program code for the Declaration of TABLE.
7

LED ( Light Emitting Diode )


LED (Light Emitting Diode) is a unique PN junction diode, where it emits light when it is
forward biased. In normal diode, energy is released in the form of heat, whereas LED releases
energy in the form of light.

Mini Push Button Switch


These are high quality momentary on switches. Perfect as a tactile reset switch. Mounts
directly into standard breadboards.

INTEL 8051 MICROPROCESSOR


INTRODUCTION
A microcontroller is an integrated circuit or a chip with a processor and other support
devices like program memory, data memory, I/O ports, serial communication interface
etc integrated together. Unlike a microprocessor (ex: Intel 8085), a microcontroller does
not require any external interfacing of support devices. Intel 8051 is the most popular
microcontroller ever produced in the world market.
Intel first produced a microcontroller in 1976 under the name MCS-48, which was an 8
bit microcontroller. Later in 1980 they released a further improved version (which is also
8 bit), under the name MCS-51. The most popular microcontroller 8051 belongs to the
MCS-51 family of microcontrollers by Intel.
Following the success of 8051, many other semiconductor manufacturers released
microcontrollers under their own brand name but using the MCS-51 core. Global
companies and giants in semiconductor industry like Microchip, Zilog, Atmel, Philips,
and Siemens released products under their brand name.
The specialty was that all these devices could be programmed using the same MCS-51
instruction sets. They basically differed in support device configurations like improved
memory, presence of an ADC or DAC etc. Intel then released its first 16 bit
microcontroller in 1982, under name MCS-96.

SPECIAL FEATURES OF 8051


Some of the features that have made the 8051 popular are:

4 KB on chip program memory.


128 bytes on chip data memory(RAM).
4 reg banks.
128 user defined software flags.
8-bit data bus
16-bit address bus
32 general purpose registers each of 8 bits
16 bit timers (usually 2, but may have more, or less).
3 internal and 2 external interrupts.
Bit as well as byte addressable RAM area of 16 bytes.
9

Four 8-bit ports, (short models have two 8-bit ports).


16-bit program counter and data pointer.
1 Microsecond instruction cycle with 12 MHz Crystal.

APPLICATIONS
8051 chips are used in a wide variety of :

control systems
telecom applications
robotics
automotive industry
By some estimations, 8051 family chips make up over 50% of the embedded chip
market.

8051 PIN DIAGRAM AND DESCRIPTION

10

BASIC PINS
PIN
9

FUNCTION
Reset pin which is used to reset the microcontrollers internal
registers and ports upon starting up.

18 & 19

The 8051 has a built-in oscillator amplifier hence we need to only


connect a crystal at these pins to provide clock pulses to the circuit.

20 & 40

Pins 40 and 20 are VCC and ground respectively.

29

30

31

This is "program store enable" or PSEN. In order to use the external


memory it is required to provide the low voltage (0) on both PSEN and
EA pins.

This pin is called ALE (address latch enable), which is used when
multiple memory chips are connected to the controller and only one
of them needs to be selected.

In order to program the built-in flash memory, we need to supply a


voltage of +12V at this pin. If external memory is connected then PIN
31, also called EA/VPP, should be connected to ground to indicate the
presence of external memory.

11

PORTS

PORT

FUNCTION

P0 (PIN 32-39)

Can be used as a general purpose 8 bit port when no


external memory is present, but if external memory access is
required then PORT P0 acts as a multiplexed address and
data bus that can be used to access external memory in
conjunction with PORT P2. P0 acts as AD0-AD7.

P1 (PIN 1-8)

P2 (PIN 21-28)

P3 (PIN 10-17)

A general purpose input/output port which can be used for a


variety of interfacing tasks. Port 1 output buffers can
sink/source four TTL inputs. When 1s are written to port 1
pins are pulled high by the internal pull-ups and can be used
as inputs.

Can be used as a general purpose 8 bit port when no


external memory is present, but if external memory access is
required then PORT P2 will act as an address bus in
conjunction with PORT P0 to access external memory. PORT
P2 acts as A8-A15.

Acts as a normal IO port, but this port has additional


functions such as serial transmit and receive pins, 2 external
interrupt pins, 2 external counter inputs, read and write pins
for memory access.

12

INTEL 8255
INTRODUCTION
The Intel 8255 Programmable Peripheral Interface (PPI) chip is a peripheral chip
originally developed for the Intel 8085 microprocessor, and as such is a member of a
large array of such chips, known as the MCS-85 Family. This chip was later also used
with the Intel 8086 and its descendants. It was later made (cloned) by many other
manufacturers.
The Intel 8255 is a general purpose programmable I/O device which is designed for use
with all Intel and most other microprocessors. It provides 24 I/O pins which may be
individually programmed in 2 groups of 12 and used in 3 major modes of operation.
In MODE 0, each group of 12 I/O pins may be programmed in sets of 4 and 8 to be
inputs or outputs. In MODE 1, each group may be programmed to have 8 lines of input
or output. 3 of the remaining 4 pins are used for handshaking and interrupt control
signals. MODE 2 is a strobe bi-directional bus configuration.
The 8255 is a 40 pin integrated circuit (IC), designed to perform a variety of interface
functions in a computer environment. The 8255 wasn't originally designed to be
connected to the Z80. It was manufactured by Intel for the 8080 microprocessor.

APPLICATION
The 8255 is widely used not only in many microcomputer/microcontroller systems
especially Z-80 based, home computers such as SV-328 and all MSX, but also in the
system board of the best known original IBM-PC.

13

8255 PIN DIAGRAM AND DESCRIPTION

PIN

FUNCTION

D0-D7

These are the data input/output lines for the device.


All information read from and written to the 8255 occurs via
these 8 data lines.

CS
(CHIP SELECT
INPUT)

If this line is a logical 0, the microprocessor can read and write


to the 8255.

RD
(READ INPUT)

Whenever this input line is a logical 0 and the RD input is a


logical 0, the 8255 data outputs are enabled onto the system
data bus.

WR
(WRITE
INPUT)

Whenever this input line is a logical 0 and the CS input is a


logical 0, data is written to the 8255 from the system data bus.

A0-A1
(ADDRESS
INPUT)

The logical combination of these two input lines determines


which internal register of the 8255 data is written to or read
from.
14

RESET

PA0-PA7,
PB0-PB7 &
PC0-PC7

The 8255 is placed into its reset state if this input line is a logical
1.
All peripheral ports are set to the input mode.

These signal lines are used as 8-bit I/O ports.


They can be connected to peripheral devices.
The 8255 has three 8 bit I/O ports and each one can be
connected to the physical lines of an external device.
These lines are labeled PA0-PA7, PB0-PB7, and PC0-PC7.
The groups of the signals are divided into three different I/O
ports labeled port A (PA), port B (PB), and port C (PC).

8255 BLOCK DIAGRAM

15

Two control groups, labeled group A control and group B control define how the
three I/O ports operate.
There are several different operating modes for the 8255 and these modes must
be defined by the CPU writing programming or control words to the device 8255.
The line group of port C consists of two 4 bit ports.
One of the 4 bit group is associated with group A control and the other 4 bit
group with group B control device signals.
The upper 4 bits of port C are associated with group A control while the lower 4
bits are associated with group B control.
The final logic blocks are read/write control logic and data bus buffer.
These blocks provide the electrical interface between the Z80 and the 8255.
The data bus buffer buffers the data I/O lines to/from the Z80 data bus.
The read/write control logic routes the data to and from the correct internal
registers with the right timing.
The internal path being enabled depends on the type of operation performed by
the Z80.
The type of operation can be I/O read or I/O write.

16

SCHEMATIC DIAGRAM

17

Flow Chart
Start
Switch off the buzzer

Switch off all the LEDs and 7-segments

Check all the switches

Is one of the switches being pressed?

No

Yes

The corresponding LED is turned on and the


corresponding number is displayed on the 7 - Segment

The buzzer is triggered to indicate one of the switches is pressed


Keypad is be used to set the time given for answering the question

A countdown switch has to be pressed to


start the countdown of the time given

Answers within the time given


Yes

Reset Switch is pressed

No

The buzzer is triggered to


indicate the time is up

18

Flow Chart of the Program Code


Start

Declare the type of


microprocessor

Insert the starting address for user

Insert data of 030H to the stack pointer

Declare the ports of 8255 PPI

Control word 10000001 is


sent to the control register
to configure the PPI of 8255

CLEAR

Move 0 to accumulator

Move the data in accumulator to Port A and Port B.

ACALL DELAY

START
19

START

Set all Upper Port C to High

Read data from Lower Port C to Accumulator

AND with 00001111B

A=0
A=0?

A 0
DISPLAY1

A 01H
A=01H?

DISPLAY2

A = 01H
Move data 06H to Accumulator

Data is sent from Accumulator to Port A

BUZZER1

20

DISPLAY2

A 02H
DISPLAY3

A=02H?

A = 02H
Move data 5BH to Accumulator

Data is sent from Accumulator to Port A

BUZZER1

DISPLAY3

A 04H
A=04H?

DISPLAY4

A = 04H
Move data 4FH to Accumulator

Data is sent form Accumulator to Port A

BUZZER1

21

DISPLAY4

Move data 66H to Accumulator

Data is sent from Accumulator to Port A

BUZZER1

BUZZER1

Move data from Accumulator to R5

ADD with 10000000B

Data is sent from Accumulator to Port A

ACALL DELAY

Move data from R5 to Accumulator

Data is sent from Accumulator to Port A

NOP

SCAN
22

SCAN

Set PC4-PC6 to High

Read data from Lower Port C to Accumulator


AND with 00001111B

A=0

A=0?

A0
Move data 3 to R6

Move data 00010000B to R7

SCAN_NEXT

SCAN _NEXT

Move data from R7 to Accumulator

Data is sent from Accumulator to Port C

Read data from Port C to Accumulator

AND with 00001111B

A=0
A=0?

NEXT_COL

A0
OR with R7
23
S0

S0

Compare with 28H


A = 28H ?

A 28H

S1

A = 28H
Move data 01H to Accumulator
Store data from Accumulator to address 2100H

Move data 3FH to Accumulator

Data is send from Accumulator to Port B

PRESS

S1

Compare with 11H


A = 11H ?

A 11H
S2

A = 11H
Move data 02H to Accumulator

Store data from Accumulator to address 2100H

Move data 06H to Accumulator

Data is send from Accumulator to Port B

PRESS

24

S2

Compare with 21H


A = 21H ?

A 21H
S3

A = 21H
Move data 03H to Accumulator

Store data from Accumulator to address 2100H

Move data 5BH to Accumulator

Data is send from Accumulator to Port B

PRESS

S3

Compare with 41H


A = 41H ?

A 41H
S4

A = 41H
Move data 04H to Accumulator

Store data from Accumulator to address 2100H

Move data 4FH to Accumulator

Data is send from Accumulator to Port B

PRESS

25

S4

Compare with 12H


A = 12H ?

A 12H
S5

A = 12H
Move data 05H to Accumulator

Store data from Accumulator to address 2100H

Move data 66H to Accumulator

Data is send from Accumulator to Port B

PRESS

S5

Compare with 22H


A = 22H ?

A 22H
S6

A = 22H
Move data 06H to Accumulator

Store data from Accumulator to address 2100H

Move data 6DH to Accumulator

Data is send from Accumulator to Port B

PRESS

26

S6

Compare with 42H


A = 42H ?

A 42H
S7

A = 42H
Move data 07H to Accumulator

Store data from Accumulator to address 2100H

Move data 7DH to Accumulator

Data is send from Accumulator to Port B

PRESS

S7

Compare with 14H


A = 14H ?

A 14H
S8

A = 14H
Move data 08H to Accumulator

Store data from Accumulator to address 2100H

Move data 07H to Accumulator

Data is send from Accumulator to Port B

PRESS

27

S8

Compare with 24H


A = 24H ?

A 24H
S9

A = 24H
Move data 09H to Accumulator

Store data from Accumulator to address 2100H

Move data 7FH to Accumulator

Data is send from Accumulator to Port B

PRESS

S9

Compare with 44H


A = 44H ?

A 44H
SCAN

A = 44H
Move data 01H to Accumulator

Store data from Accumulator to address 2100H

Move data 3FH to Accumulator

Data is send from Accumulator to Port B

PRESS

28

PRESS

Move data 10000000B to Accumulator

Data is sent from Accumulator to Port C

Read data from Port C to Accumulator

AND with 00000001B

A=0

A=0?

A =1
PRESS1

Move data 10000000B to Accumulator

Data is sent from Accumulator to Port C

Read data from Port C to Accumulator

AND with 00000001B

A=1

A=0?

A =0
COUNT
29

COUNT

Move data from address 2100H to Accumulator

Move data from Accumulator to R0 and R1

NEXT

Load Data Pointer with 16-bit constant (#TABLE)

Decrement R0

Move data from R0 to Accumulator

Move code byte relative to Data Pointer to Accumulator

Data is sent from Accumulator to Port B

ACALL DELAY

Decrement R1

R1=0?
?

R1 0

RESET

R1 = 0

BUZZER2
30

RESET

Move data 10000000B to Accumulator

Data is sent from Accumulator to Port C

Read data from Port C to Accumulator

AND with 00000001B

A=0
A=0?

NEXT

A0
RESET1

Move data 10000000B to Accumulator

Data is sent from Accumulator to Port C

Read data from Port C to Accumulator

AND with 00000001B

A0

A=0?

A=0
CLEAR
31

BUZZER2

Move data 10000000B to Accumulator

Data is sent from Accumulator to Port A

ACALL DELAY

CLEAR

32

Problem Statement and Analysis


Problem 1:
When we use the program code LJMP or SJMP to
jump to some specific function, we found out that the codes cannot
operate because it is out of the specific bit range and this causes errors
when we generate the HEX file by using Command Prompt.
Solution:
We add an extra loop JUMP: LJMP rel in between the
codes LJMP rel and the specific function so that the program code
can operate in specific bit range as it will jump to the extra loop first
before jumping to the specific function.

Problem 2:
When we use the upper output Port C (PC4-PC7) to
produce current to flow through the resistor for the detection of signal
of lower input Port C (PC0-PC3), we notice that the pin PC4 do not
produce enough current flow through the resistor and hence the lower
input Port C cannot detect the signal with the low potential difference
across the resistor.
Solution:
We program to use Port B PB7 which is not used originally
to produce a current to flow through the resistor so that now there is
enough current flow through the resistor and higher potential difference
across the resistor for the signal detection of lower input Port C.

33

Result

When one of the switches of the participants is pressed, the


corresponding number which represents the participant which be
displayed on a 7 segment and the buzzer will be triggered to indicate
one of the switches is pressed. Then, a keypad is used to set the time
given for the participant to answer a quiz question and it will be
displayed on the timer 7-segment display. A countdown switch (reset
switch) can be used to start the countdown of the timer. When the time
given is over, the buzzer will be triggered to indicate the time given is
over. Then, the circuit will be automatically reset by itself. If the
participant can answer the question within the time given, the reset
switch can be pressed to reset the system to the beginning stage.

34

Discussion
For the design of the circuit connections, we have to
consider the amount of components that we use and also the total
number of pins of the components needed to be connected to the
Programmable Peripheral Interface 8255 since there are only 3 8-bits
ports (Port A, Port B and Port C) which have only total of 24 pins can
be used for connection. Since we are using two 7-Segment Displays in
this circuit with each of them has 7 pins need to be connected to the 8bits output Port A and Port B, the only port left is Port C which can be
separately programmed as input and output (input PC0-PC3, output
PC4-PC7). Thus, we have no choice but to design the circuit
connections with the reset switch, LED, participants number
representative switches, resistors as well as keypad all connected to
Port C. Lastly, the buzzer is connected to the Port A (PA7) which is the
only pin left for connection. After the design of the circuit connection,
we can start to write the assembly code for the function of our circuit so
that it can function as a general electronic quiz system without error.
Other than that, since we are using time delay with the
software delay instead of the internal timer of microprocessor 8051, we
have to calculate the time delay of around 1 second for every Absolute
Call DELAY (ACALL) with the formula:
Delay = [1 + (R2){1 + (R3)[1 + (R4)(2) + 2] + 2} + 2] x 1/(

= [1 + (7){1 + (255)[1 + (255)(2) + 2] + 2} + 2] x 1/(

= 0.9936 s
1.0 s

35

Conclusion:
The assembly program and the circuit design can be used in
any general quiz competition with the function that who has pressed the
switch first and the number which represents the corresponding
participant will be displayed on a 7-segment display. Different time
given to answer the questions can be set and displayed on another 7segment display by using a keypad. A switch (which is also the RESET
switch) can be used to start the countdown of the timer. If the question
is not answered within the time given, the circuit will be reset. If the
question is answered within the time given, the RESET switch to stop
the countdown timer and the circuit will be reset to the beginning stage.
In conclusion, we have gained more knowledge regarding the
microprocessor 8051 through this mini project. We have learnt to
interface the Microprocessor 8051with PPI 8255, keypad, 7-segment
displays, and switches. Thus, microprocessor 8051 interfaced with PPI
8255 can be used to produce an electronic quiz system which can be
used for any general quiz competition.

36

Appendix
Assembly Program Code:
CPU"8051.TBL"
INCL"8051.INC"
ORG 2000H
MOV SP, #030H
PA: EQU 4000H
PB: EQU 4001H
PC: EQU 4002H
PCTR: EQU 4003H
MOV A, #10000001B
MOV DPTR, #PCTR
MOVX @DPTR, A

; Declaration for microprocessor 8051


; Declaration of type of microprocessor
; Starting address for user
; Stack pointer address
; Declaration for Port A
; Declaration for Port B
; Declaration for Port C
; Declaration for Control Port
; Data 10000001B is moved into accumulator
; Load Data Pointer with Control Port
; Move A to external RAM

; = = = = = = = = = = CLEAR ALL THE OUTPUTS OF THE SYSTEM = = = = = = = = = = = = = =


CLEAR: MOV A, #00H
MOV DPTR, #PA
MOVX @DPTR, A
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
ACALL DELAY
ACALL DELAY

; Data 00H is moved in to accumulator


; Load Data Pointer with Port A
; Move A to external RAM
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Absolute call DELAY
; Absolute call DELAY

; = = = = = = = = = = = = = = = CHECK ALL THE SWITCHES = = = = = = = = = = = = = = = = = =


START: MOV A, #11110000B
MOV DPTR, #PC
MOVX @DPTR, A
MOV A, #10000000B
MOV DPTR, #PB
MOVX @DPTR, A
MOV DPTR, #PC
MOVX A, @DPTR
ANL A, #00001111B
JZ START

; Data 11110000B is moved to accumulator


; Load Data Pointer with Port C
; Move A to external RAM
; Data 10000000B is moved to accumulator
; Load Data Pointer with Port B
; Move A to external RAM
; Load Data Pointer with Port C
; Move external RAM to A
; AND 00001111B to A
; Jump to START if A is zero

; = = = = = = = = DISPLAY THE CORRESPONGDING NUMBER OF THE SWITCH = = = = = = =


DISPLAY1: CJNE A, #01H, DISPLAY2
MOV A, #06H
MOV DPTR, #PA
MOVX @DPTR, A
SJMP BUZZER1

; Compare A with 01H and jump to DISPLAY2 if not equal


; Data 06H is moved to A
; Load Data Pointer with Port A
; Move A to external RAM
; Jump to BUZZER1

37

DISPLAY2: CJNE A, #02H, DISPLAY3


MOV A, #5BH
MOV DPTR, #PA
MOVX @DPTR, A
SJMP BUZZER1

; Compare A with 02H and jump to DISPLAY3 if not equal


; Data 5BH is moved to A
; Load Data Pointer with Port A
; Move A to external RAM
; Jump to BUZZER1

DISPLAY3: CJNE A, #04H, DISPLAY4


MOV A, #4FH
MOV DPTR, #PA
MOVX @DPTR, A
SJMP BUZZER1

; Compare A with 04H and jump to DISPLAY4 if not equal


; Data 4FH is moved to A
; Load Data Pointer with Port A
; Move A to external RAM
; Jump to BUZZER1

DISPLAY4: MOV A, #66H


MOV DPTR, #PA
MOVX @DPTR, A
SJMP BUZZER1

; Data 6H is moved to A
; Load Data Pointer with Port A
; Move A to external RAM
; Jump to BUZZER1

; = = = = = = = = = = = = = = = TRIGGER THE BUZZER FOR 1 SECOND = = = = = = = = = = = = = = =


BUZZER1: MOV R5, A
ADD A, #10000000B
MOV DPTR, #PA
MOVX @DPTR, A
ACALL DELAY
MOV A, R5
MOV DPTR, #PA
MOVX @DPTR, A
NOP

; Move A to R5
; Add 10000000B to A
; Load Data Pointer with Port A
; Move A to external RAM
; Absolute call DELAY
; Move R5 to A
; Load Data Pointer with Port A
; Move A to external RAM
; No operation

; = = = = = = = = = = = = = = = = = = = SCAN THE KEYPAD = = = = = = = = = = = = = = = = = = = =


SCAN: MOV A, #01110000B
MOV DPTR, #PC
MOVX @DPTR, A
MOV DPTR, #PC
MOVX A, @DPTR
ANL A, #00001111B
JZ SCAN
MOV R6, #3
MOV R7, #00010000B

; Data 01110000B is moved to A


; Load Data Pointer with Port C
; Move A to external RAM
; Load Data Pointer with Port C
; Move external RAM to A
; AND 00001111B to A
; Jump to SCAN if A is zero
; Data 3 is moved to R6
; Data 00010000B is moved to R7

38

SCAN_NEXT: MOV A, R7
MOV DPTR, #PC
MOVX @DPTR, A
MOV DPTR, #PC
MOVX A, @DPTR
ANL A, #00001111B
JZ NEXT_COL
ORL A, R7
LJMP S0

; Move R7 to A
; Load Data Pointer with Port C
; Move A to external RAM
; Load Data Pointer with Port C
; Move external RAM to A
; AND 00001111B to A
; Jump to NEXT_COL if A is zero
; OR R7 to A
; Jump to S0

; = = = = = = = = = = = SUBROUNTINE TO STORE DATA TO MEMORY 2100H = = = = = = = = = =


STORE: MOV DPTR, #2100H
MOVX @DPTR, A
RET

; Load Data Pointer with address 2100H


; Move A to external RAM
; Return from subroutine

NEXT_COL: MOV A, R7
RL A
MOV R7, A
DEC R6
MOV A, R6
JNZ SCAN_NEXT

; Move R7 to A
; Rotate A left
; Move A to R7
; Decrement R6
; Move R6 to A
; Jump to SCAN_NEXT if A is not zero

; = = = = = = = = = = = = = = DISPLAY THE TIME GIVEN ON 7-SEGEMTN = = = = = = = = = = = = =


S0: CJNE A, #28H, S1
MOV A, #01H
ACALL STORE
MOV A, #3FH
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 28H and jump to S1 if not equal


; Data 01H is moved to A
; Absolute call STORE
; Data 3FH is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

S1: CJNE A, #11H, S2


MOV A, #02H
ACALL STORE
MOV A, #06H
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 11H and jump to S2 if not equal


; Data 02H is moved to A
; Absolute call STORE
; Data 06H is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

39

S2: CJNE A, #21H, S3


MOV A, #03H
ACALL STORE
MOV A, #5BH
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 21H and jump to S3 if not equal


; Data 03H is moved to A
; Absolute call STORE
; Data 5BH is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

S3: CJNE A, #41H, S4


MOV A, #04H
ACALL STORE
MOV A, #4FH
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 41H and jump to S4 if not equal


; Data 04H is moved to A
; Absolute call STORE
; Data 4FH is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

S4: CJNE A, #12H, S5


MOV A, #05H
ACALL STORE
MOV A, #66H
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 12H and jump to S5 if not equal


; Data 05H is moved to A
; Absolute call STORE
; Data 66H is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

JUMP: LJMP SCAN

; Jump to SCAN

S5: CJNE A, #22H, S6


MOV A, #06H
ACALL STORE
MOV A, #6DH
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 22H and jump to S6 if not equal


; Data 06H is moved to A
; Absolute call STORE
; Data 6DH is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

40

S6: CJNE A, #42H, S7


MOV A, #07H
ACALL STORE
MOV A, #7DH
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 42H and jump to S7 if not equal


; Data 07H is moved to A
; Absolute call STORE
; Data 7DH is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

S7: CJNE A, #14H, S8


MOV A, #08H
ACALL STORE
MOV A, #07H
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 14H and jump to S8 if not equal


; Data 08H is moved to A
; Absolute call STORE
; Data 07H is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

S8: CJNE A, #24H, S9


MOV A, #09H
ACALL STORE
MOV A, #7FH
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 24H and jump to S9 if not equal


; Data 09H is moved to A
; Absolute call STORE
; Data 7FH is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

S9: CJNE A, #44H, JUMP


MOV A, #0AH
ACALL STORE
MOV A, #67H
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
LJMP PRESS

; Compare A with 44H and jump to JUMP if not equal


; Data 0AH is moved to A
; Absolute call STORE
; Data 67H is moved to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Jump to PRESS

; = = = = = = = = = = = = START THE COUNTDOWN USING THE RESET SWITCH = = = = = = = = =


PRESS: MOV A, #10000000B
MOV DPTR, #PC
MOVX @DPTR, A
MOV DPTR, #PC
MOVX A, @DPTR
ANL A, #00000001B
JZ PRESS

; Data 10000000B is moved to A


; Load Data Pointer with Port C
; Move A to external RAM
; Load Data Pointer with Port C
; Move external RAM to A
; AND 00000001B to A
; Jump to PRESS if A is zero

41

PRESS1: MOV A, #10000000B


MOV DPTR, #PC
MOVX @DPTR, A
MOV DPTR, #PC
MOVX A, @DPTR
ANL A, #00000001B
JNZ PRESS1

; Data 10000000B is moved to A


; Load Data Pointer with Port C
; Move A to external RAM
; Load Data Pointer with Port C
; Move external RAM to A
; AND 00000001B to A
; Jump to PRESS1 if A is not zero

COUNT: MOV DPTR, #2100H


MOVX A, @DPTR
MOV R0, A
MOV R1, A
SJMP NEXT

; Load Data Pointer with address 2100H


; Move external RAM to A
; Move A to R0
; Move A to R1
; Jump to NEXT

; = = = = = = = = = = = = = = = = = CHECK THE RESET SWTICH = = = = = = = = = = = = = = = = =


RESET: MOV A, #10000000B
MOV DPTR, #PC
MOVX @DPTR, A
MOV DPTR, #PC
MOVX A, @DPTR
ANL A, #00000001B
JZ NEXT

; Data 10000000B is moved to A


; Load Data Pointer with Port C
; Move A to external RAM
; Load Data Pointer with Port C
; Move external RAM to A
; AND 00000001B to A
; Jump to NEXT if A is zero

RESET1: MOV A, #10000000B


MOV DPTR, #PC
MOVX @DPTR, A
MOV DPTR, #PC
MOVX A, @DPTR
ANL A, #00000001B
JNZ RESET1
LJMP CLEAR

; Data 10000000B is moved to A


; Load Data Pointer with Port C
; Move A to external RAM
; Load Data Pointer with Port C
; Move external RAM to A
; AND 00000001B to A
; Jump to RESET1 if A is not zero
; Jump to CLEAR

NEXT: MOV DPTR, #TABLE


DEC R0
MOV A, R0
MOVC A, @A+DPTR
MOV DPTR, #PB
MOVX @DPTR, A
ACALL DELAY
DJNZ R1, RESET

; Load Data Pointer with TABLE


; Decrement R0
; Move R0 to A
; Move code byte relative to Data Pointer to A
; Load Data Pointer with Port B
; Move A to external RAM
; Absolute call DELAY
; Decrement R1 and jump to RESET if not zero

42

; = = = = = = = = = = = = = = = TRIGGER THE BUZZER IF TIME IS OUT = = = = = = = = = = = = = =


BUZZER2: MOV A, #10000000B
MOV DPTR, #PA
MOVX @DPTR, A
ACALL DELAY
LJMP CLEAR

; Data 10000000B is moved to A


; Load Data Pointer with Port A
; Move A to external RAM
; Absolute call DELAY
; Jump to CLEAR

; = = = = = = = = = = = = = = = = = TIME DELAY OF 1 SECOND = = = = = = = = = = = = = = = = = =


DELAY: MOV R2, #07H
LOOP: MOV R3, #255
LOOP1: MOV R4, #255
LOOP2: DJNZ R4, LOOP2
DJNZ R3, LOOP1
DJNZ R2, LOOP
RET

; Move data 07H to R2


; Move data 255 to R3
; Move data 255 to R4
; Decrement R4 and jump to LOOP2 if not zero
; Decrement R3 and jump to LOOP1 if not zero
; Decrement R2 and jump to LOOP if not zero
; Return from subroutine

; = = = = = = = = = = = = HEXADECIMAL FOR 7- SEGMENT DISPLAY = = = = = = = = = = = = = =


TABLE: DFB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 67H

;Define bit for 16-bit constant

END

Electronic quiz device that our group has designed and programed
43

Reference
1. http://www.slideshare.net/SubhashiniSundaram/micro-processormini-project
2. http://en.wikipedia.org/wiki/Light-emitting_diode
3. http://en.wikipedia.org/wiki/Keypad
4. https://www.sparkfun.com/products/97
5. http://en.wikipedia.org/wiki/Intel_8255
6. http://www.electronics.dit.ie/staff/tscarff/8255PPI/8255.htm
7. http://www.circuitstoday.com/8051-microcontroller
8. http://en.wikipedia.org/wiki/Intel_MCS-51
9. http://jap.hu/electronic/8255.pdf

44

Das könnte Ihnen auch gefallen