The Design Of A Guessword Game Via PIC Microcontroller.

(1)

i

THE DESIGN OF A GUESSWORD GAME VIA PIC MICROCONTROLLER

AHMAD SYAZNAN BIN MOHD ASRI

This report is submitted in partial fulfillment of the requirements for the award of Bachelor of Electronic Engineering (Industrial Electronic) with Honours.

Faculty of Electronic Engineering and Computer Engineering Universiti Teknikal Malaysia Melaka


(2)

UNIVERSTI TEKNIKAL MALAYSIA MELAKA

FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER BORANG PENGESAHAN STATUS LAPORAN

PROJEK SARJANA MUDA II

Tajuk Projek : The Design of a Guessword Game via Pic Microcontroller Sesi

Pengajian : 1 0 / 1 1

Saya AHMAD SYAZNAN BIN MOHD ASRI

mengaku membenarkan Laporan Projek Sarjana Muda ini disimpan di Perpustakaan dengan syarat-syarat kegunaan seperti berikut:

1. Laporan adalah hakmilik Universiti Teknikal Malaysia Melaka.

2. Perpustakaan dibenarkan membuat salinan untuk tujuan pengajian sahaja.

3. Perpustakaan dibenarkan membuat salinan laporan ini sebagai bahan pertukaran antara institusi pengajian tinggi.

4. Sila tandakan ( ) :

SULIT* *(Mengandungi maklumat yang berdarjah keselamatan atau kepentingan Malaysia seperti yang termaktub di dalam AKTA RAHSIA RASMI 1972)

TERHAD** **(Mengandungi maklumat terhad yang telah ditentukan oleh organisasi/badan di mana penyelidikan dijalankan)

TIDAK TERHAD

Disahkan oleh:

__________________________ ___________________________________

(TANDATANGAN PENULIS) (COP DAN TANDATANGAN PENYELIA)


(3)

iii

“I hereby declared that this report entitled The Design of a Guessword Game via PIC Microcontroller is a result of my own work except for the works that have been cited clearly in the references”

Signature : ……….

Student Name : AHMAD SYAZNAN BIN MOHD ASRI Date : 3rd MAY 2011


(4)

iv

“I hereby declared that I have read this report and in my opinion this report is sufficient in terms of the scope and quality for the award the Bachelor of Electronic Engineering

(Industrial Electronic) with Honours”

Signature : ……….

Supervisor Name : ENGR. ZARINA BINTI MOHD NOH Date : 3rd MAY 2011


(5)

v

Special dedicated to my beloved parents, family, friends and lecturers, who had strongly encouraged, inspired and supported me in my entire journey of education.


(6)

vi

ACKNOWLEDGEMENT

First of all, I would like to extend my deepest grateful to grace and mercy Allah S.W.T for giving me strength and determined to complete my thesis entitled “The Design of a Guessword Game via PIC Microcontroller”. I would also like to take this opportunity to express my deep and all my sincere gratitude towards my honorable supervisor, Engr. Zarina Binti Mohd Noh, for her guidance, encouragement, and motivation, I manage to finish the Bachelor Degree Project program properly. Without the continued support and interest, this thesis would not have been the same as presented here. My deepest gratitude goes to two most important people who always given their loves and support, Ibu and Ayah; i-thank-you's will never seems enough to depict my appreciation. To my dear friends, thank you for sharing all the knowledge which I applied in this project. Thank you very much.


(7)

ABSTRACT

Overall, the purpose of this project is to explore the properties of Programmable Interface Controller (PIC) as the main controller for game console design. This project explains the development of a basic guess word game using a PIC microcontroller, an LCD (Liquid Crystal Display) as the display and keypad as a input. The input device used is a 4x3 keypad and the output device used is the LCD display. A program is written using C language by using the MicroC software. The program is then assembled to be connected into a hexadecimal file and downloaded into the PIC microcontroller. This system is able to analyze data from the press keypad through microcontroller and display it at LCD display. The works that have been done includes development of PIC circuit, software for PIC to taking input from keypad and displayed it to LCD display. The systems will execute simple alphabet and need the user to guess the right word, as the question and the result is displayed on the LCD.


(8)

ABSTRAK

Secara keseluruhannya, projek ini bertujuan untuk menjadikan ciri-ciri didalam

Programmable Interface Controller(PIC) sebagai sistem utama dalam penghasilan

permainan teka perkataan ini. Projek ini menerangkan asas pembinaan permainan teka perkataan dengan menggunakan PIC, Liquid Crystal Display(LCD) sebagai paparan dan

