submitted to the electrical & electronics engineering
TRANSCRIPT
APPLICATION OF VOICE RECOGNITION
By
KAMARUL AZMAN BIN ABU BAKAR
FINAL PROJECT REPORT
Submitted to the Electrical & Electronics Engineering Programme
in Partial Fulfillment of the Requirements
for the Degree
Bachelor of Engineering (Hons)
(Electrical & Electronics Engineering)
Universiti Teknologi Petronas
Bandar Seri Iskandar
31750 Tronoh
Perak Darul Ridzuan
© Copyright 2005
by
Kamarul Azman Bin Abu Bakar 2005
Approved:
CERTIFICATION OF APPROVAL
APPLICATION OF VOICE RECOGNITION
by
Kamarul Azman Bin Abu Bakar
A project dissertation submitted to the
Electrical & Electronics Engineering Programme
Universiti Teknologi PETRONAS
in partial fulfilment of the requirement for the
Bachelor ofEngineering (Hons)
(Electrical & Electronics Engineering)
N^ktfAzinanJZakariyaProject Supervisor
UNIVERSITI TEKNOLOGI PETRONAS
TRONOH, PERAK
December 2005
u
CERTIFICATION OF ORIGINALITY
This is to certify that Tam responsible for the work submitted in this project, that the
original work is my own exceptas specified in the references and acknowledgements,
and that the original work contained herein have not been undertaken or done by
unspecified sources or persons.
Kamarul Azman Bin Abu Bakar
in
ABSTRACT
Voice recognition or speech recognition is the capability of a computer to
recognize or respond to spokenwords and commands. Speech & Voice recognition
enables "hands-free" control of various electronic devices which is a particular help
to many disabled persons and the automatic creation of "print-ready" dictation.
Among the earliest applications for speech & voice recognition were automated
telephone systems and medical dictation software (Transcription). These
applications can be enhanced to wider application where persons can control a
system by using voice command.
Therefore to fill up the gap, this project is basically to create a system that can
control the part or the whole house appliances by applying voice command added
with some other extra features. The extra features included operating windows
application, words translation, and reading notes. The house appliances can be
lighting, fan, air-conditioner, garage door and etc. This system operates like a
switching system where the main objective is to control the application ON/OFF
operation. The main different is this system used voice command as the controller
rather than manual switching by hand. There will be graphical interface that helps
the user to monitor and control the system. Throughout this report, the author will
explain in detail about the project.
IV
ACKNOWLEDGEMENTS
First of all I would like to thank Allah the Almighty, for blessing me the whole time
in completing this FinalYearProject (FYP). I would also liketo thank my family for
their support and encouragement.
My great thank you to my project supervisor; Mr Mohd. Azman Zakariya for the
supervision, guidance, and support. Your advice and comments really help me all the
way through understanding and finishing this project.
Last but not least, thank you to lecturer Mr. Zuki for lending me the PIC simulator
IDE, lab technicians Miss Yanti and Miss Siti Hawa for guidance in the lab, previous
student's report Wan Zahara and all my friends and everyone that has been involved
in helping my Final Year Project.
THANK YOU.
TABLE OF CONTENTS
LIST OF TABLES viii
LIST OF FIGURES ix
LIST OF ABBREVIATIONS xi
CHAPTER 1 INTRODUCTION 12
1.1 Background of Study 12
1.2 Problem Statement and Identification 13
1.3 Objectives of the project 14
1.4 Scope of study 14
1.4.1 Speech recognition software 15
1.4.2 Microsoft Visual Basic 6.0 16
1.4.3 PIC 19
CHAPTER 2 LITERATURE REVIEW AND THEORY 20
2.1 Detecting input voice 20
2.2 Speech recognition 21
CHAPTER 3 METHODOLOGY AND PROJECT WORK 23
3.1 Procedure Identification 23
3.2 Setting up Input 25
3.2.1 Setting Microphone 25
3.2.2 Sound card 29
3.2.3 Trainingspeech recognition software 30
3.3 Microsoft Visual Basic 6.0 34
3.3.1 Link VB to Microsoft Access 35
3.3.2 Build GUI 39
3.3.3 Communication port 41
3.3.4 Serial Communication Interface 42
3.4 Output interface 44
3.4.1 PIC Simulator IDE 44
3.4.2 Warpl3 software 45
3.4.3 HyperTerminal application 46
vi
CHAPTER 4 RESULTS AND DISCUSSION 48
4.1 Results 48
4.2 GUI 49
4.2.1 Controlling otherapplication 50
4.2.2 Translation and Read Notes 51
4.2.3 Home Automation 52
4.3 Choosing microphone 53
4.4 Programming PIC16F84 54
CHAPTER 5 CONCLUSION AND RECOMMENDATION 55
5.1 Challenges and problems 55
5.2 Recommendation 56
REFERENCES 57
APPENDICES 58
Appendix APIC16F84 Connection 59
Appendix BMAX232 Connection 60
Appendix C Table ofAscii code 61
Appendix DTable ofascii code 62
Appendix EUser Manual to Operate the system 63
Appendix F Visual Basic Source Code 64
Appendix GCoding for PIC 65
Appendix HPIC Simulator Manual 69
vn
LIST OF TABLES
Table 1Visual Basic Naming Conventions 18
Table 2 Types ofmicrophone 27
vm
LIST OF FIGURES
Figure 1Basic idea ofproject application 13
Figure 2 Voice Command Option for Microsoft Speech 4.0 15
Figure 3Accuracy Center for Dragon NaturallySpeaking 8.0 16
Figure 4 Visual Basic startup 17
Figure 5Example picture ofPIC 19
Figure 6Converting voice input into binary code 20
Figure 7Determining speech recognition 21
Figure 8Block Diagram ofProject Work 23
Figure 9Project layout 24
Figure 10 Diagram inside the microphone 25
Figure 11 Apicture ofsound card installed in PC 29
Figure 12 An ana!og-to-digital converter measures sound waves at frequent intervals.29
Figure 13 First setup to train DNS 30
Figure 14 Window for new user wizard 31
Figure 15 Selecting text for training 31
Figure 16 Training window 32
Figure 17 DNS application 32
Figure 18 Block diagram ofvisual basic 34Figure 19 Window to add new component 35
Figure 20 Window ofData Link Properties 36
Figure 21 Connection destination 37
Figure 22 Property page for RecorSource 37
Figure 23 Microsoft Access 38Figure 24 Table for database 38
Figure 25 Create GUI 39Figure 26 Visual Basic editor in view code mode 40
Figure 27 Options to add new component 41Figure 28 Visual Basic editor with added component 41
Figure 29 RS-232 Pin Out on aDB-9 Pin Used for Asynchronous Data 43
Figure 30 PIC Simulator IDE software 45
IX
Figure 31 Warpl3 PIC programmer 46
Figure 32 The location ofHyperTerminal application 47
Figure 33 HyperTerminal window 47
Figure 34 Results block diagram 48
Figure 35 Main menu ofthe project 49
Figure 36 Section 1of the project 50
Figure 37 Section 2 ofthe project 51
Figure 38 Section 3ofthe project 52
Figure 39 BASIC Compiler window 54
LIST OF ABBREVIATIONS
PC - Personal Computer
PIC - Peripheral Interface Controller
DNS - Dragon NaturallySpeaking
ADC - Analog-to-Digital Converter
S/N - Signal-to-Noise ratio
Tx - Transmitter
Rx - Receiver
SDK - Software Development ToolKit
VB - Visual Basic
RAD - Rapid Application Development
GUI - Graphical User Interface
DAO - Data Access Object
RDO - Remote Data Object
ADO - ActiveX Data Object
XI
CHAPTER 1
INTRODUCTION
1.1 Background of Study
Voice recognition or speech recognition is the capability of a computer to recognize
or respond to spoken words and commands. Speech & Voice recognition enables
"hands-free" control of various electronic devices which is a particular help to many
disabled persons and the automatic creation of "print-ready" dictation.
Among the earliest applications for speech & voice recognition were automated
telephone systems and medical dictation software (Transcription). Speaking to the
computer can be used in way oftyping or mouse clicking to input information to the
computer.
There are two major types of speech recognition programs which are speech-to-text
and command-and-control. Speech-to-text systems transfer spoken words into
written words for use in any applications such as word processing programs. It can
be Notepad, Microsoft Office Word and a lot more.
Meanwhile, command-and-control systems interpret spoken words as commands, for
example, to open a new program or save a file and it can be any command that is
programmed.
1.2 Problem Statement and Identification
Nowadays, there is lots of voice recognition software in the market. As explained
before the software can do lots of task that resemble the keyboard and mouse. Not
only for dictation and command, it also can reduce the time taken to type on
keyboard and mouseclicking.
However, its capability can be applied only for dictation and command to do simple
works. When this advantage combined with the visual basic programming and
microcontroller PIC programming more advance technologies can be made. It can
control hardware application such as home automation or carautomation and etc.
Moreover, the project can be enhanced to manipulate the power of speech
recognition software to become the translation program and to read notes. The basic
concept is as figure below.
CommandTx
voice
Sound card
Controlling applicationTranslation and read
notes
Lighting
Fan
Air-cond
Garage
Figure 1 Basic idea of projectapplication.
The figure above shows that the transmitter takes the voice as input and transmits to
the receiver which connects to the sound card installed in PC. There will be some
operation in the sound card to convert the input voice into digital signal. Then the
signal triggers thecommand and display output based onthe input.
13
The output can be in the PC itself which is controlling other application, read notes
or translate the input to Malay text. Other output is to control the home appliances
suchas lighting, fan, air-condition, garage and etc.
1.3 Objectives of the project
• To have voice recognition system that can dictate spoken words to text
• Tocreate a programmable circuit that hasspeech command as input
• To have user interface application between user and home automation system
• The program can translate word from English to Malay
1.4 Scope of study
There are several topics and issues that must be considered before proceeding any
further in the design ofthe system. The scope of study depends mainly on these few
areas:
> controlling the speech as input and produce thedictation as output
> interfacing the controller to the PC viaserial communication
> interface at the PC for the exchange of inputs and outputs from the controller
The applications and devices that are considered must be reliable, cost-effective and
practical for a feasible implementation. This will ensure that the design produced is
economical and marketable.
14
1.4.1 Speech recognition software
Firstly, through research on available speech recognition software in market, there
are two most popular software which are Microsoft Speech 4.0 and Dragon
NaturallySpeaking 8.0. To choose the best software, both speech recognition need to
test out and made the comparison.
For Microsoft Speech 4.0, it came with the Software Development ToolKit (SDK)
which enables the programmer to add the speech recognition tools in their program.
This way the program itself contains the tools for speech recognition. However after
several experiment, it shows that the voice detection is less accurate and less user
friendly than DNS.
The figure shown below is one ofthe options ofthe Microsoft Speech 4.0. Compared
to the DNS it does not have the training tool to make the recognition more accurate
as shown in the figure 3.
Voice Command Options
Listening Mode
Advanced
General
Voice Commands
ComputerVoice
Accessibility
W Provide voicecommands for frequently used directoriesMicrosoft Voice watches what directories you use, and allows you tosay, "Bring up <directory>" for common ones.
W Start<prograrn> commandsMicrosoft Voice watches what prorgams youuse from the "Start" menuand allows youto say"Start <program>" for common ones.
W Provide voice commands for FavoritesYou can say, "Start <favorite>" for any document, web-site, or directoryon your favorites list.
& Provide voice commands forWindows Controls
You can speak menu items, buttons, and links.Jv" JAIso speak items in list boKesj
OK Cancel Apply
Figure 2 Voice Command Option for Microsoft Speech 4.0
15
Improve your acoustics
iil,. Check your audio settings
M RuntheAcoustic Optimizer
<fa Schedule Acoustic Optimizer to ranlater
"ffi Perform additional training
Manage your commands
H Launch the Command Browser
'X Exit
Improve your vocabulary
* Add a single word to your vocabulary
OS Addwords from your documents to thevocabulary
1=1 Increase accuracy from e-mail
01 Add a list ofwords to your vocabulary
lb View or edit your vocabulary
hSp Run the "Vocabulary Optimizer
Get more information
^y How to manage andpersonalize yourvocabularies
Figure 3 Accuracy Center for Dragon NaturallySpeaking 8.0
Despite having more accurate recognition and accuracy center to make the
recognition even accurate, DNS software less one part which is not having the SDK
application included for free. From the research and study the SDK only included
within the professional version. Moreover, the price for Dragon NaturallySpeaking
SDK is $695.00 and due to the cost constraint this is hard to achieve.
1.4.2 Microsoft VisualBasic 6.0
Another main scope in this project is to study the software that can build the
graphical user interface and easy to handle. Therefore, Microsoft Visual Basic 6.0 is
chosen to fulfill the need. Visual Basic (VB) is an event driven programming
language and associated development environment created by Microsoft.
It is derived heavily from BASIC and enables Rapid Application Development
(RAD) ofgraphical user interface (GUI) applications, access to databases using Data
Access Object (DAO), Remote Data Object (RDO), or ActiveX Data Object (ADO),
and creation of ActiveX controls and objects. A programmer can put together an
application using the components provided with Visual Basic itself.
16
New Project
lvl (SO"
New Existing j Recent j
sSC-f^lHlfii ActiveX EXE ActiveX DLL ActiveX VB Application
Control Wizard
s£<> <S>
VB Wizard ActiveX ActiveX Addin Data ProjectManager Document Oil Document Exe
Open
Cancel
Help
P Don't showthisdialog inthe future
Figure 4 Visual Basic startup.
Visual Basic was designed to be usable by all programmers, whether novice or
expert. The language is designed to make it easy to create simple GUI applications,
but also has the flexibility to develop fairly complex applications as well. Forms are
created using drag and drop techniques. Atools palette is used to place controls (e.g.,
text boxes, buttons, etc.) on the form (window). Controls have attributes and event
handlers associated with them.
For example, code can be inserted into the form resize event handler to reposition a
control so that it remains centered on the form, expands to fill up the form, etc. By
inserting code into the event handler for a keypress in a text box, the program can
automatically translate the case of the text being entered, or even prevent certain
characters from being inserted.
17
Table 1 Visual Basic Naming Conventions
Object Prefix
Form frm
Command Button cmd
Text Box txt
Label lbl
Option Button opt
CheckBox chk
Frame fra
Horizontal Scrollbar hsb
Vertical Scrollbar vsb
Image lmg
Picture Box pic
Shape shp
1.4.3 PIC
The Peripheral Interface Controller (PIC) is a complete computer on a chip. Such
chips can be built into a device to make the product more intelligent and easier to
use. PIC chips are programmed to perform only one very specific task, e.g. - a
microwave oven may use a single micro-controller to process information from the
keypads, display user information on the seven segment display, and control the
output devices (turntable motor, light, bell andmagnetron).
By altering the software program, the same PIC chip can be used to complete
different tasks. The same type of chip can therefore be used in a range of different
products by simply programming them with a different software program. There are
many types of PIC depending on their usage and programming.
Figure 5 Example pictureof PIC.
The PIC16F84 microcontroller is made the microcontroller of choice for the
specified task. This choice is obvious as this microcontroller is competitively priced,
not to mention its sound applicability in this system. It is also good to note that this
microcontroller comes with many interesting features.
19
CHAPTER 2
LITERATURE REVIEW AND THEORY
Main parts for using the speech recognition by a personal computer requires a
microphone for audio input, a sound card to process the input, and software
including a speech engine. Before going any further the theory behind all this parts
and how it works had to be studied.
2.1 Detecting input voice
This is how the way itworks in speech recognition. Firstly, the person voice which is
speech sounds begin as vibrations in the throat that cause disruptions in the nearby
air pressure. Agraph ofthe pressure changes over time is called awaveform.
Then audio input that is a microphone converts the pressure changes into electrical
voltage changes (an analog signal). The voltage then received by a computer sound
card which is an analog-to-digital converter that converts the voltage changes back
into pressure changes and stores them as binary code (digital) on the hard drive.
Microphone
•*)<gaajj.
PC Sound Card
1010101011111001010
-Binary code
CPU
Figure 6 Converting voice input into binary code.
20
2.2 Speech recognition
From this part, the computer reads the spectrogram patterns and compares them to
known patterns for particular sounds or phonemes. A spectrogram is a graph of
frequency over time. A phoneme is a distinct speech sound.
This includes individual letters, like "b" or "p" and sounds like "ch" or "ng." Some
vowels in particular can have different sounds depending on their usage, e.g., the
words "book" and "boot" have two different "oo" phonemes [3]. Some speech
recognition programs require discrete speech, i.e., a pause after each and every word.
Others are natural language systems that allow a speaker to speak continuously. They
use contextual information to choose which words make sense and to distinguish
homophones such as "to," "too," and "two." The programs store frequently used
words in an active vocabulary list or dictionary in the computer's random-access
memory (RAM) [3]. A larger back-up dictionary, which can contain hundreds of
thousands of words, is stored on the hard drive.
RAM
(Compare
input withdatabase
dictionary)
110010101101110100
(Input in binary)
"Welcome"
(Output)
p.
Figure 7 Determining speech recognition.
21
Some programs are speaker dependent. They are designed to become familiar with
one particular speaker's voice and language patterns. The user initially trains the
program by reading exercises and identifying mistaken identifications. Eventually
the program develops a reliable voice file for that individual. Although the training
can be time consuming, a large vocabulary is possible with this type of program. A
speaker independent system requires no initial training. It comes equipped with a
limited vocabulary and can conceivably recognize any person's speech.
The best speech recognition programs on the market achieve word recognition rates
of approximately 90 percent [2]. Roughly this means one mistaken word per
sentence. Voice tone, pitch, inflection, and rate of speaking are all determining
factors. Speakers with voice disorders, colds, or heavy accents can easily be
misunderstood. Best performance is obtained when the program vocabulary is
limited, background noise is minimized, and the speaker has a clear consistent voice
with good articulation and enunciation [1].
Speech recognition technology is improving quickly and has become an area of
focus for many software designers. The latest innovations are Internet voice portals.
These systems use Voice Extensible Markup Language (VXML) to direct web
browsers to URL addresses that are spoken rather than typed [2]. Many experts
predict that the keyboard and mouse will be obsolete within a decade. Growing
consumer demand for voice responsive computers and technological advances in
neural networks and artificial intelligence are expected to result in computers that not
only recognize spoken words, but comprehend their meaning and can communicate
with their human counterparts.
22
CHAPTER 3
METHODOLOGY AND PROJECT WORK
3.1 Procedure Identification
Project Work
1ISetting up input
1 r i '
Setting Microphone Training speech
PIC Programming
Link lo Microsoft
Access
Setup table for
database
Visual Basic
Programming
Build Graphical
User Interface
Create Form
1Run Simulation
ITest with serial
comm. port
Download to PIC
1Link to Serial
comm. port
ISetup connection
PC to PIC
Figure 8 BlockDiagram of Project Work.
23
1Build Hardware
IGetting component
Build circuit
ITest circuit
Result
Procedure identification is very important to keep the project always on the track
which will help the project finish on time. Those procedures for the implementation
had to pass several systematic steps. Each step had to finish before move on to
another step to make sure the project success.
Input Interface
- controlling application
- translation and read notes
application
Figure 8 Project layout.
Controlling homeor electronic
application
Output
Interface
The figure above shows the main parts in the project. The basic structure for the
project system is illustrated as in figure above. The system consists of:
1. Input interface, which consists of microphone, sound card and voice
recognition software to detect speech and change to text.
2. Graphical UserInterface (GUI) that allow user to store database and monitor
the system in details.
3. Output interface consists of microcontroller circuit that connected with the
controlled devices such as lamp, fan and motor.
24
3.2 Setting up Input
There are two parts to consider for input interface which are hardware and software.
For hardware part it consists ofmicrophone and sound card while speech recognition
for the software part. Details in input interface project work are described below.
3.2.1 Setting Microphone
Probably the simplest and most used input to detect voice is the microphone. A
microphone is an object that transforms acoustical energy (sound) into electrical
energy (an audio signal). There are many ways to do this, and many types of
microphones.
Figure 9 Diagram inside the microphone.
A microphone wants to take varying pressure waves in the air and convert them into
varying electrical signals. There are five different technologies commonly used to
accomplish this conversion:
• Carbon microphones - The oldest and simplest microphone uses carbon dust.
This is the technology used in the first telephones and is still used in some
telephones today. The carbon dust has a thin metal or plastic diaphragm on
one side. As sound waves hit the diaphragm, they compress the carbon dust,
which changes its resistance. By running a current through the carbon, the
changing resistance changes the amount of current that flows.
25
Dynamic microphones - A dynamic microphone takes advantage of
electromagnet effects. When a magnet moves past a wire (orcoil ofwire), the
magnet induces current to flow in the wire. In a dynamic microphone, the
diaphragm moves either a magnet or a coil when sound waves hit the
diaphragm, and the movement creates a small current.
Ribbon microphones - In a ribbon microphone, a thin ribbon is suspended in
a magnetic field. Sound waves move the ribbon which changes the current
flowing through it.
Condenser microphones - A condenser microphone is essentially a capacitor,
with one plate of the capacitor moving in response to sound waves. The
movement changes the capacitance of the capacitor, and these changes are
amplified to create a measurable signal. Condenser microphones usually need
a small battery to provide a voltage across the capacitor.
Crystal microphones - Certain crystals change their electrical properties as
they change shape. By attaching a diaphragm to a crystal, the crystal will
create a signal when sound waves hit the diaphragm.
26
There are several types of microphone that available for the usage in this project.
Table below shows all the types
Table 2 Types of microphone.
Types
> Built-into the computer/monitor
> Built-into the keyboard
> Clip-on
> Close-talk
Description
Microphones built-into computers or
computer monitors work for command &
control speech recognition, but do not work
well for dictation because they are too far
away and pick up a lot of noise.
Microphones built-into keyboards do not
work well for speech recognition because
they are too far away and pick up a lot of
noise.
Clip-on microphones clip onto shirt, just
below the collar. They are not as good as
close-talk microphones. Also, the cord
sometimes gets in the way.
Close-talk microphone is wears on the head
so that the microphone is as close to mouth
as possible. These work the best for speech
recognition and dictation because they hear
only the person speaking and not any
background noise. Unfortunately, the cord
sometimes gets in the way.
27
> Desktop
> Ear-piece
> Hand-held
> Handset
> Rest on the computer
Desktop microphones usually rest in a
microphone stand. If it keeps pointing
towards user and about 6" (15cm) from
mouth, they work well, but only in quiet
rooms.
Ear-piece microphones rest on user ear.
These work well for speech recognition and
dictation but not as well as close-talk
microphones. Unfortunately, the cord
sometime gets in the way.
Although hand-held microphones pick up
very little noise, they are not convenient for
most speech recognition purposes because
they must be held 4" (10 cm) away from the
user's mouth.
These microphones look like normal
telephone handsets, but they plug into the
microphone jack rather than the telephone
jack. Handsets get good accuracy.
Microphones that rest on the computer do
not work well for dictation because they are
too far away and pick up a lot of noise, but
they will work for command and control.
28
3.2.2 Sound card.
A sound card which is installed in the PC is acting like an Analog-to-Digital
Converter (ADC). The ADC translates the analog waves of the voice into digital data
that the computer can understand. To do this, it samples, or digitizes, the sound by
taking precise measurements of the wave at frequent intervals. This is as shown in
figure below.
**«<»•ft
Figure 10 A picture of sound card installed in PC.
_P
3 F V,
i _
nfl. j!
I '
Figure 11 An analog-to-digital converter measures sound waves at frequentintervals.
The number of measurements per second, called the sampling rate, is measured in
kHz. The faster a card's sampling rate, the more accurate its reconstructed wave is.
29
3.2.3 Trainingspeech recognition software
Dragon NaturallySpeaking® 8 enables PC users to create and edit documents and e-
mails, fill out forms, and streamline workflow tasks-all by speaking! Talk to the
computer and the words instantly and accurately appear in the full Microsoft®
Office® Suite, plus Corel® WordPerfect®, Lotus® Notes®, and virtually all other
Windows®-based applications.
First of all, the software need to be train and this is done by following the New User
wizard window shown in the figure below. As shown in the figure, it is
recommended to use the close talk microphone and the way to positioning the
microphone. No matter what types ofmicrophone used, the correct positioning ofthe
microphone isone ofthe most important factors ingetting good dictation accuracy.
Position your microphone
Correct positioning of your microphone is one of the most important factors in getting gooddictation accuracy. Use the pictures below as a guideline for positioning your microphone.
For more information on connecting orpositioning your microphone, click Help.
[ Next"> ] Cancel Help
Figure 12 First setup to train DNS.
30
Then it needs to adjust the volume check of the microphone as shown in the figure
below. In this step the computer checks the audio input from the sound system.
Having high-quality audio input is very important for good speech recognition. Poor
audio input will make it difficult or impossible for the program to recognize speech
accurately. When the computer has finished checking the audio quality, it beeps to
signal that the test is complete.
Adjust Your Microphone: Volume Check
Please read this text aloud:
Inthis step thecomputer listens to thesoundofyour voice andadjusts the volume setting ofyour microphone. Whenthecomputerhas finished adjusting the volume, itbeeps to signal that the processiscomplete. Ifyou reach theend of this text butyou havenotheard abeep,start reading thetext again from the beginning. You should onlyhave to read for about ten to fifteen seconds.
I Stop VolumeCheck | Listening...
< Back Cancel
Figure 13 Window for new user wizard.
Please select the text that you would like to read.
Talking to your-Computer [EasierReading;-Instructional)Kennedy's Inaugural Address (Medium Reading: Historical Speech)Dave Barry in Cyberspace (Medium Reading: Humor)Dogbert's TopSecret Management Handbook (Harder Reading: Humor)Stories Written by Children(Reading for Children)Alice's Adventures inWonderland (Reading for Teens: Fantasy)
OK
Figure 14 Selecting text for training.
31
Help
New User Wizard
Train Dragon NaturallySpeakingTalking toyour Computer [Easier Reading: Instructional)
Read the following paragraph.
Start '•"••••" '
; Pause j]
>r-u tn f!?.:v:s -;ionn for h few minuter mm® tne
we would like to explain why talking toa computer is not the same as talking to a person and then giveyou a few tips about how to speak when dictating.
Finish
<- Redo Skip ->
Cancel Help
Figure 15 Training window.
After selecting the available text to read as shown in the figure, the training window
will appear and here the training will begin. The text provide for training is divided
to easier, medium and harder depending on the user. The choice also will affect the
recognition accuracy as harder text having more difficult word to pronounce.
After the training session, the DNS is ready to use for dictation. Figure below show
the toolbars for DNS application.
Accuracy Center...
Command Browser..
Add New Command.
DragonPad...
Options,,,
Figure 16 DNS application.
32
There are lots of benefits using DNS software which are:
S More Accurate Than Ever Before
With a 25% increase in accuracy, Dragon NaturallySpeaking® 8 is up to 99%
accurate and frequently more accurate than typing.
S Faster Than Typing
Most people speak over 160 words per minute, but type less than 40 words a
minute. That means user can create documents and e-mails about three times
faster with Dragon NaturallySpeaking 8.
V Safer Than Typing
Dragon NaturallySpeaking 8 will help protect user from repetitive stress injuries
like carpal tunnel syndrome - injuries thatcan cost tens of thousands of dollars.
S Easy To Use
Simply install the Dragon NaturallySpeaking CD, and in just a few minutes, user
will be creating documents, e-mails and filling out forms by voice! It even
included with a free noise-canceling microphone.
33
3.3 Microsoft Visual Basic 6.0
Microsoft Access
(Database)
ICreate table
Visual Basic
Build GUI
ICreate form consists
of text box,
command button,
etc.
Link to
Communication Port
Setup MSCommproperties
Figure 17 Block diagram of visual basic.
There are three criteria that have to include in order creating the GUI as shown in
block diagram above. Firstly, visual basic requires a tool that can interconnect with
Microsoft Access which operates as database. It also requires tool to create form or
interface which include some coding for user to operate the program. To
communicate with serial port, it involves extra component to be able to do so.
In order to write a proper Visual Basic project, there several important elements to
learn and understand. The two vital steps are:
1. Planning
> Design the user interface
> Plan the properties
> Plan the Basic code - procedures are associated with the events, actions
written in pseudocode
2. Programming
> Define the user interface - define objects
> Set the properties
> Write the Basic code
34
3.3.1 Link VB to Microsoft Access.
One of the functions of visual basic is able to link with other application such as
Microsoft Access. Therefore, to setup the link visual basic needs to have component
that can communicate with Microsoft Access. This is shown in the figure below how
to add the component Microsoft ADO DataControl 6.0 (OLEDB).
Controls Designers! Insertable Objects
. GridDTC
Help Center UI 1.0 Type LibraryIStudio Active Designer Controls
' LayoutDTC 1,0 Type Library!Microsoft ActiveXPlugin
\ Microsoft ADO Data Control 6,0 (OLEDB)j Microsoft Agent Control 2.0„Microsoft Calendar Control 8.0
.! Microsoft Chart Control6,0 (OLEDB)
." Microsoft Comm Control 6,0
] Microsoft Common Dialog Control6.0", Microsoft Data Bound Grid Control 5,0 (SP3)
" Microsoft Data Bound List Controls b 0
:-) VideoSoft vsFlexO Controls
Location: C:\WINDOW5\system32\V5FLEX3.0CX
OK
^s^ng^iSijj-iE3' El
•fi=- TC=- B9255""
•"a-fe.fe
•'Mi'H EE3 mn
Browse,,,
IT SelectedItems Only
Cancel
Figure 18 Window to add new component.
Then the component of the Adodc is dragging to the form to activate the link with
Microsoft Access. A few properties need to setup ensure the connection with table
from Microsoft Access. The properties are shown in the figure below and how to
setup it.
35
The three important settings that must be initialized under the ADO Data Control
properties are:
> Connection String; using the Microsoft Jet 4.0 OLEDB Provider, which is the
normal choice for real-time application
> Connection Destination; declaring the path of the designated database
> RecordSource; setting the command type and table or stored procedure name
to compliment the RecordSet
Data Link Properties
Provider | Connection | Advanced j All
Select the data you want to connect to:
OLE pB_Provjder[sl _.__ _MediaCatalogDB OLE DB ProviderMediaCatabgMergedDB OLE DB ProviderMediaCatalogWebDB OLE DB Provider
Microsoft OLE DB Provider For Data Mining "ServicesMicrosoft OLE DB Piovider for IndexingServiceMicrosoft OLE DB Provider forInternet PublishingMicrosoft OLE DB Provider for ODBC DriversMicrosoft OLE DB Provider for OLAP Services S.OMicrosoft OLE DB Provider for OracleMicrosoft OLE DB Piovider for SQL ServerMicrosoft OLE DB SimpleProviderMSDataShapeOLE DB Provider for Microsoft Directory Services
OK Cancel
Next>>
Help
Figure 19 Window of Data LinkProperties.
36
IData Link Properties
Provide! Connection | Advanced jAll |
Specify the following toconnecttoAccess data:
1. Select or enter a database name:
|C:\Documents and SettingsSKamarul Azrnan\My Docu
2. Enter information to log on to the database:
User name: Admin
W Blank password F Allow saving password
Test Connection
OK Cancel
Figure 20 Connection destination.
General) Authentication RecordSource | Color ] Fontr RecordSource— ~-
I CommandType
; f2 ' adCmdTable 3
Table or Stored Procedure Name
Command Text (SQL)
Help
OK Cancel Apply
Figure 21 Property page for RecorSource.
37
Help
The built-in Visual Basic functions proved to be a real boost as it allows Microsoft
Access to communicate with Visual Basic to exchange data and provide proper
database storage.
For this project the database consists of a translation table that store a few simple
words that canbe translate for this project. This is presented in figure below.
13 Microsoft Access
File Edit View Insert Tools Sflndow rJetp T' P" Jiu^tnn r t h> In
dbl : Database {Access 2000 file format);
L^jOpen i^ Design J]New | }
Objects !
'J Tables
J Queries
•£l Forms
U Reports
si Pages
;2 Macros
& Modules
Groups
•M Favorites
Ready
Create table in Design view
Sj Create table by using wizardl|lj Create table by entering data
Figure 22 Microsoft Access.
• Translation : Table
*
No Spoken
1 we
2 they3, food
4 night(AutoNumber)
Figure23 Table for database.
38
NUM
Translation
;KitaMereka
•fvlakanan
,Malarnl
3.3.2 Build GUI.
Another feature that makes visual basic is a powerful GUI application is that it can
create a form for user to operate the program. A GUI is a graphical, (rather than
purely textual) user interface to a computer. The term came into existence because
the first interactive user interfaces to computers were not graphical; they were text-
and-keyboard oriented and usually consisted of commands that we had to remember
and computer responses that were infamously brief.
The command interface of the DOS operating system is an example of the typical
user-computer interface before GUIs arrived. An intermediate step in user interfaces
between the command line interface and the GUI was the non-graphical menu-based
interface, which allows interaction by using a mouse rather than by having to type in
keyboard commands.
Figure presented below shows the main elements to have good graphical user
interface for this project which are label, text box and command button. Basically
label is to display information on how to operate the form. While textbox is to allow
the user to enter text such as user name or password. Last but not least is command
button that basically to runthe program or to enterto another form.
Labell
Textl
Commandl
Figure 24 Create GUI.
39
The figure below shows theVisual Basic editor in view code mode and the red circle
indicate run button to running the program written. The codemode is where to write
the Basic codeto program the event or action should be taken when command button
is pushed or to set the properties for linkto the communication port.
"^fProjectl -Microsoft Visual Basic [design} [Forml (Corte)]
& File Edit
;j3
View Project Format Debug Run Query Jtiagram Tools Add-Ins Window Help _!i9JX
• 1;
Figure 25 Visual Basic editor in view codemode.
40
3.3.3 Communication port.
A component known as the Microsoft Comm Control 6.0 is applied to allow the
connection between Visual Basic and the serial port. This is shown in figure below to
add the new component and where it will appear.
Components
Controls Designers] InsertableObjects
il; LayoutDTC 1.0 Type Library'.'Microsoft ActiveXPlugin
V; Microsoft ADO Data Control 6.0 (OLEDB)
\'S', Microsoft Agent Control 2.0O. Microsoft Calendar Control 3.0
U MicrosoftChart Control 6.0 (OLEDB)
Vifi licrosoft Coram Control 6,0
.[Microsoft Common Dialog Control 6.01 MirrrwnFr Date Rni mrl GriHCnnhml R.fl fSPiVi
Figure 26 Options to add new component.
A'
JJ -±U 'El
-III!! 'FI^-IS
•Q- Forml (Forml)
|Form1 Form
Alphabetic | Categorized.BackColor Q &H3000000F ABorder5tyle 2 - Sizable
Forml v
Caption
•Returns/sets the text displayedin an;object's title bar or below an object's
L&'iy
Figure27 VisualBasic editorwith added component.
41
To setup the connection from visual basic to serial port, the figure that looks like
telephone is drag to the form to activate the connection. Another important thing is to
set the properties of the communication port by typing the code as shown below in
the code mode under form load.
Private Sub Form_Load()
'openport
MSComml.CommPort = 1
MSComml.Settings = "9600,n,8J"
MSComml.PortOpen = True
End Sub
3.3.4 Serial Communication Interface
When using the component Microsoft Comm Control 6.0, it needs the transmission
medium which is serial communication interface. The serial port is chosen because it
proves to be feasible.
As far as interfacing between the PIC16F84 and PC isconcerned, initialization is the
first consideration by modifying the settings on both ends to accommodate each
other. These settings include:
> Baud rate: 9600
> Parity bit: None
> Data bits: 8
> Stop bits: 1
These initializations will coincide with that of the PIC16F84. The two pins from
PIC16F84 that interacts with the serial port are:
> Transmit pin (Bl)
> Receive pin (B2)
42
Old PC's used 25 pin connectors but only about 9 pins were actually used so today
most connectors are only 9-pin. Each of the 9 pins usually connects to a wire.
Besides the two wires used for transmitting and receiving data, another pin (wire) is
signal ground. The voltage on any wire is measured with respect to this ground. Thus
the minimum number of wires to use for 2-way transmission of data is 3. Despite this
method, it has also been known to work with no signal ground wire but with
degraded performance and sometimes with errors.
4 5
f \ IDHO
0 0 0 0
Pin Signal Pin
OalaCarrier Deiecl
2 ReceivedData
3 Transmitted Data
4 Data Terminal Ready
Signal Ground
SignalDataSet Ready
Reouest to Send
Clear toSend
Ring indicator
Figure 28 RS-232 Pin Outon a DB-9 Pin Used for Asynchronous Data
Almost all digital devices used nowadays require either TTL or CMOS logic levels.
Therefore the first step to connecting a device to the RS-232 port is to transform the
RS-232 levels back into 0 and 5 Volts. This is done by RS-232 level converters. Two
common RS-232 level converters are the 1488 RS-232 driver and the 1489 RS-232
receiver. Each package contains 4 inverters of the one type, either drivers or
receivers. The driver requires two supply rails, +7.5V to +15V and -7.5V to -15V.
As expected, this may pose a problem in many instances where only a single supply
of+5V is present. However the advantages of these IC's are theyare cheap.
43
Besides the RS-232, another device is the MAX-232. It includes a charge pump,
which generates +10V and -10V from a single 5V supply. This IC also includes two
receivers and two transmitters in the same package. This is handy in many cases
when onlythe Transmit andReceive dataLines are needed
3.4 Output interface
To make the project able to run with external program such as PIC microcontroller,
the visual basic program needs to communicate with the circuit through serial port.
Before that, a simple experiment needs to test out whether the communication port
works properly with the PIC microcontroller.
The experiment consists of PIC Simulator IDE software, Warpl3 software, and
HyperTerminal application.
3.4.1 PIC Simulator IDE
PIC Simulator IDE is software that help user to program the PIC microcontroller.
PIC Simulator IDE is powerful application that supplies PIC developers with user-
friendly graphical development environment for Windows with integrated simulator
(emulator), BASIC compiler, assembler, disassembler and debugger.
Default extension for basic source files is BAS. The compiler output is assembler
source file (with ASM extension) that can be translated to binary code using
integrated assembler. Smart editor marks all reserved keywords in different color
that simplifies debugging process. BASIC compiler's assembler output has all
necessary comment lines that make it very useful for educational purposes, also.
Figure below shows the windows of the PIC simulator IDE software.
44
Microcontroller
•• Last Instruction—
SUBWF Qk15.F
1Instructiar. -
| BTFSS STATUS.C
"1 Instructions Counter I 477G7
| DockCycles Counter. | 364
| Res]Time Duration | 91.0 ns
- ProgramCounterandWRegister •• ••
fFT rras" rrrrr^rrrr^rI wr^st™- fW rrrrrrrr
SpBcral FunctionRegisters(SFRs)
Addiess and Name
D05h PORTA
Hen Binary ValueValue 7 5 5 4 3 2 1 0__ rrrrrrrr__ r(_rrrrpr
IT rrrrrrrrW rrrrrrrr•Err rrrrrrrrW rrrrrrrr_ rrrrrrrr_ rrr[_rrrr
w rrrrrrrr_ rrrrrrrr
-?r rrrrrrrr~ rrrrrrrrft mrrrrrr— rrrrrr'"r
rrrrrrrr
D81h OPTIONREG
]38h EECDH1
rrrr-i—r _j
• General PurposeRegisteis (GPRs) i
HenAddi. Value
HenAddi. Value
ODCh 00
00 .
00
00
00
QO .
00
00
B2
01 •
4E
00
0E
02
5B
OO
01 Ch OA
OQDh OlDIi 00
OCEh
OOFh
01 Eh 00
Q1Fh 00
D10h 020h 00
Ollh 021 h 00
012h 022h 00
013h 023h 00
D14h 024h 00
DISh 025h 00
01 Eh 02Eh 00
017h Q27h 00
OlSh •28h 00
019h Q29h 00
01Ah 02A!i 00
01 Bh 02Bh 00
I- AlwaysOn Top
<Wli q-
|RXLine >PORTB 2Bend Rate ~> 9600
UART Output
Number. 10Number: 9Number: 8Num
•Jii " DSC2>CLK0UT
-*,•••
|TXLine Status1 Bit 5 received
UARTInput-
-inlxl
]TX Line -> PORTB 1
|Logic Levels> Standaid
Send Byte {Dec) | Sard Byte [Hex] | SendChai
|RX Line Status: MARK slate generated
r AlwaysOn Top
Figure 29 PIC Simulator IDE software.
3.4.2 Warpl3 software
After make sure the program is running smoothly using the simulator, it needs to be
transfer to the real PIC microcontroller. To do this, the program has to download in
the PIC using WARP13 software which capable to do so. The requirement to
download it is the file that is called '.hex' file. This file is automatically generated
when the user compile the programming.
The WARP13 software window is shown in this figure below.
45
WARP-13 BINARY MODE ORIVEIt - NEWFOUNDHHHRMCS
File ' Dayfca Program Option;. Comms Help
! |JEaaSli|lHF20it
-Configflil... ' —; 17 MCLR onPm .| 17 W.DogTMRT
r
r
r
.r
:r
;r
'rjr
r
QuickOptions(Notir AuloBlank
Config
"3
.......
NW T ForcolSP...L
r
Code Protection - -11
« Code protect OFF ;
r
1 r
r
r
r
1 C CodeProLeclCN j r
; Cdbiaiion "
• "t-fFF- Caj jr Auto |;_npjr3fi0 r df !•-
r
r
"3"3;
Config HHLLJPIFFFF
Program - FS
jJOOO FFF FFF FFF FFF FFF FFE FFF FFF
inns FFF FFF FFF FFF FFF FFF FFF FFF
1010 FFF FFF FFF FFF FFF FFF PFF FFF
JPie FFF FFF FFF FFF FFF FFF FFF FFF
3PZP FFF FFV FFF FFF FFF FFF FFF FFF
JU?6 FFF FFF FFF FFF FFF FFF FFF YH
3IJ30 FFF FFF FFF FFF FFF FFF FFF FFF
3039 FFF FFF FFF FFF FFF FFF FFF FFF
ferity • F6 Blank • F7- Bead - FB
Projects - --
Unloadprojectfie
Figure 30 Warpl3 PIC programmer.
-Serial No
SerioINo • off
-JSLfil
3.4.3 HyperTerminalapplication
The last element in this output interface experiment is HyperTerminal application
where usually automatically installed in the PC. Its location is shown in the figure
below.
46
0ta £dt Bow [nse^
L^i *»**
1f, - *Set ProgramAccessand betsufts
i_- Windows Catalog
>$ windows LrMtaii-
,£, FraaAOtaurtmited [ntemet
Games
*3| Microsoft Cflice
^ Startup
i$ ireemetExplotoi
V M5N
£5} Outlook Express
,'i Remote Assistance
Q wndows Media Flayer
•^ Windows Messenger
^ Wftdoivs Movie Maker
"§ Microsoft Visual Studio 6.0
f2 Microsoft Web Publishing'~. Kasbio Interactive
'fj inoisetW 1.6
-£j WtiRAR
^) Creative
2J Acrobat Reader S.0
(3 Novel(Comnon)
.^r Oragcn NatualySpeal'ino f
^ Macromedia
£j C-tile Codec Pact
".•4 WrtuolCrive
*3 ValBol Hesferoar
^ Operanjj MortaCrsto
£3 ActMslon
^J fltuasarver Noobpatk
tjrS 1
Mcrosofr Dictation
Microsoft Speeih SDK1 0
Mcrowft Yoke
Atcessibity
Entertainment
System Tools
Address Book
Calculator
Command FTcmpt
Notepad
Paint
ProgramCompatibiltyWizard
Synchronize
Tour Widow *P
Windows Explorer
WotdPad
12 - B / H m ,= .= sf D * A •
Connects Id otrHTcomputers, [ntfipat telnet sites, bulletin^ H?i bandsystems, onlreservlcss, andhostcomputers using
Bithiw a modem » a nJ-modemcable._<j NiW'cmracnorrvnzarc— ] "" '
-,i^ Remote Desktop Connection '
J', Wlr§l«sr4flt«ork5etupWff4fd |•CD Hyperterminfll
Figure 31 The location of HyperTerminal application.
HyperTerminal is a program that user can use to connect to other computers, Telnet
sites, bulletin board systems (BBSs), online services, and host computers, using
either modem or a null modem cable
.^Test - HyperTerminalFje Edit View Call Transfer Help
Connected 0:OQ:30 ' Auto detect Auto detect
Figure 32 HyperTerminal window.
47
4.1 Results.
Operatewindows
application
DNS
command
and dictation
CHAPTER 4
RESULTS AND DISCUSSION
Translation and
read notes.
Controllinghome appliances
Figure 33 Results block diagram.
48
4.2 GUI
For Graphical User Interface part, the author had divided it into four windows which
are Main Menu, Section 1, Section 2 and Section 3. Main Menu windows as shown
in figure below consists title of the program and options to the other sections.
From the Main Menu window, it states all the three sections which are Controlling
other application, Translation and Read notes and Home Automation. To enter the
section of choice, user needs to click on the appropriate button or just simply say the
button command e.g "Section 1".
Application of VoiceRecognition
Control other application
Translation and read
notes
Home Automation
Figure 34 Main menu of the project.
49
Section 1
Section 2
Seciion3
4.2.1 Controlling other application
Once the Section 1 is chosen, the window as shown below is appearing. The window
consists of simple instruction, a text box and main menu button. The text boxhere is
acting as the trigger to open a new or different application. When user speaks to the
microphone, the voice recognition will detect and transcript it to text and display in
the text box provided.
As the example shown, to open the Notepad application user need to say "Start
Notepad" and wait for the application to appear. Then the other command can be
continue such as to write a document, open file and etc. To open another application,
usercan simply say"Start<application>" for the application of choice.
All types of application can be open unless the application is not to complex to spell
out. At this part, the voice recognition software DNS itself play most of the
command. As stated earlier, if only the SDK tools come free with the software then
only the command can run from the visual basic.
"i Control other application
Say "Start<application>-
e.g "Start Notepad"
Figure 35 Section 1 of the project.
50
Main Menu
4.2.2 Translation and Read Notes
For Section 2 - Translation and read Notes, it requires three text box, and two
command buttons. The first text box to recognize the spoken word by user while
second text box is to view the translation word in Malay. As stated in the third text
box, it lets user to paste the note to be read here. When the read button is click, the
computer will read all the textwritten in the text box.
To achieve this, author had program several words only that can be translated by
using Microsoft Access to create database. This is because to show the
demonstration on how it can be done. This is perhaps to be a learning module to kids
or even greater as tool of communication between two person with different
language.
.Translation and Read Notes
Spoken
Translation
<Put notes here>
Read
Main Menu
Figure 36 Section 2 of the project.
51
4.2.3 Home Automation
Last but not least is Home Automation section. This section is more complicated
than the other two because it link with the serial communication port to control the
PIC microcontroller. Home Automation window as shown below consists of
recognition part, home status and button to return to main menu.
Basically this section provide user to control their home appliances by using speech
command. Itwill acting like a remote switch to turn onand offthe application. When
user gives command, the program will compare the speech recognition with the
command database. If the recognition is match it will trigger the output circuitry and
execute the command given. If there is not match the program will ask user to try
again the command.
Home Automation
Detection
Recognize words
Home Status
THE LAMP IS OFF
THE FAN IS OFF
THE DOOR IS CLOSE
I Main Menu
Figure 37 Section 3 of the project.
52
4.3 Choosing microphone
After recognize and try out a few types of microphone, the author had decided to
choose the wireless hand held microphone. The microphone with better performance
can influence the accuracy of speech recognition for this project beside the program
itself. There are reasons why this type of microphone had been chosen.
Firstly, the price of the microphone is within the budget provided by the Final Year
Project committee. The budget is around RM 250 while the price for the microphone
is RM180. Although it is quite expensive, but the Signal-to-Noise (S/N) ratio is high
which is larger than lOOdB. If compared to other less expensive microphone, this
wireless microphone is more robust.
Due to the high S/N ratio, the voice recognition is more accurate compared to other
microphone. This wireless microphone is included with receiver which able the
service areas around 50 meters in the best condition. The best condition indicate that
the quite and noise free environment.
Moreover, wireless microphone is free with problem tangling or caught up with long
wire. Therefore this makes it easy to handle. The details of the overall specification
can be found in appendix.
53
4.4 Programming PIC16F84
As stated earlier, to program the microcontroller PIC the author chooses to use PIC
Simulator IDE. Figure below shows the BASIC compiler where the programming is
been done. ASCII code is chosen to be the medium of data transmission.
BASIC Compiler fina!1 .bas
File Edit Tools Help
Microcontroller: PIC16F84; Clock Frequency: 4.0 MHz
Diiti i As Byte 'declare a variable
TRI3B = %OOO00100 'set PORTB Bit 2 As input(receive pin)
loop:
If i = 53 Then 'door open
PORTB.5 = 1 'set bit 5 high
Endif
If i = 54 Then 'door close
PORTB.5 = 0 'set bit 5 low
Endif
If i = 51 Then 'fan on
PORTB.4 = 1
|EndifIf i = 52 Then 'fan off
PORTB.4 = 0
Endif
If i = 49 Then 'lamp on
PORTB.3 = 1
Endif
If i = 50 Then 'lamp off
PORTB.3 = 0
Endif
iserin PORTB.2, 9600, i 'set baud rate as serial port(Goto loop 'loop forever
Lin 14, Col 0
Figure 38 BASIC Compiler window.
The details on circuitry are attached to the appendix.
54
CHAPTER 5
CONCLUSION AND RECOMMENDATION
5.1 Challenges and problems
As conclusion, the project is success although there are some problems that interfere.
The first problem in this project is to find the best speech recognition software in the
market. There are lots of the software where it needs to be familiarize before decided
to apply in the project.
Another one is challenge to keep the accuracy of the speech recognition. There are
few factors that can reduce accuracy to recognize the spoken words. First is the type
of microphone chosen need to have high S/N ratio. This will help to eliminate the
noise better. Second is the environment where to apply this system the place need to
be quite and peace.
Last but not least, is user condition and emotion. The condition of the user needs to
be normal as possible so that the words spoken are clear and easy to recognize.
When user had a cough or fevers their tone and pitch of voice is changes and will
affect the system to recognize the user.
55
5.2 Recommendation
To achieve better performance of the system, it is recommended to use high quality
input hardware for microphone and sound card. But due to cost constraint, it cannot
achieve for this project. For the system to be global, means everyone can use it, the
system should allow to recognize different accent and voice pitch of person. To
achieve this new guideline for the standardize and simple command need to be
create.
56
REFERENCES
1. History of Speech & Voice Recognition and Transcription Software,
http://www.dragon-medical4ranscription.com/history speech recognition.html
2. A Timeline & History of Voice Recognition Software, http://www.dragon-
medical4ranscription.com/historv speech_recognition_timeline.html
3. Article of Speech Recognition, Gunish Rai Chawla,
http://www.develoDerdotstar.com/communitv/user/49/
4. How Microphone Works,
http://electronics.howstuffvvorks.com/question309.htm
5. How Sound Card Works,
http://computer.howstuffworks.com/sound-card2.htm
6. Programming the PICController, http://www.microchip.com/
7. PIC Tutorial, http://www.mstracev.btinternet.co.uk/index.htm
8. PIC Simulator IDE, http://www.oshonsoft.com/index.html
9. PIC 16F84 Fundamental,
http://www.boondog.eom//tutorials/picl6F84/picl6f84.html#Overview
10. Microchip PIC Project, http://www.users.bigpond.com/armagh/page2.html
11. PICProgrammer, http://www.bobblick.com/index.html
12. Error in Opening Comm port in VB, http://www.control.com/index html
13. Visual Basic Tutorial, http://wvvw.vbtutor.net/vbtutor.html
14. General PIC tutorial, http://www.sparkfun.com/tutorial/coding/l-intro.htm
15. Home Automated Living, http://wwvv.automatedliving.com/
16. Home Automation System,
http://wvvw.chiark.greenend.org.uk/~theom/electronics/has/index.html
17. Voice Recognition Project, Wan Zahara's Report.
18. Home Surveillance Project, Wan Nubli's Report
19. Microsoft Speech SDK Getting Help.
57
APPENDICES
Appendix A PIC 16F84 Connection 59
Appendix B MAX232 Connection 60
Appendix C Table of Ascii code 61
Appendix DTable of ascii code 62
Appendix E User Manual to Operate the system 63
Appendix F Visual Basic Source Code 64
Appendix G Coding for PIC 65
Appendix H PIC Simulator Manual 69
58
_6_RX DATA 7
TX DATA 8
LED 3
•'hKh
APPENDIX A
PIC16F84 CONNECTION
RA2
RA3
RA4
MCLR
Vss
RBO/INT
RB1
RB2
RB3
RA1
RAO
SC1
OSC2
Vdd
RB7
RB6
RB5
RB4
18
17
16
15
14
13
12
11 .1M
vex
LED1
-OH
•OH'LED I
5V
4Mhz
7ND
Legend:
Vss = GND
Vdd - +5V
SCI = External clock
RBI = Transmit data to MAX232
RB2 = Receive data from MAX232
RB3 = RB4 - RB5 = Output pin
Figure above shows the basic connection of microcontroller PIC16F84 which used in
the project. The PIC is power up with +5V power supply and the timing is set by the
crystal clock 4Mhz. The microcontroller will receive data from the PC through the
MAX232 chip. Then the program inside the PIC will read the received data and
determine which output pin should be high or low.
59
Transmitted data firom PIC
Received data to PIC
APPENDIX B
MAX232 CONNECTION
C71u
E\\M
£
TXDATA
RXDATA
CI1uF
11
10
12
C1+ W V+
C1- > v-C2+ Tlout
C2- T2out
Tlin R1in
T2in R2in
RlOUt gR2out o
14
7
13
KSSSQ91uF
^f^jC101uF
MAX232
QO
QO-^
QO
QO
aCONN-D9
RS232 DB9 FEMALE
GND
Legend:
Vcc = +5V
GND = OV
Tl in = Received transmitted data from PIC
Rlout = Transmit data to PIC
Tlout = Transmit data to communication serial port
Rl in = Received data from communication serial port
Figure above shows the basic connection of MAX232 between PIC16F84 and
communication serial port. The chip is power up with +5V power supply. MAX232 is
behave to translate the output data (analog) from PC which used ASCII as data
transmit format (digital) to microcontroller PIC.
60
APPENDIX C
TABLE OF ASCII CODE
Dec HxOct Char Dec Hx Oct Html Chr Dec Hx Oct Html Chr Dec Hx Oct Html Chr
0 0 000 HUL (null) 32 20 040 £#32; Space 64 40 100 £#64, % 96 60 140 £#96
1 1 001 SOH (start of heading) 33 21 041 £#33; ! 65 41 101 £#65, A 97 61 141 £#97 a
2 2 002 3TX (start of text) 34 22 042 £#34; " 66 42 102 £#66, B 98 62 142 £#98 b
3 3 003 ETC (end of text) 35 23 043 £#35; # 67 43 103 £#67, C 99 63 143 £#99 c
4 4 004 EOT (end of transmission) 36 24 044 $ $ 68 44 104 £#68, D 100 64 144 £#100; d
5 5 005 EHQ (enquiry) 37 25 045 £#37; H 69 45 105 £#69, E 101 65 145 £#101; e
6 6 006 ACK (acknowledge) 38 26 046 4#38; & 70 46 106 £#70 F 102 66 146 £#102; f
7 7 007 BEL (bell) 39 27 047 6039; ' 71 47 107 £#71 G 103 67 147 £#103; g
8 8 010 BS (backspace) 40 28 050 £#40; ( 72 48 110 £#72 H 104 68 150 £#104; h
9 9 011 TAB (horizontal tab) 41 29 051 £141; ) 73 49 111 £#73 I 105 69 151 £#105; i
10 A 012 LF (WL line feed, new line) 42 2A 052 £#42; * 74 4A 112 £#74 J 106 6A 152 £#106; j
11 B 013 7T (vertical tab) 43 2B 053 4#43; + 75 4B 113 £#75 K 107 6B 153 £#107; k
12 C 014 FF (UP form feed, new page] 44 2C 054 4#44; , 76 4C 114 £#76 L 108 6C 154 £#108; 1
13 D 015 CR (carriage return) 45 2D 055 4#45; - 77 4D 115 £#77 H 109 6D 155 £#109; i
14 E 016 SO [shift out) 46 2E 056 £#46; . 78 4E 116 £#78 If 110 6E 156 £#H0; n
15 F 017 31 (shift in) 47 2F 057 £#47; / 79 4F 117 £#79 0 111 6F 157 £#111; o
16 10 020 DIE (data link escape) 48 30 060 £#48; 0 80 50 120 £#80 P 112 70 160 £#H2; P
17 11 021 DC1 (device control 1) 49 31 061 £#49; i 81 51 121 £#31 0 113 71 161 £#H3; q
18 12 022 IC2 (device control 2) 50 32 062 £#50; 2 82 52 122 £#82 p. 114 72 162 £#114; r
19 13 023 DC3 [device control 3) 51 33 063 4*51; 3 83 53 123 £#83 3 115 73 163 £#115; 3
20 14 024 DC4 (device control 4) 52 34 064 £#52; 4 84 54 124 £#84 T 116 74 164 £#H6; t
21 15 025 UAK (negative acknowledge) 53 35 065 £#53; 5 85 55 125 £#85 U 117 75 165 £#H7; u
22 16 026 SYfl (synchronous idle) 54 36 066 £#54; 6 86 56 126 £#86 V 118 76 166 £#118; v
23 17 027 ETB (end of trans, block) 55 37 067 4#55; 7 87 57 127 £#87 U 119 77 167 £#H9; u
24 18 030 CM (cancel) 56 38 070 £#56; 8 88 58 130 £#88 X 120 78 170 £#120; x
25 19 031 EM (end of medium) 57 39 071 £#57; 9 89 59 131 £#89 Y 121 79 171 4*121; Y
26 1A 032 SUB (substitute) 58 3A 072 £#58; : 90 5A 132 £#90 I 122 7A 172 £#122; z
27 IB 033 ESC (escape) 59 3B 073 £#59; ; 91 5B 133 £#91 [ 123 7B 173 £#123; !
28 1C 034 F3 (file separator) 60 3C 074 4#60; < 92 5C 134 £#92 ; \ 124 7C 174 £#124; 1
29 ID 035 03 (group separator) 61 3D 075 4161; = 93 5D 135 £#93 ; 1 125 7D 175 £#125; ]
30 IE 036 ES (record separator) 62 3E 076 &I62; > 94 5E 136 £#94 . h 126 7E 176 £#126; •-
31 IF 037 US (unit separator) 63 3F 077 £#63; ? 95 5F 137 £#95 ' „127 7F 177 £#127; DEL
Source: www.asciitable.com
61
APPENDIX D
TABLE OF ASCII CODE
128 r: 144 E 160 a 176 193 J_ 209 T 225 & 241 ±
129 i'j 145 a 161 i 177 194 T 210 F 226 r 242 >
no e 146 M 162 6 178 I 195 |- 211 li 227 n 243 K
131 a 147 6 163 u 179 | 196 _ 212 L 228 £ 244 r
132 a 143 0 164 n 180 i 197 f 213 F 229 a 245 j
133 a 149 6 165 N 181 H 198 F 214 fr 230 P- 246 -
1340
150 "U 1663
182 II 199 Ih 215 f 231 i; 247 K
135 'l 151 u 167O 183 ti 200 Ik 216 + 232 <$. 248 *
136 % 152 168 6 184 i 201 If 217 j 233 © 249
137 e 153 6 169 185 ii 202 JL 218 r 234 Q 250
138 e 154 u 170 —i 186 1 203 TT 219 1 235 6 251 4
139 i 156 i 171 1v? 187 Tl 204 ILlr 220 • 236 K> 252
_
140 i 157 ¥ 172 ¥* 18S Jl 205 = 221 i 237 + 253 2
141 i 158 173 l 189 Jf 206 JLt 222 i 238 s 254 B
142 £_ 159 / 174 <K 190 J 207 i 223 • 239 r-i 255
143 A 192 L 175 v. 191 1 208 JL 224 a 240 s
Source: www.asciitable.com
62
APPENDIX E
USER MANUAL TO OPERATE THE SYSTEM
63
SY
ST
EM
OP
ER
AT
ION
(US
ER
MA
NU
AL
)
PR
OC
ES
S/P
RO
CE
DU
RE
Inst
all
ati
on
soft
ware
Inst
all
ati
on
hard
ware
Tur
non
soft
war
eap
plic
atio
n
Con
trol
ling
othe
rw
indo
wap
plic
atio
ns.
DR
AG
ON
NA
TU
RA
LL
YS
PE
AK
IN
G
1.In
sert
CD
into
Cd
-RO
M
2.
Fo
llo
win
stru
cti
on
of
the
inst
all
ati
on
wiz
ard
.
3.T
rain
the
Dra
go
nN
atur
ally
Spe
akin
gby
foll
owin
gth
etu
tori
al.
1.M
ake
sure
that
mic
roph
one
ispr
oper
lyco
nnec
ted.
2.S
wit
chon
the
mic
roph
one.
1.S
tart
the
Dra
go
nN
atur
ally
Spe
akin
gap
plic
atio
n.
2.
Do
ub
lecli
ck
the
ico
nD
NS
.ex
eo
n
the
desk
top.
VIS
UA
LB
AS
IC
1.C
opy
file
"Voi
ceR
ecog
niti
on.e
xe"
tode
skto
p.
1.S
tart
the
voic
ere
cogn
itio
nap
plic
atio
n.
2.
Do
ub
lecli
ck
the
ico
nV
oic
e
Rec
ogni
tion
.exe
onth
ede
skto
p.
1.C
lick
on
the
Secti
on
1b
utt
on
.
2.S
tart
desi
red
appl
icat
ion
bysa
ying
"Sta
rt<
app!
icat
ion>
".
PIC
CO
NT
RO
LL
ER
1.C
onne
ctth
e9-
pin
fem
ale
co
nn
ecto
rfr
om
cir
cu
itto
the
PC
.
2.
Tu
rno
nth
ecir
cu
it.
3.e.
g;"
Star
tN
otep
ad".
Ref
erto
figu
rein
App
.E
l.
Usi
ngtr
ansl
atio
nan
dre
adn
ote
s.
1.C
lick
on
the
Secti
on
2b
utt
on
.
2.S
tart
sayi
ngw
ords
that
need
tran
slati
on
.
3.C
opy
text
that
need
sto
bere
adan
dpa
ste
inth
ebo
xpr
ovid
ed.
4.
Cli
ck
the
read
bu
tto
nan
dle
t
com
pute
rre
adth
ete
xt.
5.R
efer
tofi
gure
inA
pp.
E2.
Usi
ngho
me
auto
mat
ion
syst
em
.
1.C
lick
on
the
Secti
on
3b
utt
on
.
2.Sa
yth
eap
prop
riat
eco
mm
and
toop
erat
eth
eci
rcui
t.
3.
Ch
eck
the
statu
sat
ho
me
statu
s
box.
Ref
erto
figu
rein
App
.E
3.
1.C
hec
kth
est
atu
so
fL
ED
,b
uzzer
an
dfa
n.
2.R
efer
tofi
gure
inA
pp.
E3.
Clo
seth
esy
stem
1.S
wit
cho
ffth
em
icro
phon
ean
dclo
se
the
soft
ware
.
1.C
lick
on
the
clo
seb
utt
on
.1.
Tu
rno
ffcir
cu
it.
Ap
p.E
l
'̂MaV
M.e
njfl
App
lica
tion
ofV
oice
Rec
og
nit
ion
Co
ntr
ol
oth
er
ap
pli
cati
on
1S
ecti
on
1!
Tra
nsla
tio
na
nd
rea
d
no
tes
Secti
on
2
Ho
me
Au
tom
ati
on
Sec
tio
n3
Sa
y"S
tart
<a
pp
lica
tio
n>
"
e.g
"Sta
rtN
otep
ad"
Mai
nM
enu
Ap
p.
E2
Slif
lfey
^'ji
App
lica
tion
ofV
oice
Rec
og
nit
ion
Co
ntr
ol
oth
er
ap
pli
ca
tio
n]
Sec
tio
n!
1
Tra
nsla
tio
na
nd
rea
d
no
tes
Sec
tio
n2
Ho
me
Au
tom
ati
on
Sec
tio
n3
ito
Eil
lili
Jfc
ilm
ms^
hs^
Sp
oken
Igoo
dm
orni
ng
Tra
nsl
ati
on
Sela
mai
pagi
<P
ut
no
tes
hei
e>
Sp
oken
Tra
nsla
tio
n
For
Sec
tio
n2
•T
ran
slat
ion
an
dre
adM
otes
,itr
equi
rest
hree
tent
box,
and
two
com
man
db
utt
on
s.T
he
firs
tte
xtbo
xto
reco
gniz
eth
esp
oken
wot
dby
user
whi
lese
co
nd
text
box
isto
vie
wth
etr
ansl
atio
nw
ord
inM
alay
.As
stat
edin
the
thir
dte
ntbo
x.it
lets
user
top
aste
the
note
tobe
read
her
e.W
hen
the
read
bu
tto
nis
clic
k,
the
com
pute
rwill
read
allt
hete
xtw
ritte
nin
the
text
box.
1
Read
Mai
nM
en
u
Read
Mai
nM
en
u
Ap
p.
E3 A
ppli
cati
onof
Voi
ceR
ecog
niti
on
Co
ntr
ol
oth
er
ap
pli
ca
tio
n
Tra
nsla
tio
na
nd
rea
d
no
tes
Ho
me
Au
tom
ati
on
Secti
on
1
Secti
on
2
Secti
on
3
~i;
rfiZc
Vi.
•:::;
Vrv
-I
|.:»
#^
,-\i
H'\
fey
-J^'
iV*
ft
Dete
cti
on
Reco
gn
ize
wo
rds
LAM
P0N
|
Ho
me
Sta
tus
-
WM
THE
LAM
PIS
ON
TH
EFA
NIS
OFF
TH
ED
OO
RIS
CL
OS
E
Mai
nM
en
u
APPENDIX F
VISUAL BASIC SOURCE CODE
64
Main
Men
uW
ind
ow
So
urc
eC
od
e
Pri
vate
Sub
Com
man
dl_C
lick
()fr
mM
ain
.Hid
e
frm
App
.Sho
wE
nd
Su
b
Pri
vate
Sub
Com
man
d2_C
lick
()fr
mM
ain
.Hid
e
frm
Tra
ns.
Sh
ow
En
dS
ub
Pri
vate
Sub
Com
man
d3_C
lick
()fr
mM
ain
.Hid
e
frm
Ho
me.S
ho
w
En
dS
ub
Secti
on
1W
ind
ow
So
urc
eC
od
e
Pri
vate
Sub
Com
man
dl_
Cli
ck()
rrm
App
.Hid
efr
mM
ain
.Sh
ow
En
dS
ub
Secti
on
2W
ind
ow
So
urc
eC
od
e
Pri
vate
Sub
Co
mm
and
l_C
lick
()fr
mT
ran
s.H
ide
frm
Main
.Sh
ow
En
dS
ub
Pri
vate
Sub
Com
man
d2_C
lick
()If
Com
man
d2.C
apti
on=
"Rea
d"T
hen
tts.
Spe
akT
ext1
.Tex
tC
omm
and2
.Cap
tion
="S
top"
Els
e
IfC
omm
and2
.Cap
tion
="S
top"
Th
entt
s.S
topS
peak
ing
Com
man
d2.C
apti
on=
"Rea
d"E
nd
if
En
dif
En
dS
ub
Pri
vate
Sub
txtS
pk_C
hang
e()
Ad
od
cl
.Reco
rdse
t.M
ov
eF
irst
Do
Un
til
Ad
od
cl.
Reco
rdse
t.E
OF
IfA
dodc
l.R
ecor
dset
.Fie
lds(
"Spo
ken"
).V
alue
=tx
tSpk
.Tex
tT
hen
txtT
ran
s.D
ata
Fie
ld=
"Tra
nsl
ati
on
"
Ex
itS
ub
Eis
e
Ad
od
c1.
Reco
rdse
t.M
ov
eN
ex
t
En
dif
Lo
op
txtS
pk.T
ext
-""
txtT
rans
.Tex
t=
"<U
nrec
ogni
zed
wor
d>'
En
dS
ub
Secti
on
3W
ind
ow
So
urc
eC
od
e
Pri
vate
Sub
Com
man
dl_C
Iick
()
frm
Ho
me.H
ide
frm
Main
.Sh
ow
En
dS
ub
Pri
vate
Sub
For
m_L
oad(
)
'op
enp
ort
MS
Co
mm
l.C
om
mP
ort
=1
MS
Co
mm
l.S
etti
ng
s-
"960
0,11
,8,1
"M
SC
om
ml.
Po
rtO
pen
=T
rue
'in
itia
lsco
nd
itio
n
lblL
amp.
Bac
kCoI
or=
vbR
edlb
lLam
pSta
t.Cap
tion
-"T
HE
LA
MP
ISO
FF'
lblF
an
.Back
Co
lor
=v
bR
ed
IblF
anS
tat.
Cap
tion
="T
HE
FAN
ISO
FF"
lblD
oo
r.B
ack
Co
lor
=v
bR
ed
IblD
oorS
tat.
Cap
tion
="T
HE
DO
OR
ISC
LO
SE
"E
nd
Su
b
Pri
vate
Sub
IblD
oor_
Cha
nge(
)If
lblD
oo
r.B
ack
Co
lor
=v
bR
ed
Th
en
IblD
oorS
tat.
Cap
tion
-"T
HE
DO
OR
ISC
LO
SE
"E
lse
IblD
oorS
tat.
Cap
tion
="T
HE
DO
OR
ISO
PE
N"
En
dIf
En
dS
ub
Pri
vate
Sub
lblF
an_C
hang
e()
Iflb
lFan
.Back
Co
lor
-v
bR
ed
Th
en
IblF
anS
tat.
Cap
tion
="T
HE
FAN
ISO
FF"
Els
e
IblF
anS
tat.
Cap
tion
="T
HE
FAN
ISO
N"
En
dIf
En
dS
ub
Pri
vate
Sub
lblL
amp_
Cha
nge(
)If
lblL
amp.
Bac
kCoI
or=
vbR
edT
hen
lblL
ampS
tat.C
apti
on=
"TH
EL
AM
PIS
OFF
"E
lse
lblL
ampS
tat.C
apti
on=
"TH
EL
AM
PIS
ON
"E
nd
if
En
dS
ub
Pri
vate
Sub
txtD
ict
Cha
ngeQ
Dim
txtl
As
Str
ing
txtl
=tx
tDic
t.T
ex
t
ado
Vo
ice.
Rec
ord
set.
Mo
veF
irst
Do
Un
til
ado
Vo
ice.
Rec
ord
set.
EO
FIf
adoV
oice
.Rec
ords
et.F
ield
s("L
ampO
n").
Val
ue-
txtl
The
nT
ex
t2.T
ex
t=
"LA
MP
ON
"
lblL
ampS
tat.C
apti
on=
"LA
MP
ON
"tx
tRec
.Tex
t=
"Lam
pO
n"M
SC
omm
l.O
utpu
t=C
hr(4
9)lb
lLam
p.B
ackC
oIor
=vb
Gre
enE
xit
Su
b
Els
e
ad
oV
oic
e.R
eco
rdse
t.M
ov
eN
ex
t
En
dif
Lo
op
ado
Vo
ice.
Rec
ord
set.
Mo
veF
irst
Do
Un
til
ad
oV
oic
e.R
eco
rdse
t.E
OF
Ifad
oVoi
ce.R
ecor
dset
.Fie
lds(
"Lam
pOff
').V
alue
=tx
tlT
hen
Tex
t2.T
ex
t-
"L
AM
PO
FF
"
lblL
ampS
tat.C
aptio
n-
"LA
MP
OFF
"tx
tRec
.Tex
t=
"Lam
pO
ffM
SC
omm
I.O
utpu
t=C
hr(5
0)lb
lLam
p.B
ackC
oIor
=vb
Red
Ex
itS
ub
Els
e
ad
oV
oic
e.R
eco
rdse
t.M
ov
eN
ex
t
En
dIf
Lo
op
ad
oV
oic
e.R
eco
rdse
t.M
ov
eF
irst
Do
Un
til
ad
oV
oic
e.R
eco
rdse
t.E
OF
Ifad
oVoi
ce.R
ecor
dset
.Fie
lds(
"Fan
On"
).V
alue
=tx
tlT
hen
Tex
t2.T
ex
t="F
AN
ON
"
IblF
anS
tat.
Cap
tion
="F
AN
ON
"tx
tRec.T
ex
t=
"F
an
On
"
MS
Co
mm
l.O
utp
ut
-C
hr(5
1)lb
lFan
.Back
Co
lor
=v
bG
reen
Ex
itS
ub
Els
e
ad
oV
oic
e.R
eco
rdse
t.M
ov
eN
ex
t
En
dif
Lo
op
ad
oV
oic
e.R
eco
rdse
t.M
ov
eF
irst
Do
Un
til
ad
oV
oic
e.R
eco
rdse
t.E
OF
Ifad
oVoi
ce.R
ecor
dset
.Fie
lds(
"Fan
Off
').V
alue
-tx
tlT
hen
Tex
t2.T
ex
t="F
AN
OF
F"
IblF
anS
tat.
Cap
tion
="F
AN
OFF
"tx
tRec.T
ex
t=
"Fan
Off
MS
Com
ml.
Out
put
=C
hr(5
2)lb
lFan
.Back
Co
lor
=v
bR
ed
Ex
itS
ub
Els
e
ad
oV
oic
e.R
eco
rdse
t.M
ov
eN
ex
t
En
dif
Lo
op
ado
Vo
ice.
Rec
ord
set.
Mo
veF
irst
Do
Un
til
ad
oV
oic
e.R
eco
rdse
t.E
OF
Ifad
oVoi
ce.R
ecor
dset
.Fie
lds(
"Ope
n").
Val
ue=
txtl
The
nT
ex
t2.T
ex
t=
"DO
OR
OP
EN
"
IblD
oorS
tat.
Cap
tion
="D
OO
RO
PEN
"tx
tRec
.Tex
t-
"Ope
nD
oor"
MS
Co
mm
1.O
utpu
t-C
hr(5
3)lb
lDo
or.
Back
Co
lor
=v
bG
reen
Ex
itS
ub
Els
e
ad
oV
oic
e.R
eco
rdse
t.M
ov
eN
ex
t
En
dIf
Lo
op
ado
Vo
ice.
Rec
ord
set.
Mo
veF
irst
Do
Un
til
ado
Vo
ice.
Rec
ord
set.
EO
FIf
adoV
oice
.Rec
ords
et.F
ield
s("C
lose
").V
alue
=tx
tlT
hen
Tex
t2.T
ex
t-
"D
OO
RC
LO
SE
"Ib
lDoo
rSta
t.Cap
tion
-"D
OO
RC
LO
SE"
txtR
ec.T
ex
t=
"C
lose
Do
or"
MS
Com
ml.
Out
put
=C
hr{5
4)lb
lDo
or.
Back
Co
lor
=v
bR
ed
Ex
itS
ub
Els
e
ad
oV
oic
e.R
eco
rdse
t.M
ov
eN
ex
t
En
dIf
Lo
op
Tex
t2.T
ex
t=
""
txtD
ict.
Tex
t=
""
txtR
ec.T
ext
="<
Un
reco
gn
ized
wo
rd>
'
En
dS
ub
APPENDIX G
CODING FOR PIC
l.",basfile" .PORTB.5 = 0 'set bit 5 low
Endif
If i = 51 Then 'fan on
PORTB .4 = 1
Endif
If i = 52 Then 'fan off
PORTB .4 = 0
Endif
If i = 49 Then 'lamp onPORTB.3 = 1
Endif
Ifi = 50Then 'lamp offPORTB.3 - 0
Endif
Serin PORTB.2, 9600, i 'set baud rate as serial portGoto loop 'loop forever _^^_____
2. ".asm file"
; BeginROL EQU OxCROH EQU OxDR1L EQU OxER1H EQU OxFR2L EQU 0x10R2H EQU 0x11R3L EQU 0x12R3H EQU 0x13R4L EQU 0x14R4H EQU 0x15R5L EQU 0x16R5H EQU 0x17SO_PORTEQU0xl8SO_BIT EQU 0x19SOJNTL EQU OxlASOJNTHEQUOxlBORG 0x0000
BCF PCLATH.3BCF PCLATH,4GOTO L0002
ORG 0x0004
RETFIE
L0002:
; 1: Dim i As Byte 'declare a variable; The address of? is OxlC
i EQU OxlC;2:; 3: TRISB = %00000100 'setPORTB Bit2 As input(receive pin)
BSF STATUS,RP0MOVLW 0x04
MOVWF 0x06
BCF STATUS,RP0 „_^
65
;4:; 5: loop:L0001:
; 6: If i = 53 Then 'door openMOVF OxlC,W
SUBLW 0x35
BTFSS STATUS,ZGOTO L0003
;7:PORTB.5= 1 'set bit 5 highBSF 0x06,5
; 8: EndifL0003: MOVLWOxlF
ANDWF STATUS,F;9: If i = 54 Then 'door close
MOVF 0xlC,WSUBLW 0x36
BTFSS STATUS,Z
GOTO L0004
; 10: PORTB.5 = 0 'set bit 5 lowBCF 0x06,5
; 11: EndifL0004: MOVLWOxlF
ANDWF STATUS,F; 12: iri = 51 Then'fan on
MOVF 0xlC,W
SUBLW 0x33
BTFSS STATUS,Z
GOTO L0005
; 13:PORTB.4= IBSF 0x06,4
; 14: EndifL0005: MOVLWOxlF
ANDWF STATUS,F
; 15: If i = 52 Then 'fan offMOVF0xlC,WSUBLW 0x34
BTFSS STATUS,ZGOTO L0006
; 16:PORTB.4 = 0BCF 0x06,4
; 17: EndifL0006: MOVLWOxlF
ANDWF STATUS,F; 18: If i = 49 Then'lamp on
MOVF OxlQW
SUBLW 0x31
BTFSS STATUS,Z
GOTO L0007
; 19: P0RTB3 = 1BSF 0x06,3
; 20: EndifL0007: MOVLWOxlF
ANDWF STATUS,F
; 21: Ifi = 50 Then'lamp offMOVF0xlC,W
SUBLW 0x32
BTFSS STATUS,Z
GOTO L0008
; 22: PORTB.3 = 0BCF 0x06,3
; 23: Endif
66
L0008: MOVLWOxlFANDWF STATUS,F
;24:; 25: Serin PORTB.2, 9600, i 'set baud rate as serial port
BSF STATUS,RP0
BSF TRISB,2BCF STATUS,RP0
MOVLW 0x06
MOVWF SO_PORTMOVLW 0x04
MOVWF SO_BITMOVLW 0x5B
MOVWF SOJNTLMOVLW 0x00
MOVWF SOJNTHCALL SI01
MOVWF OxlC
; 26: Goto loop 'loop foreverGOTOL0001
27:
28:
29:
End of programL0009: GOTOL0009
; Waitus Routine - Word ArgumentY001: MOVLW 0x10
SUBWF R4L,FCLRW
BTFSS STATUS,C
ADDLW 0x01
SUBWF R4H,FBTFSS STATUS,CRETURN
GOTO Y002
Y002: MOVLW OxOA
SUBWF R4L,F
CLRW
BTFSS STATUS,CADDLW 0x01
SUBWF R4H,FBTFSS STATUS,C
RETURN
GOTO Y002
; Serin RoutineS101: CALLSI03
BTFSC STATUS,CGOTO SI01
MOVF SO_INTL,WMOVWF R4L
MOVF SO_INTH,WMOVWF R4H
RRF R4H,F
RRF R4L,F
BCF STATUS.CRRF R4H,F
RRF R4L,F
CALL Y001
MOVLW 0x08
MOVWF R5H
SI02: MOVF SO_INTL,WMOVWF R4L
67
MOVF SO_INTH,WMOVWF R4H
CALLY001
CALL SI03
RRF R5L,F
DECFSZ R5H,F
GOTO SI02
MOVF SO_INTL,WMOVWF R4L
MOVF SO_INTH,WMOVWF R4H
CALLY001
MOVF R5L,WRETURN
SI03: MOVF SO_PORT,WMOVWF FSR
MOVF SO_BIT,WANDWF INDF,WADDLW OxFF
RETURN
; End of listingEND
68
APPENDIX H
PIC SIMULATOR MANUAL
Default extension for basic source files is BAS. The compiler output is assembler source file (withASM extension) that can be translated to binary code using integrated assembler. Smart editor marksall reserved keywords in different color, that simplifies debugging process. BASIC compiler'sassembler output has all necessary comment lines, that makes it very useful for educational purposes,also.
Three data types are supported:- Bit (1-bit, 0 or 1)- Byte (1-byte integers in the range 0 to 255)- Word (2-byte integers in the range 0 to 65,535)
Declarations may be placed anywhere in the program. All variables are considered global. The totalnumber of variables is limited by the available microcontroller RAM memory. Variables are declaredusingDIM statement:
DIM A AS BIT
DIM B AS BYTE
DIM X AS WORD
It is also possible to useone-dimensional arrays. For example:DIM A(10) AS BYTEdeclares an array of 10 Byte variables with array index in the range[0-9].
RESERVE statement allows advanced usage by reserving some of the RAM locations to be usedby in-code assembler routines or by MPLAB In-Circuit Debugger. For example:RESERVE 0x70
It is possible to make conversions between Byte and Word data types using .LB and .HB extensions ordirectly:DIM A AS BYTE
DIM B AS WORD
A = B.HB
A = B.LB 'This statement is equivalent to A = BB.HB = A
B.LB = A
B = A 'This statement will also clear the high byte of B variable
All special function registers (SFRs) are available as Byte variables in basic programs. Individual bitsof a Byte variable can beaddressed by .0, .1, .2, .3, .4, .5, .6 and .7 extensions or using official namesof the bits:
DIM A AS BIT
DIM B AS BYTE
A = B.7
B.6= 1
TRISA.l =0
TRISB = 0
PORTA. 1 = 1
PORTB = 255
STATUS.RPO = 1
INTCON.INTF = 0
69
Standard short forms for accessing port registers and individual chip pins are also available (RA, RB,RC, RD, RE can be used as Byte variables; RAO, RA1, RA2, ..., RE6, RE7 are available as Bitvariables):RA = OxFF
RB0= 1
It is also possible to usesymbolic names (symbols) in programs:SYMBOL LED1 = PORTB.O
LED1 = 1
SYMBOLAD_ACTION = ADCON0.GO_DONE
Constants can be used in decimal number system with no special marks, in hexadecimal numbersystem with leading Ox notation (or with H at the end) and in binary system with leading % mark (orwithB at theend). Keywords True and Falseare also available for Bit type constants.For example:DIM A AS BIT
DIM BAS BYTE
A = TRUE
B = 0x55
B = %01010101
Constants can also be assigned to symbolic names using CONST directive:DIM A AS WORD
C0NSTP1 = 314
A = PI
There are three statements that are used for bit manipulation - HIGH, LOW and TOGGLE. If theargument of these statements is a bit in one of the PORT registers, then the same bit in thecorresponding TRIS register is automatically cleared, setting the affected pin as an output pin. Someexamples:HIGH PORTB.O
LOW ADCON0.ADON
TOGGLE OPTION_REG.INTEDG
Five arithmetic operations (+, -, *, /, MOD) are available for Byte and Word data types. The compileris able to compile all possible complex arithmetic expressions. Forexample:DIM A AS WORD
DIM B AS WORD
DIM X AS WORD
A =123
B = A*234
X = (12345-B*X)/(A + B)
Square root ofa number can becalculated using SQR function:DIM A AS WORDA = 3600
A = SQR(A)
For Bit data type variables seven logical operations are available. It is possible to make only onelogical operation in one single statement. Logical operations are also available for Byte and Wordvariables. For example:DIM A AS BIT
DIM B AS BIT
DIM X AS BIT
X = NOT A
X = A AND B
X = A OR B
X = A XOR B
X = A NAND B
X = A NOR B
70
X = A NXOR B
DIM A AS WORD
DIM B AS WORD
A = A OR B
PORTB = PORTC AND %11110000
There are two parameters CONF_WORD and CONF_WORD_2 (not available for all devices) that canbe set usingDEFINE directive to override the defaultvalues:DEFINE CONF_WORD = 0x3F72
The GOTO statement uses line label name as argument. Line labels must be followed by colon mark":". Here is one example:DIM A AS WORD
A = 0
loop: A = A + 1GOTO loop
WAITMS and WAITUS statements can be used to force program to wait for the specified number ofmilliseconds or microseconds. It is aiso possible to use variable argument of Byte or Word data type.These routines use Clock Frequency parameter that can bechanged from the Options menu. WAITUSroutine has minimal delay and step that alsodepends on the ClockFrequency parameter.DIM A AS WORD
A= 100
WAITMS A
WAITUS 50
PLEASE NOTE: When writing programs for real PIC devices you will most likely use delay intervalsthat are comaprable to 1 second or 1000 milliseconds. Many examples in this help file also use such'real-time' intervals. But, if you want to simulate those programs you have to be very patient to seesomething to happen, even on very powerful PCs available today. For simulation of 'WaitMs 1000'statement on 4MHz you have to wait the simulator to simulate 1000000 instructions and it will takeconsiderable amount of time even if 'extremely fast' simulation rate is selected. So, just for the purposeof simulation you should recompile your programs with adjusted delay intervals, that should notexceed l-10ms. But, be sure to recompile your program with original delays before you download it toa real device.
Access to EEPROM data memory can be programmed using READ and WRITE statements. The firstargument is the address ofa byte in EEPROM memory and can be a constant or Byte variable. Thesecond argument is data that is read or written (for READ statement it must be a Byte variable). It issuggested to keep interrupts disabled during theexecution of WRITE statement.DIM A AS BYTE
DIM B AS BYTE
A= 10
READ A, BWRITE 11, B
Three standard BASIC statements are supported:FOR-TO-STEP-NEXT, WHILE-WEND and IF-THEN-ELSE-ENDIF.Here are several examples:DIM A AS BYTE
TRISB = 0
A = 255
WHILE A > 0
PORTB = A
A = A- 1
WAITMS 100
WEND
PORTB = A
TRISB = 0
71
loop:IF PORTA.O THEN
PORTB.O = 1
ELSE
PORTB.O = 0
ENDIF
GOTO loop
DIM A AS WORD
TRISB = 0
FORA = 0TO 10000 STEP 10
PORTB = A.LB
NEXT A
DIM A AS BYTE
DIM BAS BYTE
DIM X AS BYTE
B = 255
X = 2
TRISB = 0
FOR A = B TO 0 STEP -X
PORTB = A
NEXT A
After IF-THEN statement in the same line can be placed almost every other possible statement andthen ENDIF is not used. There are no limits for the number of nested statements of any kind.
LOOKUP function can be used to select one from the list of Byte constants, based on the value in theindex Byte variable, that issupplied as the last separated argument ofthe function. The first constant inthe list has index value 0. The selected constant will be loaded into the result Byte data type variable. Ifthevalue in the index variable goes beyond the number of constants in the list, the result variable willnot beaffected by thefunction. Here isone small example for a 7-segment LED display:DIM DIGIT AS BYTE
DIM MASK AS BYTE
loop:TRISB = %00000000
FOR DIGIT = 0 TO 9
MASK = LOOKUP(0x3F, 0x06, 0x5B, 0x4F, 0x66,0x6D, 0x7D, 0x07,0x7F, 0x6F), DIGIT
PORTB = MASK
WAITMS 1000
NEXT DIGIT
GOTO loop
SHIFTLEFT and SHIFTRIGHT functions can be usedto shift bit-level representation of a variable leftand right. The first argument is input variable and the second argument is number of shifts to beperformed.Here are two examples:TRISB = 0x00
PORTB = %00000011
goleft:WAITMS 250
PORTB = SHIFTLEFT(PORTB, 1)IF PORTB = %11000000 THEN GOTO gorightGOTO goleftgoright:WAITMS 250
PORTB = SHIFTRIGHT(PORTB, 1)IF PORTB = %00000011 THEN GOTO goleftGOTO goright
72
TRISB = 0x00
PORTB = %00000001
goleft:WAITMS 250
PORTB - SHIFTLEFT(PORTB, 1)IF PORTB.7 THEN gorightGOTO goleftgoright:WAITMS 250
PORTB = SHIFTRIGHT(PORTB, 1)IF PORTB.O THEN goleftGOTO goright
ADCIN statement is available as a support for internal A/D converter. Its first argument is ADCchannel number and the second argument is a variable that will be used to store the result od A/Dconversion. ADCIN statement uses two parameters ADC_CLOCK and ADC_SAMPLEUS that havedefault values 3 and 20. These default values can be changed using DEFINE directive. ADC_CLOCKparameter determines the choice for ADC clock source (allowed range is 0-3 or 0-7 depending on thedevice used). ADC_SAMPLEUS parameter sets the desired ADC acquisition time in microseconds (0-255). ADCIN statement presupposes that the corresponding pin is configured as an analog input(TR1S, ADCON1 register and on some devices ANSEL register). Here is one example:DIM V(5) AS BYTEDIM VM AS WORD
DIM I AS BYTE
DEFINE ADCpLOCK = 3DEFINE ADC_SAMPLEUS = 50TRISA = OxFF
TRISB = 0
ADCON1= 0
FOR I - 0 TO 4
ADCIN 0, V(I)NEXT1
VM = 0
FOR I = 0 TO 4
VM = VM + V(I)NEXT I
VM = VM/5
PORTB = VM.LB
Structured programs can be written using subroutine calls with GOSUB statement that uses line labelname as argument. Return from a subroutine is performed by RETURN statement. User need to takecare that the program structure is consistent. When using subroutines, main routine need to be endedwith END statement. END statement is compiled as an infinite loop. Here is an example:SYMBOL adjiction - ADCON0.GO_DONESYMBOL display = PORTBTRISB = %00000000
TRISA = %111111
ADCON0 = OxCO
ADCON1= 0
HIGH ADCON0.ADON
main:
GOSUB getadresuitdisplay = ADRESHGOTO main
END
getadresuit:HIGH ad_actionWHILE ad_actionWEND
RETURN
73
Interrupt routine should be placed as all other subroutines after the END statement. It should beginwith ON INTERRUPT and end with RESUME statement. If arithmetic operations, arrays or any othercomplex statements are used in interrupt routine, then SAVE SYSTEM statement should be placedright after ON INTERRUPT statement to save the content of registers used by system. ENABLE andDISABLE statements can be used in main program to control GIE bit in INTCON register. RESUMEstatement will set the GIE bit and enable new interrupts. For example:DIM A AS BYTE
A = 255
TRISA = 0
PORTA = A
INTCON.INTE=l
ENABLE
END
ON INTERRUPT
A = A-1
PORTA - A
INTCON.INTF = 0
RESUME
DIM T AS WORD
T = 0
TRISA = 0xFF
ADCON1=0
TRISB = 0
OPTION_REG.T0CS = 0INTCON.T0IE = 1
ENABLE
loop:ADCIN 0, PORTB
GOTO loopEND
ON INTERRUPT
SAVE SYSTEM
T = T+ 1
INTCON.T0IF = 0
RESUME
Basic compiler also features the support for LCD modules. Prior to using LCD related statements, usershould set up LCD interface usingDEFINE directives. Here is the list of available parameters:LCD_BITS - defines the number of data interface lines(allowed valuesare 4 and 8; default is 4)LCD_DREG- defines the port where data lines are connected to(default is PORTB)LCD_DBIT - defines the position of data linesfor 4-bit interface (0 or 4;default is 4), ignored for 8-bit interfaceLCD_RSREG - defines the portwhereRS line is connected to (defaultis PORTB)LCD_RSBIT - defines the pin whereRS line is connected to (default is3)LCD_EREG - defines the portwhereE line is connected to (default isPORTB)LCD_EBIT - defines the pin where E Sine is connected to (default is 2)LCD_RWREG - defines the port where R/W line is connected to (set to0 if not used; 0 is default)LCD_RWBIT - defines the pin where R/W line is connected to (set to 0if not used; 0 is default)LCD_COMMANDUS - defines the delay after LCDCMDOUTstatement(default value is 5000)LCD_DATAUS - defines the delayafter LCDOUT statement (defaultvalue is 50)LCD INITMS - defines the delay for LCDINIT statement (default value
74
is 100)Thelastthree parameters should beset to low values when using integrated LCD module simulator.
LCDINIT statement should be placed in the program before any of LCDOUT (used for sending data)and LCDCMDOUT (usedfor sending commands) statements. Its argument is usedto define the cursortype: 0 = no cursor (default), 1= blink, 2 = underline, 3 = blink + underline.LCDOUT and LCDCMDOUT statements may have multiple arguments separated by ','. Strings,constants and variables can be used as arguments of LCDOUT statement. If '#' sign is used before thename of a variable then its decimal representation is sent to the LCD module. Constants and variablescan be used as arguments of LCDCMDOUT statement and the following keywords are alsoavailable:LcdClear, LcdHome, LcdLine2Home, LcdLeft, LcdRight, LcdShiftLeft, LcdShifiRight,LcdLinelCIear, LcdLine2Clear, LcdLinelPos() and LcdLine2Pos(). Argument of LcdLinelPos() andLcdLine2Pos() statements can be a number in the range (1-40) or Byte data type variable. The valuecontained in that variable should be in the same range. Here are some examples:DEFINE LCD_BITS - 8DEFINE LCDJDREG = PORTBDEFINE LCD_DBIT=0DEFINE LCD_RSREG = PORTDDEFINE LCDJISBIT = 1DEFINE LCD_EREG = PORTDDEFINE LCD_EBIT = 3DEFINE LCD_RWREG = PORTDDEFINE LCD_RWBIT = 2DEFINE LCD_COMMANDUS = 10000DEFINE LCD_DATAUS = 100DEFINE LCDJNITMS = 1000LCDINIT
loop:LCDOUT "Hello world!"
WAITMS 1000
LCDCMDOUT LcdClear
WAITMS 1000
GOTO loop
DEFINE LCD_BITS = 8DEFINE LCD_DREG = PORTBDEFINE LCD_DBIT = 0DEFINE LCD_RSREG = PORTDDEFINE LCD_RSBIT = 1DEFINE LCD^EREG = PORTDDEFINE LCDJEBIT = 3DEFINE LCD_RWREG = PORTDDEFINE LCD_RWBIT = 2DEFINE LCD^COMMANDUS = 10000DEFINE LCD_DATAUS = 100DEFINE LCDJNITMS = 1000DIM A AS WORD
A = 65535
LCDINIT 3
WAITMS 1000
loop:LCDOUT "I am counting!"LCDCMDOUT LcdLine2Home
LCDOUT #A
A = A- 1
WAITMS 250
LCDCMDOUT LcdClear
GOTO loop
75
LCD related statements will take control over TRIS registers connected with pins used for LCDinterface, but if you use PORTA or PORTE pins on devices with A/D Converter Module then youshould take control over ADCONI register to set used pins as digital I/O.
You can setup up to eight user defined charcters to be used on LCD. This can easily be done withLCDDEFCHAR statement. The first argument of this statement is char number and must be in therange 0-7. Next 8 arguments form 8-line char pattern (from the top to the bottom) and must be in therange 0-31 (5-bits wide). These 8 user characters are assigned to char codes 0-7 and 8-15 and can bedisplayed using LCDOUT statement. After LCDDEFCHAR statement the cursor will be in HOMEposition. For example:LCDDEFCHAR 0, 10, 10, 10, 10, 10, 10, 10, 10LCDDEFCHAR 1, %11111, %10101, %10101, %10103, %10101,%10101,%10101,%11111LCDOUT 0, 1, "Hello!", i,0
The support for both hardware and software serial communication is also available. HSEROPEN,HSEROUT, HSERIN and HSERGET statements can be used with PIC devices that have internalhardware UART. HSEROPEN statement sets up the hardware UART. Its only argument is baud rateand allowed values are: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400 and57600. If the argument is omitted UART will be set up for 9600 baud rate. If parameterALLOW_MULTIPLEJTSEROPEN is set to 1 using DEFINE directive, it will be possible to useHSEROPEN statement more thanonce in the program, for example to change selected baudrate. IfALLOW_ALL_BAUDRATES parameter is setto 1 using DEFINE directive all baud rates intherange100-57600 will be allowed. HSEROUT statement is used for serial transmission. HSEROUTstatement may have multiple arguments separated by ','. You can use strings, LF keyword for LineFeed character or CRLF keyword for Carriage Return - Line Feed sequence, constants and variables. If'#' sign is used before the name of a variable then its decimal representation is sent to the serial port.HSERIN statement can be usedto loada list of Byteand Word variables with the values received onserial port. This statement will wait until the required number of bytes is received on serial port.HSERGET statement have one argument that must be a Byte variable. If there is a charcter waiting inthe receive buffer it will be loaded in the variable, otherwise 0 value will be loaded. Here are someexamples:DIM I AS BYTE
HSEROPEN 38400
WAITMS 1000
FOR I = 20 TOO STEP-1
HSEROUT "Number: ", #1, CrLfWAITMS 500
NEXT I
DIM I AS BYTE
HSEROPEN 19200
loop:HSERIN I
HSEROUT "Number: ", #1, CrLfGOTO loop
DIM I AS BYTE
HSEROPEN 19200
loop:HSERGETI
IF I > 0 THEN
HSEROUT "Number:", #1, CrLfWAITMS 50
ENDIF
GOTO loop
76
On all supported PIC devices you can use software serial communication routines with SEROUT andSERIN statements. The first argument of both statements must be one of the microcontroller's pins,and the second argument is baud rate: 300, 600, 1200, 2400, 4800 or 9600. For SEROUT statementthen follows the list of arguments to be sent to serial port. You can use strings, LF keyword for LineFeed character or CRLF keyword for Carriage Return - Line Feed sequence, constants and variables. If'#' sign is used before the name of a variable then its decimal representation is sent to the serial port.SEROUT statement uses SEROUT_DELAYUS parameter that can be set by DEFINE directive andhas default value of 1000 microseconds. This defines the delay interval before a character is actuallysent to the port and it is used to increase the reliability of software SEROUT routine. For SERINstatement then follows the list of Byte and Word variables to be loaded with the values received onserial port. This statement will wait until the required number of bytes is received on serial port. Forserial interface with inverted logic levels there are SERININV and SEROUTINV statements available.Some examples:DEFINE SEROUT_DELAYUS = 5000SEROUT PORTC.6, 1200, "Hello world!", CrLf
DIM I AS BYTE
loop:SERIN PORTC.7, 9600,1SEROUT PORTC.6, 9600, "Number:", #1, CrLf
GOTO loop
I2C communication can be implemented in basic programs using I2CWRITE and I2CREADstatements. The first argument of both statements must be one of the microcontroller's pins that isconnected to the SDA line of the external I2C device. The second argument of both statements must beone of the microcontroller's pins that is connected to the SCL line. The third argument of bothstatements must be a constant value or Byte variable called 'slave address'. Its format is described inthe datasheet of the used device. For example, for EEPROMs from 24C family (with device addressinputs connected to ground) the value OxAO should be used for slave address parameter. Bothstatements will take control over bit 0 of slave address during communication. The forth argument ofboth statements must be a Byte or Word variable (this depends on the device used) that contains theaddress of the location that will be accessed. If a constant value is used for address parameter it mustbe in Byte value range. The last (fifth) argument of I2CWRITE statement is a Byte constant or variablethat will be written to the specified address, and for I2CREAD statement it must be a Byte variable tostore the value that will be read from the specified address. It is allowed to use more than one 'data'argument. For I2C devices that do not support data address argument there is short form of I2Cstatements (I2CWRITE1 and I2CREAD1) available where slave address argument is followed withone or more data arguments directly. For some I2C slave devices it is necessary to make a delay tomake sure device is ready to respond to I2CREAD statement. For that purpose there isI2CREAD_DELAYUS parameter that can be set by DEFINE directive and has default value of 0microseconds. Here is one combined example with LCD module and 24C64 EEPROM (SDAconnected to RC2; SCL connected to RC3):DEFINE LCD__BITS = 8DEFINE LCD_DREG = PORTBDEFINE LCD_DBIT = 0DEFINE LCDJRSREG = PORTDDEFINE LCDJISBIT = 1DEFINE LCD_EREG = PORTDDEFINE LCD_EBIT = 3DEFINE LCD_RWREG = PORTDDEFINE LCD_RWBIT = 2DEFINE LCD_COMMANDUS = 10000DEFINE LCD_DATAUS = 100DEFINE LCDJNITMS = 1000DIM ADDR AS WORD
DIM DATA AS BYTE
SYMBOL SDA = PORTC.2
SYMBOLSCL=PORTC3
LCDINIT 3
WAITMS 1000
FOR ADDR = 0 TO 31
77
LCDCMDOUT LcdClear
DATA = 255-ADDR
I2CWRITE SDA, SCL, OxAO, ADDR, DATALCDOUT "Write To EEPROM"
LCDCMDOUT LcdLine2Home
LCDOUT "(", #ADDR, ") = ", #DATAWAITMS 1000
NEXT ADDR
FOR ADDR = 0 TO 31
LCDCMDOUT LcdClear
I2CREAD SDA, SCL, OxAO, ADDR, DATALCDOUT "Read From EEPROM"
LCDCMDOUT LcdLine2Home
LCDOUT "(", #ADDR,") = ", #DATAWAITMS 1000
NEXT ADDR
There is a set of low-level I2C communication statements available, if the user needs to get morecontrol over I2C communication process. I2CPREPARE statement has two arguments that must be oneof the microcontroller's pins. The first argument defines SDA line and second argument defines SCLline. This statement will prepare these lines for I2C communication. I2CSTART statement willgenerate start condition, and I2CSTOP statement will generate stop condition. One byte can be sent tothe I2C slave using I2CSEND statement. After the statement is executed C bit in STATUS register willhold the copy of the state on the SDA line during the acknowledge cycle. There are two statements thatcan be used to receive one byte from I2C slave. I2CRECA or I2CRECEIVEACK will generateacknowledge signal during acknowlegde cycle after the byte is received. I2CRECN orI2CRECEIVENACK will generate not acknowledge signal during acknowlegde cycle after the byte isreceived. One example:DIM ADDR AS WORD
DIMDATA(31)ASBYTESYMBOL SDA = PORTC.4
SYMBOL SCL = PORTC.3
ADDR = 0
I2CPREPARE SDA, SCLI2CSTART
I2CSEND OxAO
I2CSEND ADDR.HB
I2CSEND ADDR.LB
I2CSTOP
I2CSTART
I2CSEND0xAl
FOR ADDR = 0 TO 30
I2CRECEIVEACK DATA(ADDR)NEXT ADDR
I2CRECNDATA(31)I2CSTOP
It is possible to use comments in basic source programs. The comments must begin with single quotesymbol (') and may be placed anywhere in the program.
Lines of assembler source code may be placed anywhere in basic source program and must begin withASM: prefix. For example:ASM: NOP
ASM:LABEL1: MOVLW OxFF
Symbolic names of declared variables can be used in assembler routines because proper variableaddress will be assigned to those names by EQU directive:DIM VARNAME AS BYTE
ASM: MOVLW OxFF
ASM: MOVWF VARNAME
78