MICROCONTROLLER INTERFACING AND APPLICATION
WONG HOONG BOK
ý
a mka
wt y
> ý..
TJ 223
P76 N872
tNIMý
Universiti Malaysia Sarawak
2002
MICROCONTROLLER INTERFACING AND APPLICATION
WONG HOONG BOK
'"LAYS
ý
"L `ý
. 6IV _m Aý 'V K.
Universiti Malaysia Sarawak
2002
Borang Penyershan Tesis Universitf Malaysia Sarawak
R13a
BORANG PENYERAHAN THESIS
Judul: MICROCONTROLLER INTERFACING AND APPLICATION
SESI PENGAJIAN: 2001/2002
Saya WONG HOONG ROK
(HURUF BESAR)
mengaku membenarkan tesis ini disimpan di Pusat Khidmat Maklumat Akademik, Universiti Malaysia Sarawak dengan syarat-syarat kegunaan seperti berikut:
1. Hakmilik kertas projek adalah di bawah nania penulis melainkan penulisaa sebagai projek bersama dan dibiayai oleh UNIMAS, halaniliknya adalah kepunyaan UNIMAS.
2. Naskhah salinan di daiwm bentuk kertas atau mikro hanya botch dibuat dengan kebenaran bertulis daripada penulis.
3. Pusat Khidmat Maklumat Akademik, UNIMAS dibenarkan membuat salinan untuk pengajian mereka.
4, Kertas projek hanya boleh diterbitkan dengan kebonaran penulis. Bayaran royalti adalah mengikut kadar yang dipersetujui kelak.
5. * Saya membenarkan/tidak membenarkan Perpustakaan membuat satinan kertas projek ini sebagai bahan pertukaran di antara institusi pengajian tinggi.
6. ** Sila tandakan ()
I
0
LJ
SULIT (Mengandungi maklumat yang berdaijah keselamatan stau kepentingan
Malaysia seperti yang termaktub di dalam AKTA RAHSIA RASMI 1972) TERHAD (Mengandungi maldumat TERHAD yang telah ditentukan oleh orgauisasi/
badan di mana penyelidikan dijalankan) TIDAK TERHAD
L
ýv ti(TANDAT Aý
f:
Alamat Tetap: 3305_ DdM STREET.
JINJANG UTARA, 52000, K. L WILAYAH PERSEKUTUAN
Disahken oleh
EN. MARTIN ANYI
Nama Penydia
Tarikh: 3 APRIL 2002 Tarikh: 3
,R 200 CATATAN *
ss
Potong yang tidek berkenaan
Jika kertas Projek ini SULIT atau TERHAD, sila lampirkan surat daripada pihak berkuasa/
organisasi berkenaan dengan menyertakan seJcali tempoh kertas projek. Ini perhi dikelaskan sebagai SULIT atau TERHAD.
SUPERVISOR'S CERTIFICATION
After having read this thesis paper prepared by WONG HOONG BOK entitled MICRCONTROLLER INTERFACING AND APPLICATION, this supervisory camp is satisfied with the thesis papers a fulfillment for the award of a bachelor's degree with Honours in Electronic and Telecommunication Engineering
/v'- ate
MICROCONTROLLER INTERFACING AND APPLICATION
WONG HOONG BOK
Tesis Dikemakakan Kepada
Fakulti Kejuruteraan, Universiti Malaysia Sarawak Sebagai Memenuhi Sebahagian daripada Syarat
Penganugeraban Sarjana Muda Kejuruteraan
Dengan Kepujian (Kejuruteraan Elektronik dan Telekomunikasi)
2002
To my Beloved Family
ACKNOWLEDGEMENT
First and foremost I would like to express my gratitude to everyone who directly and indirectly given me assistance through out the project. My heartfelt thanks to MK Martin Anyi, my supervisor, for giving me endless guidance and assistance during the
whole project.
My deepest thanks to my family for their love, encouragement and support that they have given me throughout the whole process.
Not forgotten, thanks to my colleagues and friends, Mr. Chua Tiong Chong, Mr. Tan Boon Kau, Mr. Francis Liew which giving their helping hands when I face the difficulty
in my project. In additional, a special thanks also to Mr. Zakaria for providing the necessary electronic components and testing tools for doing this project.
Finally, my deepest gratitude goes out to all the Lecturers of the Faculty of Engineering from whom I have gained much knowledge and experience. Not forgetting my dearest friends who have given me the moral support, encouragement, assistance and comfort that I needed during these three years here. To them, I wish the best of luck and may the future hold bright for you all
i
ABSTRACT
Microcontroller has been played a vital role in our daily life over the past 25 years.
Today in our life, most of the devices were powered by microcontroller. It takes part in controlling, data storing, and human interaction that granted limited intelligence to the
most of the devices. It is without doubt that life without microcontroller is just like living in the Dark Age. In most of the automobiles, fuel level has been displayed using an analog meter, which proved not to be so efficient and accurate. So microcontroller is been used to display the fuel level digitally on the LCD panel in this project. It provides higher accuracy in displaying the amount of fuel left in the tank and informs the user of how far the vehicle can go with those certain of fuel level. Data can be displayed clearly on the LCD panel and beep sound to inform the driver when the fuel level is low. In the future, most of the automobile will be equipped with digital devices, especially on the gauge devices. Accuracy will be in demand and this project would be the stepping-stone for creation of a fully digital automobile in the near future.
11
ABSTRAK
Microcontroller telah memainkan peranan yang amat penting dalam kehidupan kita sejak 25 tahun dahulu lagi. Hari ini dalam kehidupan kita, kebanyakan perkakas elektronik dikuasai oleh microcontroller. la mengambil bahagian dalam aktiviti pengawalan, penyimpanan data, interaksi manusia yang memberikan kebijaksanaan yang terhad kepada kebanyakan perkakas. Tanpa microcontroller hidup kita bagaikan dalam zaman gelap. Kebanyakan kenderaan masa kini menggunakan meter petrol secara analog yang mana tidak begitu tepat dan efisien. Jadi microcontroller digunakan dalam
projek ini untuk memaparkan kandungan petrol dalam tangki kenderaan secara digital diatas skrin LCD. la membekalkan ketepatan yang lebih tinggi dalam memaparkan jumlah baki kandungan petrol dalam tangki clan memberitahu pengguna kenderaan
tentang jarak kejauhan yang boleh dicapai dengan menggunakan baki kandungan petrol tersebut. Data dapat terpapar dengan jelas di atas skrin LCD dan mengeluarkan bunyi beep untuk memberitahu pengguna apabila bald kandungan petrol berada di tahap rendah. Pada masa hadapan, kebanyakan kenderaan akan dilengkapi dengan dengan peralatan digital terutamanya dalam penggunaan alat pengukuran. Ketepatan adalah amat penting dan projek ini menjadi satu batu lonjatan untuk mereka kenderaan penuh digital pada masa akan datang.
111
TABLE OF CONTENTS
CHAPTER NO. CONTENTS
ACKNOWLEDGEMENT ABSTRACT
ABSTRAK
TABLE OF CONTENTS LIST OF TABLES
LIST OF FIGURES
ONE
INTRODUCTION1.1 Introduction
1.1.1 Microcontroller 1.2 Objectives
1.3 Project Overview
PAGE.
1
ll
111
iv
ix
X
I I I
3
4
iv
TWO
The Hardware Reviews 2.0 Introduction2.1 Intel Microcontroller -- 80C3 1 BH 2.1.1 Introduction
2.1.2 Architecture 2.1.3 Port 0
2.1.4 Port 1 2.1.5 Port 2
2.1.6 Port 3
2.1.7 Program Store Enable 2.1.8 Address Latch Enable 2.1.9 External Access
2.1.10 Reset
2.1.11 Oscillator and Clock 2.1.12 Power Connections
2.1.13 Special Function Register
2.1.14 Program Counter and Data Pointer 2.1.15 A and B CPU Registers
2.1.16 Program Status Word
2.1.17 The Stack and the Stack Pointer 2.1.18 Timer Register
2.1.19 Timer Register
2.1.20 Power Control Register
5 5 6 6 6 6
9
9 9 10 11
11
11
12
12
12
14
14
15
17
17 17 18
V
2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.26
Internal RAM
External Memory
Accessing External Code Memory Accessing External Data Memory
Counters and Timers
Timer Counter Interrupt
18 21 22 22 22 23
2.1.27 Timing 23
2.2 Comparison Between Microcontroller and 24 Microprocessor
2.2.1 Hardware Architecture 24
2.2.2 Application 26
2.2.3 Instruction Set Features 26
2.3 Liquid Crystal Display 28
2.3.1 Introduction 28
2.3.2 Alphanumerical LCD 28
2.3.3 LCD Hardware Description 31
2.3.4 Function Description 33
2.3.5 Graphic LCDs 34
2.4 Fuel Level System 37
2.4.1 Introduction 37
2.4.2 Operation of the Fuel Level Mechanism 37
V1
THREE
FOUR
Design and Implementation 3.1 Introduction
3.2 Hardware Design
3.2.1 Input (Fuel Level Mechanism) 3.2.2 Analog to Digital Converter
3.2.3 Introduction
3.2.4 The Specification of the ADC 0804 pins 3.2.5 Operation of the ADC 0804
3.2.6 The Ideal Transfer Functions
3.3 80C31 Microcontroller Design 3.3.1 Introduction
3.3.2 Reset and Clock Circuit 3.3.3 External Memory
3.4 Output: LCD Board
3.5 Software Development
Results and Discussions 4.1 Introduction
4.2 Software Setup and Testing 4.3 Testing on ADC IC
4.4 Testing on the Real Fuel Mechanism
4.5 Testing on the Digital Fuel Level Display System 4.6 Conclusion
40
40
40
41
41 41 42
43
45
47 47
47 47 52
55
62
62 63 65
66
67 68
vii
FIVE
Conclusion and Recommendation 5.1 Conclusion5.2 Recommendation
69 69
71
REFERENCES 72
APPENDIX
viii
Table 2.1
2.2
2.3
2.4
LIST OF TABLES
Alternate Pin Functions for Port Pins Special Function Register
The Program Status Word (PSW) Hardware Description of LCD
ix
Page
10
13
16
33
LIST OF FIGURES
Figure
1.0 A Block Diagram of a Microcontroller 1.1 Concept of the Project
2.1 80C31BH Architecture Block Diagram 2.2 Oscillator Circuit
2.3 Internal RAM Organization 2.4 Accessing External Memory
2.5 Internal Operation of Timer
2.6 Architecture of Microcontroller and Microprocessor 2.7 Resolution of the LCD
2.8 Architecture of the Alphanumerical LCD 2.9 Architecture of the Graphical LCD
2.10 Difference Resolution of Graphical LCD 2.11 Architecture of Fuel Mechanism System 3.0 Pin Assignment of ADC 0804 Chip
3.1 The Ideal Transfer Function (ADC)
3.2 Connections between Microcontroller and EPROM
Page
3 4
8
12 20 21 24 25
29
30 35
36
38 42 46
51
X
3.3 Connections between Microcontroller and LCD 3.4 Standard LCD Table
4.1 Circuitry of ADC
4.2 Fuel Level Mechanisms 4.3 Fuel Display System
53
54 66 67 67
I
xi
Chapter 1
Introduction
1.1 Introduction
This project discusses the used of Microcontroller 80C31 in interfacing-with LCD and apply in displaying the fuel level in the vehicle. This project will review the usefulness and powerfWness of the microcontroller in most of the devices in the world nowadays. So this project will concern about the design,
construction and testing of the Mic rocontroller 80C31 with LCD display and applied it based to the needs of users.
1.1.1 Microcontroller
Microcontroller is acting as a computer on a single integrated circuit. Its structure and designs incorporates all of the features found in a microprocessor central processing unit (CPU), such as arithmetic and logic unit (ALU), a program counter (PC), a stack pointer (SP), and some working registers. Microcontroller also has added other features needed to make a
n
1
complete computer, which are read only program memory (ROM), random access data memory (RAM), parallel I/O, serial I/O, counters and a clock
circuit. All those features are fabricated into a single integrated circuit before implemented on any machine to perform control-oriented activities.
Besides functioning as a general purpose device, which is meant to read data, perform limited calculations on that data, and control its environment based
on those calculations. The prime application of the microcontroller is to control the operation of a machine using a fixed program that is stored in
ROM and that will not change forever. Microcontroller uses very limited set of single- and double-byte instructions for operations. Many instructions are coupled with pins on the integrated circuit package, and the pins are programmable (by software programs) for capabilities of having several
different functions depend on the users.
Microcontrolier become an industry standard in control-oriented applications.
Nowadays, micro-controller could be found in for various applications in the field of electronics and mechanical such as in automobiles, industrial
equipments, consumer entertainment products, computer peripherals and etc.
4
2
ALU
Accumulator Register(s)
Internal RAM
Stack Pointer
Timer/cmmter
Internal ROM
Program Counter
I UO
Port
UO Port
Interrupt Circuit
Clock Circuit
Fig. 1.0 A block diagram of a microcontroller
1.2 Objectives
The objectives of this project are:
" To learn and understand the power and applications of Microcontroller 80C31.
" To interface Microcontroller 80C31 with the LCD (liquid crystal display) display for displaying message and graphic.
" To create software to support microcontroller 80C31 system and operation.
" To analyze the fuel level mechanism in the vehicle
" To display the fuel level in the vehicle on the LCD display board.
3
1.3 Project Overview
The purpose of this project is to display the fuel level in the vehicle by using an input that varied in voltage on the LCD display panel.
The block diagram below shows the concept how the project will be carried.
Car Fuel
Mechanism (Variation of
Voltage)
Analog to Digital
Converter
LCD Display Board
Micxoaxitroller 8031
Figure 1.1 Concept of the project
4
Chapter 2
The Hardware Reviews
2.0 Introduction
This chapter will review the hardware used in interfacing the microcontroller 80031 with the LCD with the use of fuel level mechanism as an input and the
display the output on the LCD display board. The main parts of the circuit consist of the microcontroller 80C31, LCD display board, the fuel level mechanism, and the software (assembly language, A51 assembler) used to program the EPROM. A detail description and a broad overview on the
architecture of the Intel Microcontroller - 80031 BH, the fuel level mechanism and the LCD display board will be discussed in this chapter.
I
5
2.1 Intel Microcontroller - 80C31 BH
2.1.1 Introduction
This section will reviews on the hardware and software architecture of the 80C31BH Intel microcontroller from the MCS®51 microcontroller family.
The MCS®51 CHMOS microcontroller products are fabricated on the Intel's reliable CHMOS process and this technology combines the high speed and
density characteristics of HMOS with the low power attributes of CHMOS.
Thus expanding the effectiveness of the powerful MCS 51 microcontroller architecture and instruction set. (Ayala, 1997), (MacKenzie, 1992)
2.1.2 Architecture
The 80C31BH microcontroller contains 128 bytes of RAM (on chip), 32 I/O lines, two 16-bit timer/counters, a five source two level interrupt structure, a
full duplex serial port, and on-chip oscillator and clock circuitry. Figure 2.1 shows the 80C31 BH microcontroller architectural block diagram.
The 80C31 BH consists of 40 pins, which 32 pins of it function as bidirectional 110 port lines, and only 24 of these pins are dual-purpose. Each
can acts as an UO port, or a control line or as a part of the address or data bus.
The 24 pins divided into three ports (Port 0, Port 2, and Port 3) and served as an unit in interfacing to parallel devices or can operate independently in interfacing to single-bit devices. (8051 Tutorial)
6
2.1.3 Port 0
Port 0 is an 8-bit bidirectional 1/O port on pins 32-39 of 80C31BH. It can serve as inputs, outputs or as a bidirectional low-order address and data bus
for external memory. When a pin is to be used as an input, a1 must be written to the corresponding port 0 latch by the program, causes the pin to
"float" in a high impedance state, and the pin is essentially connected to the input buffer. When used as an output, contrast to input, is programmed to 0.
All latches that are programmed to a1 still float; thus, external pull-up resistor will be needed to supply logic high when using port 0 as an output.
1
7