Keypad sebagai masukkan data. Peranti input yang digunakan adalah keypad 4x3 dan

peranti output yang digunakan adalah paparan LCD. Bahasa pengaturcaraan yang digunakan adalah ditulis didalam bahasa C dengan menggunakan perisian MikroC. Perisian ini akan menukarkan bahasa pengaturcaraan kepada fail hexadecimal dan dimuat turun ke PIC microcontroller. Sistem ini menggunakan microcontroller untuk menganalisis masukkan data daripada keypad dan memaparkan pada skrin LCD. Kerja-kerja yang telah siap dilaksanakan adalah penghasilan litar PIC, perisian untuk mendapatkan masukkan daripada keypad dan memaparkan pada paparan LCD. Sistem ini akan memaparkan pada paparan LCD susunan abjad secara rawak yang akan membentuk perkataan, kemudian pengguna perlu meneka perkataan yang diberikan.


(9)

ix

CONTENTS

CHAPTER TITLE PAGE

PROJECT TITLE i

REPORT STATUS FORM ii

DECLARATION iii

APPROVAL iv

DEDICATION v

ACKNOWLEDGEMENT vi

ABSTRACT vii

ABSTRAK viii

CONTENTS ix

LIST OF TABLES xii

LIST OF FIGURES xiii

LIST OF ABBREVIATIONS xv

LIST OF APPENDIX xvi

1 INTRODUCTION

1.1 Introduction 1

1.2 Objectives 4


(10)

x

1.4 Scope Of Project 4

1.5 Methodology 5

1.6 Report Structure 7

2 LITERATURE REVIEW

2.1 Introduction 8

2.2 Microcontroller 8

2.2.1 Decision For Choose Microcontroller 9

2.3 PIC16F877A 10

2.3.1 Power Supply 12

2.3.2 Voltage Regulator 12

2.3.3 Clock Oscillator 12

2.3.4 Programming The PIC16F887A 13

2.4 LCD 15

2.5 Keypad 16

2.5.1 4x3 Keypad 17

2.6 MicroC 19

3 METHODOLOGY

3.1 Introduction 21

3.2 Project Methodology 21

3.2.1 Flowchart of Project 22

3.3 Literature Review 24

3.4 Software Implementation and Programming 24 3.4.1 Algorithm and Programming in MikroC PRO

for PIC 25

3.4.2 MicroC 26

3.5 Testing 27


(11)

xi

3.6.1 Voltage regulator (5 V) 27

3.6.2 LCD Module (20x4) Character 28 3.6.3 Microcontroller PIC 16F877A 29

3.6.4 4x3 Keypad 29

4 RESULT AND DISCUSSION

4.1 Introduction 31

4.2 Hardware-User Interface 32

4.3 Software Analysis 32

4.4 Hardware Analysis 38

4.4.1 Power Supply Circuit 38

4.4.2 Microcontroller Circuit 39

4.4.3 LCD Interface 39

4.4.4 Keypad Interface 41

4.5 Overview of The Complete Hardware 43

4.6 Discussion 44

4.7 Project Overview 47

5 CONCLUSION AND RECOMMENDATION

5.1 Introduction 48

5.2 Conclusion 48

5.3 Recommendation 50


(12)

xii

LIST OF TABLES

NO. TITLE PAGE

1 PIC library 14

2 The pin assignment for LCD 16


(13)

xiii

LIST OF FIGURES

NO. TITLE PAGE

1 Tennis for two 2

2 Flow Chart for Project Methodology 6

3 Basic microcontroller system 9

4 The on board peripherals as a guide in connecting the output and input

of this microcontroller 11

5 PIC Microcontroller power supply 12

6 LCD 20 x 4 15

7 4x3 keypad 17

8 keypad switch layout 17

9 keypad connection to microcontroller 19

10 MicroC IDE 20

11 Flow chart of the project 22

12 Flow chart of design process 23

13 MicroC software Tool 26

14 20x4 LCD display 28

15 8 pins (4x3 keypad) 30

16 3x4 keypad 30

17 Full functional block diagram 32

18 Simulation using proteus 7 professional software 33


(14)

xiv

20 Flowchart of the Programming 34

21 Shows the character message “Welcome to Word Guessing Game” on

The welcome screen 35

22 Shows the word that need to be guess 35

23 Shows the input from the user 36

24 Shows the input word from the user 36

25 Shows the display result if the result is right 37 26 Shows the display result if the result is wrong 37

27 Voltage regulator Circuit 38

28 Clock Oscillator circuit 39

29 Connection for LCD 40

30 Connection for Keypad 41

31 Pin description for 4 x 3 keypad 42

32 PCB layout design using the ARES Professional 43

33 The complete etching circuit 43

34 Complete Circuit 44

35 LCD cannot display the word character 45

36 SK40C module from Cytron 46


(15)

xv

LIST OF ABBREVIATIONS

ADC Analog-Digital Converter

EEPROM Electrically Erasable Programmable Read-Only Memory ISR Interrupt Service Routine

LCD Liquid crystal display

PIC Programmable Interface Controller RAM Random-access memory

ROM Read Only Memory

USART Universal Asynchronous Receiver Transmitter VES Video Entertainment System


(16)

xvi

LIST OF APPENDIX

Appendix A LCD Connection Source Code Appendix B Program source code


(17)

1

CHAPTER I

INTRODUCTION

1.1 Introduction

This chapter will discuss about the introduction, objectives, scope and methodology of the project.

The origin of video games lies in early cathode ray tube-based missile defense systems in the late 1940s. These programs were later adapted into other simple games during the 1950s. By the late 1950s and through the 1960s, more computer games were developed (mostly on mainframe computers), gradually increasing in sophistication and complexity. Following this period, video games diverged into different platforms: arcade, mainframe, console, personal computer and later handheld games. [1]

A device called the Cathode-Ray Tube Amusement Device was patented in the United States by Thomas T. Goldsmith, Jr. and Estle Ray Mann. It is described using eight vacuum tubes to simulate a missile firing at a target and contains knobs to adjust the curve and speed of the missile. Because computer graphics could not be drawn electronically at the time, small targets were drawn on a simple overlay and placed on the screen. A graphical version tic-tac-toe, was created by A.S. Douglas in 1952 at the


(18)

2

University of Cambridge, in order to demonstrate his thesis on human-computer interaction. It was developed on the EDSAC computer, which uses a cathode ray tube as a visual display to display memory contents. The player competes against the computer. In 1958 William Higinbotham created a game using an oscilloscope and analog computer. Titled Tennis for Two, it was used to entertain visitors of the Brookhaven National Laboratory in New York. Tennis for Two showed a simplified tennis court from the side, featuring a gravity-controlled ball that needed to be played over the "net," unlike its successor. The game was played with two box-shaped controllers, both equipped with a knob for trajectory and a button for hitting the ball. Tennis for Two was exhibited for two seasons before its dismantlement in 1959.[2]

Figure 1.1: Tennis for two

The first home 'console' system was developed by Ralph Baer and his associates. Development began in 1966 and a working prototype was completed by 1968 (called the "Brown Box") for demonstration to various potential licensees, including GE, Sylvania, RCA, Philco, and Sears, with Magnavox eventually licensing the technology to produce the world's first home video game console.[3] The system was released in the USA in 1972 by Magnavox, called the Magnavox Odyssey. The Odyssey used cartridges that mainly consisted of jumpers that enabled/disabled various switches inside the unit, altering the circuit logic (as opposed to later video game systems that used


(19)

3

programmable cartridges). This provided the ability to play several different games using the same system, along with plastic sheet overlays taped to the television that added color, play-fields, and various graphics to 'interact' with using the electronic images generated by the system.

In the earliest consoles, the computer code for one or more games was hardcoded into microchips using discrete logic, and no additional games could ever be added. By the mid-1970s video games were found on cartridges, starting in 1976 with the release of the Fairchild 'Video Entertainment System (VES). Programs were burned onto ROM chips that were mounted inside plastic cartridge casings that could be plugged into slots on the console. When the cartridges were plugged in, the general-purpose microprocessors in the consoles read the cartridge memory and executed whatever program was stored there. Rather than being confined to a small selection of games included in the game system, consumers could now amass libraries of game cartridges. However video game production was still a niche skill. Warren Robinett, the famous programmer of the game Adventure, spoke on developing games "in those old far-off days, each game for the 2600 was done entirely by one person, the programmer, who conceived the game concept, wrote the program, did the graphic, drawn first on graph paper and converted by hand to hexadecimal and did the sounds.".[4]

A Programmable Interface Controller (PIC) was widely use in the electronic devices and giving many benefits in nowadays life, such as measurement and control of parameters in industry. Thus, the purpose of this project is to explore the properties of PIC as the main controller for game console design. In this project, the microcontroller PIC16F877A will be use and LCD as device to display the result or character and the input will type using the keypad. The microC will be using as the program to writing C language and the assembled to be connected into a hexadecimal file and download into the PIC microcontroller. The work that will do includes the development controlled board circuit, serial interface circuit and character or result must display at LCD.


(20)

4

1.2 Objectives

The main objectives for this project are:

I. To gain knowledge in interfacing between keypad, microcontroller and LCD

II. To design an algorithms(programming code) for the guess word game III. To create a database of word via PIC registers

IV. To develop the input and output circuit related for the gaming system

1.3 Problems Statement

A Programmable Interface Controller (PIC) was widely use in the electronic devices and giving many benefits in nowadays life, such as measurement and control of parameters in industry. One of the applications of the PIC is for Online Monitoring and Fiber Fault Identification in optical fiber communication. [5] Thus the purpose of this project is to explore the properties of PIC as the main controller for gaming purpose.

1.4 Scope of Project

This project consists of two parts as mention earlier which is hardware and software development. While implementing this unit, a microcontroller assembly language programming is learned. Besides, it is also can get more knowledge and learn about the keypad, PIC microcontroller and LCD. This unit are consisting a development of a basic game using chosen PIC microcontroller, keypad and LCD. There is PIC 16F877A, keypad 4 x 3 and LCD display. A microcontroller circuit is built which can receive and process input from the keypad and displaying the result to the LCD. A


(21)

5

program is written to initialize the PIC, set the input port, receive the input from the keypad, and process the input and lastly displaying the result to the LCD. [6]

1.5 Methodology

Project methodology is an important part in order to ensure that this project is implemented according to the planning. In methodology a flowchart is provided to explain the design steps to accomplish this project. This project contains two main parts. The first part is to design the circuit game model that is to be developed. Next part is the software part where programming for the game needs to be created for the PIC. The details methodology will be explained in chapter 3.


(22)

6


(23)

7

1.6 Report Structure

This report shall explain the first part of the final year project, which is the research. What is done thus far is compiled in this report. This report is going to be the reference point with which it is going to be used in the next part of this project. All of contents of this report are useful to fast pacing this project to the next level. So it is important that the contents of this report to be thoroughly researched and put into place.

Chapter 1: introduces the project as a whole. The early and basic explanations are mentioned in this chapter. This chapter consists of the project’s objectives, statements of problems, scope of work, and the simplified methodology.

Chapter 2 is literature review. Past projects or researches are taken into consideration when completing this chapter. The ways those projects and researches are done are compared with what this project is all about. These comparisons are done to understand what this project is all about and where it stands.

Chapter 3 explains how this project came to be. It is the methodology which is the project procedure. This chapter will enlighten the part most important of all, the flow this project. What is researched and what needs to be done is explained in this chapter.

Chapter 4 concentrates on the result and discussion of this project. What has been done thus far is explained in diagrams and written programs. Why the results are like so will also be explained. The reasons and setbacks that cause the project to be halted are discussed in this chapter. The expected results will also be mentioned in this chapter.

Chapter 5 is the final chapter in this report. The conclusions and recommendations are placed in this chapter. The conclusion is the final overview of this project. In other words, the conclusion is the summary of what has been done throughout this project. After the project is done, recommendations are made for the betterment of this project or any expansions or upgrades that might be done in the future.


(24)

8

CHAPTER II

LITERATURE REVIEW

2.1 Introduction

This chapter will discuss about theory and concepts of the project in detail to explain perspective and method that being used in the past research and survey how far this project related with the research and theory that already have. Besides that, this chapter also will show the theory and concepts that being used to solve project problem. Understanding about the theory is very important as a guide line through-out the research.

2.2 Microcontroller

Microcontroller is a revolution that has developed since 15 years ago. Microcontroller designed with a smaller size and has high speed performance. The microcontroller have input and output pin, timer, memory and other features. Basically, microcontroller is a computer system that is fabricated in a single integrated chip. It is


(1)

programmable cartridges). This provided the ability to play several different games using the same system, along with plastic sheet overlays taped to the television that added color, play-fields, and various graphics to 'interact' with using the electronic images generated by the system.

In the earliest consoles, the computer code for one or more games was hardcoded into microchips using discrete logic, and no additional games could ever be added. By the mid-1970s video games were found on cartridges, starting in 1976 with the release of the Fairchild 'Video Entertainment System (VES). Programs were burned onto ROM chips that were mounted inside plastic cartridge casings that could be plugged into slots on the console. When the cartridges were plugged in, the general-purpose microprocessors in the consoles read the cartridge memory and executed whatever program was stored there. Rather than being confined to a small selection of games included in the game system, consumers could now amass libraries of game cartridges. However video game production was still a niche skill. Warren Robinett, the famous programmer of the game Adventure, spoke on developing games "in those old far-off days, each game for the 2600 was done entirely by one person, the programmer, who conceived the game concept, wrote the program, did the graphic, drawn first on graph paper and converted by hand to hexadecimal and did the sounds.".[4]

A Programmable Interface Controller (PIC) was widely use in the electronic devices and giving many benefits in nowadays life, such as measurement and control of parameters in industry. Thus, the purpose of this project is to explore the properties of PIC as the main controller for game console design. In this project, the microcontroller PIC16F877A will be use and LCD as device to display the result or character and the input will type using the keypad. The microC will be using as the program to writing C language and the assembled to be connected into a hexadecimal file and download into the PIC microcontroller. The work that will do includes the development controlled board circuit, serial interface circuit and character or result must display at LCD.


(2)

1.2 Objectives

The main objectives for this project are:

I. To gain knowledge in interfacing between keypad, microcontroller and LCD

II. To design an algorithms(programming code) for the guess word game III. To create a database of word via PIC registers

IV. To develop the input and output circuit related for the gaming system

1.3 Problems Statement

A Programmable Interface Controller (PIC) was widely use in the electronic devices and giving many benefits in nowadays life, such as measurement and control of parameters in industry. One of the applications of the PIC is for Online Monitoring and Fiber Fault Identification in optical fiber communication. [5] Thus the purpose of this project is to explore the properties of PIC as the main controller for gaming purpose.

1.4 Scope of Project

This project consists of two parts as mention earlier which is hardware and software development. While implementing this unit, a microcontroller assembly language programming is learned. Besides, it is also can get more knowledge and learn about the keypad, PIC microcontroller and LCD. This unit are consisting a development of a basic game using chosen PIC microcontroller, keypad and LCD. There is PIC 16F877A, keypad 4 x 3 and LCD display. A microcontroller circuit is built which can receive and process input from the keypad and displaying the result to the LCD. A


(3)

program is written to initialize the PIC, set the input port, receive the input from the keypad, and process the input and lastly displaying the result to the LCD. [6]

1.5 Methodology

Project methodology is an important part in order to ensure that this project is implemented according to the planning. In methodology a flowchart is provided to explain the design steps to accomplish this project. This project contains two main parts. The first part is to design the circuit game model that is to be developed. Next part is the software part where programming for the game needs to be created for the PIC. The details methodology will be explained in chapter 3.


(4)

(5)

1.6 Report Structure

This report shall explain the first part of the final year project, which is the research. What is done thus far is compiled in this report. This report is going to be the reference point with which it is going to be used in the next part of this project. All of contents of this report are useful to fast pacing this project to the next level. So it is important that the contents of this report to be thoroughly researched and put into place.

Chapter 1: introduces the project as a whole. The early and basic explanations are mentioned in this chapter. This chapter consists of the project’s objectives, statements of problems, scope of work, and the simplified methodology.

Chapter 2 is literature review. Past projects or researches are taken into consideration when completing this chapter. The ways those projects and researches are done are compared with what this project is all about. These comparisons are done to understand what this project is all about and where it stands.

Chapter 3 explains how this project came to be. It is the methodology which is the project procedure. This chapter will enlighten the part most important of all, the flow this project. What is researched and what needs to be done is explained in this chapter.

Chapter 4 concentrates on the result and discussion of this project. What has been done thus far is explained in diagrams and written programs. Why the results are like so will also be explained. The reasons and setbacks that cause the project to be halted are discussed in this chapter. The expected results will also be mentioned in this chapter.

Chapter 5 is the final chapter in this report. The conclusions and recommendations are placed in this chapter. The conclusion is the final overview of this project. In other words, the conclusion is the summary of what has been done throughout this project. After the project is done, recommendations are made for the betterment of this project or any expansions or upgrades that might be done in the future.


(6)

CHAPTER II

LITERATURE REVIEW

2.1 Introduction

This chapter will discuss about theory and concepts of the project in detail to explain perspective and method that being used in the past research and survey how far this project related with the research and theory that already have. Besides that, this chapter also will show the theory and concepts that being used to solve project problem. Understanding about the theory is very important as a guide line through-out the research.

2.2 Microcontroller

Microcontroller is a revolution that has developed since 15 years ago. Microcontroller designed with a smaller size and has high speed performance. The microcontroller have input and output pin, timer, memory and other features. Basically, microcontroller is a computer system that is fabricated in a single integrated chip. It is