You are on page 1of 99

DESIGN OF AN INTELLIGENT ELECTRIC VEHICLE FOR BLIND

ABSTRACT:
As the technology increases we can solve many problems of the people.
There are lots of persons who cannot walk very easily due to blindness. For them
travelling with safety is a major problem. An intelligent electric vehicle is thus
required to solve their problem. The vehicle is made with a lot of technologies such
as Digital image processing for obstacle detection, edge detection and road
detection, Sonar, Infrared and Lidar based Obstacle avoidance, GPS and Map
based location guidance for vehicle, GSM based emergency servicing and semi
automatic control system for vehicle. We propose a design of completely
intelligent electric vehicle for blind which can be implemented successfully. The
vehicle is designed in such a way that it can climb footpaths. The vehicle is
designed to obey all traffic signals so that the design is apt for real world.

CHAPTER-1
INTRODUCTION:
In system the vehicle is designed with voice control along with automated
obstacle avoidance. Using voice commands the vehicle is navigated. The
microcontroller connected with the voice module kit recognizes the voice
command and controls the vehicle movement automatically. Also the vehicle is
attached with a web camera and a PC which is used to take images continuously
and if it encounters a traffic signal it analyses the signal and informs the
microcontroller about the traffic signal which in turn controls the vehicle
accordingly. Along with this the obstacle detecting system is established with
ultrasonic sensors.

CHAPTER-2
REQUIREMENTS
GENERAL
The requirements are to make the project using the some hardwares and the
softwares. That all are listed below.
HARDWARE REQUIREMENT:

PIC Microcontroller
Ultrasonic sensor
Max232 & LCD
Relay
Robo model

SOFTWARE REQUIREMENT:
MPLAB COMPILER
EMBEDDED C

Block diagram:

Power
Supply

Traffic Light with


switch and battery

LCD Display

Recognition
Authenticati
on
Processing

Web
Camera

CIRCUIT DIAGRAM:

MAX
232
PIC16F877A
Microcontroller

Ultrasonic
Sensor
Driver
Circuit

Wheel
Chair

12v

RL3
12V

D3
DIODE

Q2

R3
B1

BC547

1k
12v

5V

U2
13
14

C3
0.1uF

2
3
4
5
6
7

U1

C1+

C1-

RXD FROM PC

11
12
10
9

T1IN
R1OUT
T2IN
R2OUT

T1OUT
R1IN
T2OUT
R2IN

TXD to PC

VS+
VSC2+
4

14
13
7
8
2
6

8
9
10

C1
0.1uF

OSC1/CLKIN
OSC2/CLKOUT

RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD

RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS/C2OUT
RC0/T1OSO/T1CKI
RE0/AN5/RD
RC1/T1OSI/CCP2
RE1/AN6/WR
RC2/CCP1
RE2/AN7/CS
RC3/SCK/SCL
RC4/SDI/SDA
MCLR/Vpp/THV
RC5/SDO
RC6/TX/CK
RC7/RX/DT

C2-

C2

RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7

MAX232

0.1uF

33
34
35
36
37
38
39
40

RL1
12V

D4
DIODE

1
2
3
4
5
6

19
20
21
22
27
28
29
30

7
8
9
10
11
12
13
14

Q4

R4

LCD1

15
16
17
18
23
24
25
26

BC547

1k
VSS
VDD
VEE

12v

RL4

RS
RW
E

12V

D2
DIODE

D0
D1
D2
D3
D4
D5
D6
D7

Q3

R2
1k

BC547
12v

PIC16F877A
LM016L

RL2

D1

12V

DIODE

RV1
5.0K DESC="TRIMPOT 5.0K OHM 6MM SQ SMD"

R1

Q1
BC547

1k

CHAPTER-3

INTRODUCTION OF PIC16F877A:
The PIC16F877A CMOS FLASH-based 8-bit microcontroller is upward compatible with
the PIC16C5x, PIC12Cxxx and PIC16C7x devices. It features 200 ns instruction execution, 256
bytes of EEPROM data memory, self programming, an ICD, 2 Comparators, 8 channels of 10-bit
Analog-to-Digital (A/D) converter, 2 capture/compare/PWM functions, a synchronous serial port
that can be configured as either 3-wire SPI or 2-wire I2C bus, a USART, and a Parallel Slave
Port.

Microchip PIC16F877A Microcontroller Features:


High-Performance RISC CPU

Operating speed: 20 MHz, 200 ns instruction cycle

Operating voltage: 4.0-5.5V

Industrial temperature range (-40 to +85C)

15 Interrupt Sources

35 single-word instructions

All single-cycle instructions except for program branches (two-cycle)

Special Microcontroller Features

Flash Memory: 14.3 Kbytes (8192 words)

Data SRAM: 368 bytes

Data EEPROM: 256 bytes

Self-reprogrammable under software control

In-Circuit Serial Programming via two pins (5V)

Watchdog Timer with on-chip RC oscillator

Programmable code protection

Power-saving Sleep mode

Selectable oscillator options

In-Circuit Debug via two pins

Peripheral Features

33 I/O pins; 5 I/O ports

Timer0: 8-bit timer/counter with 8-bit prescaler

Timer1: 16-bit timer/counter with prescaler


o Can be incremented during Sleep via external crystal/clock

Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler

Two Capture, Compare, PWM modules


o 16-bit Capture input; max resolution 12.5 ns
o 16-bit Compare; max resolution 200 ns
o 10-bit PWM

Synchronous Serial Port with two modes:


o SPI Master
o I2C Master and Slave

USART/SCI with 9-bit address detection

Parallel Slave Port (PSP)


o 8 bits wide with external RD, WR and CS controls

Brown-out detection circuitry for Brown-Out Reset

Analog Features

10-bit, 8-channel A/D Converter

Brown-Out Reset

Analog Comparator module


o 2 analog comparators
o Programmable on-chip voltage reference module
o Programmable input multiplexing from device inputs and internal VREF
o Comparator outputs are externally accessible

Pin diagram:

Memory of the PIC16F877 divided into 3 types of memories:

Program Memory - A memory that contains the program(which we had written), after
we've burned it. As a reminder, Program Counter executes commands stored in the
program memory, one after the other.

Data Memory This is RAM memory type, which contains a special registers like SFR
(Special Faction Register) and GPR (General Purpose Register). The variables that we
store in the Data Memory during the program are deleted after we turn of the micro.
These two memories have separated data buses, which makes the access to each one of
them very easy.

Data EEPROM (Electrically Erasable Programmable Read-Only Memory) - A


memory that allows storing the variables as a result of burning the written program.

Each one of them has a different role. Program Memory and Data Memory two memories that
are needed to build a program, and Data EEPROM is used to save data after the microcontroller
is turn off. Program Memory and Data EEPROM they are non-volatile memories, which store
the information even after the power is turn off. These memories called Flash Or EEPROM. In
contrast, Data Memory does not save the information because it needs power in order to maintain
the information stored in the chip.

PIC16F87XA Program Memory


The PIC16F87XA devices have a 13-bit program counter capable of addressing an 8K
word x 14 bit program memory space. This memory is used to store the program after we burn it
to the microcontroller. The PIC16F876A/877A devices have 8K words x 14 bits of Flash
program memory that can be electrically erased and reprogrammed. Each time we burn program
into

the

micro,

we

erase

an

old

program

and

write

new

one.

PIC16F876A/877A program memory map and stack


Program Counter (PC) keeps track of the program execution by holding the address of the
current instruction. It is automatically incremented to the next instruction during the current
instruction execution.
The PIC16F87XA family has an 8-level deep x 13-bit wide hardware stack. The stack
space is not part of either program or data space and the stack pointer is not readable or writable.
In the PIC microcontrollers, this is a special block of RAM memory used only for this purpose.
The CALL instruction is used to jump to a subroutine, which must be terminated with the
RETURN instruction. CALL has the address of the first instruction in the subroutine as its
operand. When the CALL instruction is executed, the destination address is copied to the PC.
The PC is PUSHed onto the stack when a CALL instruction is executed, or an interrupt causes a
branch. The stack is POPed in the event of a RETURN, RETLW or a RETFIE instruction
execution.

The stack operates as a circular buffer. This means that after the stack has been PUSHed
eight times, the ninth push overwrites the value that was stored from the first push. The tenth
push overwrites the second push (and so on).
Each time the main program execution starts at address 0000 - Reset Vector. The address
0004 is reserved for the interrupt service routine (ISR).
If we plan to use an interrupt, our program will begin after the Interrupt Vector; and if not
we can start to write from the beginning of the Reset Vector.
Some of the memory is divided into the pages that are designed for write/burn the
program into them; the remaining memory (Stack, Interrupt Vector, and Reset Vector) is
hardware registers.
Attention!

Program Memory is divided into the pages, where the program is stored. Data Memory is
divided into the banks. The banks are located inside the RAM, where the special registers and the
data located.

PIC16F87XA Data Memory Organization


The data memory is partitioned into multiple banks which contain the General Purpose
Registers and the Special Function Registers. Number of banks may vary depending on the
microcontroller; for example, micro PIC16F84 has only two banks.
Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are reserved
for the Special Function Registers. Above the Special Function Registers are General Purpose
Registers, implemented as static RAM. While program is being executed, it is working with the
particular bank. The default bank is BANK0.

To access a register that is located in another bank, one should access it inside the
program. There are special registers which can be accessed from any bank, such as STATUS
register.

PIC16F876A/877A register file map


In order to start programming and build automated system, there is no need to study all the
registers of the memory map, but only a few most important ones:

STATUS register changes/moves from/between the banks

PORT registers assigns logic values (0/1) to the ports

TRIS registers - data direction register (input/output)

You can learn about other registers at a later stage or as needed.


STATUS register

In most cases, this register is used to switch between the banks (Register Bank Select), but also
has other capabilities.

PIC STATUS register


With the help of three left bits (IRP, RP1, and RP0) one can control the transition between the
banks:

IRP - Register Bank Select bit, used for indirect addressing method.

RP1:RP0: - Register Bank Select bits, used for direct addressing method.

To distinguish between the two methods, at this point, the will use the definition of fundamental
concepts. Later on, the two methods will be studied in detail. When the IRP Equal to 0, the
program will work with banks 0,1. When the IRP Equal to 1, the program will work with banks
2,3.
The following table demonstrates, which of the Banks the program is working with, based on the
selection of the RP0 and RP1 bits:
RP1:RP0

BANK

00

01

10

11

An example of using STATUS register and Register Bank Select bit:

1. bsf STATUS, 5 ; Change to Bank 1


2. clrf TRISB ; Set PORTB as output
3. bcf STATUS, 5 ; Change to Bank 0

In the first line, we are in changing/setting the 5th bit, RP0, in the STATUS register to 1, and
thus, base on the table we are switching/selecting Bank 1. After PortB was set as output in the
second line, we switched back to Bank 0 by in changing/setting the 5th bit, RP0, in the STATUS
register to 0, in the third line.
C: Carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
An example of using STATUS register and Carry/borrow bit:
1. Movlw 200
2. Addwf 100, 0

In this example, we are assigning value of 200 to the W (working) register. Then, we are
adding the value of 100 and the W register together. The result is stored in W register and should
be

300

(200+100).

However, the maximum value is 256, resulting in carry out. The C (bit 0) of the STATUS register
becomes 1 (C = 1). Register W will contain the reminder: 44.
DC: Digit carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions) (for borrow,
the polarity is reversed)
1 = A carry-out from the 4th low order bit of the result occurred
0 = No carry-out from the 4th low order bit of the result
Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero

The bits 3 and 4 are used with WDT - Watchdog Timer.


PD: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
TO: Time-out bit
1 = After power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out occurred
PORT register

The role of the PORT register is to receive the information from an external source (e.g.
sensor) or to send information to the external elements (e.g. LCD). The 28-pin devices have 3
I/O ports, while the 40/44-pin devices, like PIC16F877, have 5 I/O ports located in the BANK 0.
1. PORTA is a 6-bit wide, bidirectional port. The corresponding data direction
register

is

TRISA.

Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input.
Clearing a TRISA bit (= 0) will make the corresponding PORTA pin an output.
2. PORTB is an 8-bit wide, bidirectional port. The corresponding data direction
register

is

TRISB.

Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input.
Clearing a TRISB bit (= 0) will make the corresponding PORTB pin an output.
3. PORTC is an 8-bit wide, bidirectional port. The corresponding data direction
register

is

TRISC.

Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input.
Clearing a TRISC bit (= 0) will make the corresponding PORTC pin an output.
4. PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is
individually configurable as an input or output.

5. PORTE has three pins (RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7) which are
individually configurable as inputs or outputs. These pins have Schmitt
Trigger input buffers.

Pin diagram of PIC16F877A


We can control each port by using an assigned address of specific port, but there is much easier
way to control the port. We are allowed to use the names of the ports without considering their
addresses.
For example:
# define SWITCH PORTA, 0
We define a variable named SWITCH, which received a value of bit number 0 of the PORTA.
Usually we define the ports at the beginning of the program, and then we use only the given
names.

TRIS register

The TRIS register is data direction register which defines if the specific bit or whole port
will be an input or an output. Each PORT has its own TRIS register. Here's a map of the
locations:
BANK0

BANK1

PORTA

TRISA

PORTB

TRISB

PORTC

TRISC

PORTD

TRISD

PORTE

TRISE

The default mode of each TRIS is input. If you want to set a specific port as exit you
must change the state of the TRIS to 0.
Keep in mind: to change a specific port to an output, one should first move to the
BANK1, make the change, and then return to BANK0. The default state of the banks is BANK0.
The running program is working only with one bank at all time. If not set otherwise, then
as stated, the default bank is BANK0. Part of the registers located inside BANK0, and some are
not. When we need to access a register that is not located inside BANK0, we are required to
switch between the banks.
For example, the access to PORT registers is done inside BANK0. However, to change
port from an input to an output and vice versa, we need to access TRIS register that is located
inside BANK1. From the moment we moved to the BANK1, the program will always work with
BANK1; at this time, to access registers inside BANK0, we will have to return to the situation in
which our program will work with BANK0.

Direct and Indirect addressing

Direct Addressing: Using this method we are accessing the registers directly by
detecting location inside Data Memory from Opcode and by selecting the bank using bits RP1
and RP0 of the STATUS register.
Indirect Addressing: To implement indirect addressing, a File Select Register (FSR) and
indirect register (INDF) are used. In addition, when using this method we choose bank using bit
IRP of the STATUS register. Indirect addressing treated like a stack pointer, allowing much more
efficient work with a number of variables. INDF register is not an actual register (it is a virtual
register that is not found in any bank).
Dont be confused! There is SFR (Special Function Register) - special registers of RAM,
and there is FSR (File Select Register).
The following figure shows the two addressing methods:

Pin diagram of PIC16F877A


To the left you can see the direct addressing method, where the bank selection is made by
RP bits and the referencing is made directly from memory Opcode by using the variable name.

To the right you can see the indirect addressing method, where the bank selection is made
by IRP bit and accessing the variable by pointer FSR.

Lets explore the differences between the 2 methods:


We want to assign number 5 to the variable TEMP located at address 0X030. In the first
row of each example, we will define the variable TEMP at the address 0X030.
Example of direct addressing:
1. TEMP Equ 0x030
2. Movlw 5
3. Movwf TEMP

It's easy to understand, that direct addressing method means working directly with the
variables. In the second line we put the number 5 into the working register W, and in the line 3,
the content of the W passes to the TEMP variable.

Example of indirect addressing:


1. TEMP Equ 0x030
2. Movlw 0x030
3. Movwf FSR
4. Movlw 5
5. Movwf INDF

In the second line, we put a value into the W register. In the third line, the value passes to the
FSR register, and from this moment FSR points to the address of the TEMP variable. In the
fourth line, the number 5 passes to the W register, and in the fifth line, we move the contents of
W register (which is 5) to the INDF. In fact INDF performs the following: it takes the number 5
and puts it in the address indicated by FSR register.

PIC16F87XA Data EEPROM


The data EEPROM and Flash program memory is readable and writable during normal
operation (over the full VDD range). This memory is not directly mapped in the register file
space. Instead, it is indirectly addressed through the Special Function Registers.
There are six SFRs used to read and write to this memory:
1. EECON1
2. EECON2
3. EEDATA
4. EEDATH
5. EEADR
6. EEADRH

When interfacing to the data memory block, EEDATA holds the 8-bit data for read/write and
EEADR holds the address of the EEPROM location being accessed. These devices have 128 or
256 bytes of data EEPROM (depending on the device), with an address range from 00h to FFh.
On devices with 128 bytes, addresses from 80h to FFh are unimplemented.
A few important points about Data EEPROM memory:

It lets you save data DURING programming

The data is saved during the burning process

You can read the data memory during the programming and use it

The use is made possible with the help of SFR

At this point there is no need to learn how to use this memory with special registers, because
there are functions (writing and reading) that are ready.

Write to DATA EEPROM

To write to an EEPROM data location, the user must first write the address to the
EEADR register and the data to the EEDATA register. Then the user must follow a specific write
sequence to initiate the write for each byte.
BSF STATUS, RP1 ;
BSF STATUS, RP0 ; Bank 3
BTFSC EECON1, WR ;Wait for write
GOTO $-1 ;to complete
BCF STATUS, RP0 ;Bank 2
MOVF DATA_EE_ADDR, W ;Data Memory
MOVWF EEADR ;Address to write
MOVF DATA_EE_DATA, W ;Data Memory Value
MOVWF EEDATA ;to write
BSF STATUS, RP0 ;Bank 3
BCF EECON1, EEPGD ;Point to DATA memory
BSF EECON1, WREN ;Enable writes
BCF INTCON, GIE ;Disable INTs.
MOVLW 55h ;
MOVWF EECON2 ;Write 55h
MOVLW AAh ;
MOVWF EECON2 ;Write AAh
BSF EECON1, WR ;Set WR bit to begin write

BSF INTCON, GIE ;Enable INTs


BCF EECON1, WREN ;Disable writes

Read DATA EEPROM


To read a data memory location, the user must write the address to the EEADR register,
clear the EEPGD control bit (EECON1<7>) and then set control bit RD (EECON1<0>). The
data is available in the very next cycle in the EEDATA register; therefore, it can be read in the
next instruction. EEDATA will hold this value until another read or until it is written to by the
user (during a write operation).
BSF STATUS, RP1 ;
BCF STATUS, RP0 ; Bank 2
MOVF DATA_EE_ADDR, W ; Data Memory
MOVWF EEADR ; Address to read
BSF STATUS, RP0 ; Bank 3
BCF EECON1, EEPGD ; Point to Data memory
BSF EECON1, RD ; EE Read
BCF STATUS, RP0 ; Bank 2
MOVF EEDATA, W ; W = EEDATA
Both of these functions are provided by the manufacturer. There is a required sequence in
order to write/read to/from the memory; that process can be performed independently, but it is
better to use ready functions of Microchip.

PIC Timer0:
Many times, we plan and build systems that perform various processes that depend on
time.
Simple example of this process is the digital wristwatch. The role of this electronic
system is to display time in a very precise manner and change the display every second (for
seconds), every minute (for minutes) and so on.

To perform the steps we've listed, the system must use a timer, which needs to be very
accurate in order to take necessary actions. The clock is actually a core of any electronic system.
In this PIC timer module tutorial we will study the existing PIC timer modules. The
microcontroller PIC16F877 has 3 different timers:

PIC Timer0

PIC Timer1

PIC Timer2

We can use these timers for various important purposes. So far we used delay procedure to
implement some delay in the program, that was counting up to a specific value, before the
program could be continued. "Delay procedure" had two disadvantages:

we could not say exactly how long the Delay procedure was in progress

we could not perform any further steps while the program executes the "delay procedure"

Now, using Timers we can build a very precise time delays which will be based on the
system clock and allow us to achieve our desired time delay well-known in advance.
In order for us to know how to work with these timers, we need to learn some things about each
one of them. We will study each one separately.

PIC Timer0
The Timer0 module timer/counter has the following features:

8-bit timer/counter

Readable and writable

8-bit software programmable prescaler

Internal (4 Mhz) or external clock select

Interrupt on overflow from FFh to 00h

Edge select (rising or falling) for external clock

Lets explain the features of PIC Timer0 we have listed above:


Timer0 has a register called TMR0 Register, which is 8 bits of size.
We can write the desired value into the register which will be increment as the program
progresses. Frequency varies depending on the Prescaler. Maximum value that can be assigned to
this register is 255.
TMR0IF - TMR0 Overflow Interrupt Flag bit.
The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h.
This overflow sets bit TMR0IF (INTCON<2>). You can initialize the value of this register to
what ever you want (not necessarily "0"). We can read the value of the register TMR0 and write
into. We can reset its value at any given moment (write) or we can check if there is a certain
numeric value that we need (read).
Prescaler - Frequency divider.

1:2

1:4

1:8

1:16

1:32

1:64

1:128

1:256

The structure of the OPTION_REG register


We perform all the necessary settings with OPTION_REG Register. The size of the register is 8
bits.

Initializing the OPTION_REG register


The following is an example how we can initialize the OPTION_REG:
1. PSA=0; // Prescaler is assigned to the Timer0 module
2. PS0=1; // Prescaler rate bits
3. PS1=1; // are set to 111
4. PS2=1; // which means divide by 256
5. TOSE=0; // rising edge
6. TOCS=0; // Internal instruction cycle clock

Block diagram of the PIC Timer0 / WDT prescaler

PIC TIMER0 block diagram

Calculating Count, Fout, and TMR0 values


If using INTERNAL crystal as clock, the division is performed as follow:

PIC TIMER0 formula for internal clock


Fout Output frequency after the division.
Tout The Cycle Time after the division.
4 - The division of the original clock (4 MHz) by 4, when using internal crystal as clock (and not
external oscillator).
Count - A numeric value to be placed to obtain the desired output frequency - Fout.
(256 - TMR0) - The number of times in the timer will count based on the register TMR0.

An example of INTERNAL crystal as clock


Suppose we want to create a delay of 0.5 second in our program using Timer0. What is the value
of Count?
Calculation:
First, lets assume that the frequency division by the Prescaler will be 1:256. Second, lets set
TMR0=0. Thus:

Formula to calculate Cout using Timer0


If using EXTERNAL clock source (oscillator), the division is performed as follow:

PIC TIMER0 formula for external clock


In this case there is no division by 4 of the original clock. We use the external frequency as it is.
An example of EXTERNAL clock source (oscillator):

What is the output frequency - Fout, when the external oscillator is 100kHz and Count=8?
Calculation:
First, lets assume that the frequency division by the Prescaler will be 1:256. Second, lets set
TMR0=0. Thus:

Formula to calculate Fout for Timer0

PIC Timer1:
The Timer1 module, timer/counter, has the following features:

16-bit timer/counter consisting of two 8-bit registers (TMR1H and TMR1L)

readable and writable

8-bit software programmable prescaler

Internal (4 Mhz) or external clock select

Interrupt on overflow from FFFFh to 0000h

Lets explain the features of PIC Timer1 we have listed above:


Timer1 has a register called TMR1 register, which is 16 bits of size.
Actually, the TMR1 consists of two 8-bits registers:

TMR1H

TMR1L

It increments from 0000h to the maximum value of 0xFFFFh (or 0 b1111 1111 1111 1111 or
65,535 decimal). The TMR1 interrupt, if enabled, is generated on overflow which is latched in
interrupt flag bit, TMR1IF (PIR1<0>). This interrupt can be enabled/disabled by setting/clearing

TMR1 interrupt enable bit, TMR1IE (PIE1<0>). You can initialize the value of this register to
what ever you want (not necessarily "0").
TMR1IF TMR1 overflow Interrupt Flag bit.
This flag marks the end of ONE cycle count. The flag need to be reset in the software if
you want to do another cycle count. We can read the value of the register TMR1 and write into.
We can reset its value at any given moment (write) or we can check if there is a certain numeric
value that we need (read).
Prescaler Frequency divider.
We can use Prescaler for further division of the system clock. The size of the
register is 2-bit only, so you can make four different division. The options are:

1:1

1:2

1:4

1:8

You can choose whether to use an internal system clock (crystal) or external
oscillator that can be connected to a pin RC0.

The structure of the T1CON register


We perform all the necessary settings with T1CON register. As we can see, the size of the
register is 8 bits. Lets explore the relevant bits:

Initializing the T1CON register


The following is an example how we can initialize the T1CON register:
1. TMR1ON=1; // the timer is enable
2. TMR1CS=0; // internal clock source
3. T1CKPS0=0; // Prescaler value set to 00
4. T1CKPS1=0; // which means 1:1 (no division)
Or you can set all the T1CON register at once as follows:
T1CON=0b00000001;

Block diagram of the PIC Timer1

PIC TIMER1 block diagram


Calculating Count, Fout, and Timer1 values

If using INTERNAL crystal as clock, the division is performed as follow:

PIC TIMER1 formula for internal clock

Fout The output frequency after the division.


Tout The Cycle Time after the division.
4 - The division of the original clock (4 MHz) by 4, when using internal crystal as clock (and not
external oscillator).
Count - A numeric value to be placed to obtain the desired output frequency - Fout.
(256 - TMR1) - The number of times in the timer will count based on the register TMR0.
If using EXTERNAL clock source (oscillator), the division is performed as follow:

PIC TIMER1 formula for external clock


Simple example and calculation of how to use TIMER1:

Suppose we want to create a delay of 2 second in the our program using Timer1. What is the
value of Count?
Calculation:
First, lets assume that the frequency division by the Prescaler will be 1:1. Second, lets set
TMR1=0, which means the TMR1 will count 65,536 times. Thus:

Formula to calculate Cout for Timer1

PIC Timer2:

The Timer2 module has the following features:


two 8-bit registers (TMR2 and PR2)
readable and writable
prescaler and a postscaler
connected only to an internal clock - 4 MHz crystal
Interrupt on overflow
Lets explain the features we have listed above:
Timer2 has 2 count registers: TMR2 and PR2. The size of each registers is 8-bit in which we
can write numbers from 0 to 255. The TMR2 register is readable and writable and is cleared on
any device Reset. PR2 is a readable and writable register and initialized to FFh upon Reset.
Register TMR2 is used to store the initial count value (the value from which it begins to
count). Register PR2 is used to store the ending count value (the maximum value we
need/want to reach). ie: using Timer2 we can determine the started count value, the final count
value, and the count will be between these two values. The Timer2 increments from 00h until it
matches PR2 and then resets to 00h on the next increment cycle.
Prescaler and Postscaler - Timer2 is an 8-bit timer with a prescaler and a postscaler. Each
allows

to

make

additional

division

of

the

frequency

clock

source.

Prescaler divides the frequency clock source BEFORE the counting take place at the register
TMR2, thus the counting inside the TMR2 register is performed based on the divided frequency
clock

source

by

the

Prescaler

The match output of TMR2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling
inclusive) to generate a TMR2 interrupt (latched in flag bit, TMR2IF (PIR1<1>)).
Postscaler divides the frequency that comes out of the Comparator again for the last time.
TIMER2 Prescaler and Postscaler

TMR2IF - TMR2 to PR2 Match Interrupt Flag bit.


Comparator Compares the value of the register TMR2 and the maximum value of the register
PR2.
TMR2 The register in which the initial count value is written.
PR2 The register in which the final or the maximum count value is written.
We perform all the necessary settings with T2CON Register The structure of the T2CON
register:

As we can see, the size of the register is 8 bits. Lets explore the relevant bits:
T2CKPS1:T2CKPS0: Timer2 Clock Prescale Select bits
The input clock (FOSC/4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits
T2CKPS1:T2CKPS0 (T2CON<1:0>).

00 = Prescaler is 1
01 = Prescaler is 4
1x = Prescaler is 16

TMR2ON: Timer2 On bit


Timer2 can be shut-off by clearing control bit, TMR2ON (T2CON<2>), to minimize power
consumption.
1 = Timer2 is on
0 = Timer2 is off

TOUTPS3:TOUTPS0: Timer2 Output Postscale Select bits


The match output of TMR2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling
inclusive selected by control bits TOUTPS3:TOUTPS0 (T2CON<6:3>).
0000 = 1:1 postscale
0001 = 1:2 postscale
0010 = 1:3 postscale
1111 = 1:16 postscale

The following is an example how we can initialize the T2CON register:


1. TMR2ON=1; // the timer is enable
2. T2CKPS0=0; // Prescaler 1:1
3. T2CKPS1=0;
4. TOUTPS0=1; // Postscaler 1:16
5. TOUTPS0=1;

6. TOUTPS0=1;
7. TOUTPS0=1;
Or you can set all the T2CON register at once as follows:
T2CON=0b01111100;

TIMER2 BLOCK DIAGRAM

How to calculate the required values of the TIMER2:

Fout The output frequency after the division.


Tout The Cycle Time after the division.
4 - The division of the original clock (4 MHz) by 4, when using internal crystal as clock (and not
external oscillator).
Count - A numeric value to be placed to obtain the desired output frequency - fout.
(PR2 TMR2) - The number of times the counter will count.
Simple example and calculation of how to use TIMER2:
Suppose we want to create a delay of 1 second in the our program using Timer2. What is the
value of Count?
Calculation:
First, lets assume that the frequency division by the Prescaler will be 1:1 and Postscaler will be
1:16. Second, lets set TMR1=0 and PR2=255. Thus:

Introduction to Serial communication with PIC16F877 microcontroller


In this tutorial we will study the communication component USART (Universal
Synchronous Asynchronous Receiver Transmitter) located within the PIC. It is a

universal communication component (Synchronous/Asynchronous), which can be


used as transmitter or as receiver. We will look at:

serial and parallel communications

synchronous and asynchronous communications

how to enable serial communication - TXSTA and RCSTA registers

An example of 8-bit transmission

An example of 9-bit transmission

how to calculate the value being placed in the SPBRG register

USART Transmit and Receive block diagrams

Max323 Driver/Receiver

the implementation of the PIC serial communication (C program and a video)

We will show how to set USART in order to allow communication between PIC to PIC or
between PIC to a personal computer. We will start with the definition of media concepts. There
are two options to differentiate when speaking about transmission of information on the
transmission lines:

serial communication

parallel communication

In order to understand what serial communication is, and emphasize the difference between
serial communication and parallel communication, lets take a look at the following example:
We have a multi-bit word, and we want to transmit it from one computer to the second computer.

Using the serial communication:


When using the serial communication we transmit the multi-bit word bit after bit (when
at any given moment only one bit will pass).

Transmitting the word 10011101 using serial communication.


Using the parallel communication:
When using the parallel communication, however, the number of bits will be transmitted
at once from one computer to the second computer.

Transmitting the word 10011101 using parallel communication.

In addition to the serial and parallel communications, there are 2 types of communication we
will explore:

Synchronous communication

Asynchronous communication

Synchronous communication
When using the synchronous communication the information is transmitted from the
transmitter to the receiver:

in sequence

bit after bit

with fixed baud rate

and the clock frequency is transmitted along with the bits

That means that the transmitter and the receiver are synchronized between them by the same
clock frequency. The clock frequency can be transmitted along with the information, while it is
encoded in the information itself, or in many cases there is an additional wire for the clock.
This type of communication is faster compare to the asynchronous communication since it is
"constantly transmitting the information, with no stops.
Asynchronous communication

When using the asynchronous communication - the transmitter and the receiver refraining
to transmit long sequences of bits because there isn't a full synchronization between the
transmitter, that sends the data, and the receiver, that receives the data.
In this case, the information is divided into frames, in the size of byte. Each one of the frame has:

Start bit marks the beginning of a new frame.

Stop bit marks the end of the frame.

Frames of information must not necessarily be transmitted at equal time space, since they are
independent of the clock.

Enabling Serial Communication


To communicate with external components such as computers or microcontrollers, the PIC
micro uses a component called USART - Universal Synchronous Asynchronous Receiver
Transmitter. This component can be configured as:

a Full-Duplex asynchronous system that can communicate with peripheral devices, such
as CRT terminals and personal computers

a Half-Duplex synchronous system that can communicate with peripheral devices, such
as A/D or D/A integrated circuits, serial EEPROMs, etc.

To enable the serial communication with PIC micro we must set different parameters within two
registers: (click the links for the explanation of each bit)
1. TXSTA - Transmit Status and Control Register

2. RCSTA - Receive Status and Control Register

An example of 8-bit transmission:


Lets assume that we need to transmit the following information: 10110010. This
information will be stored inside TXREG register, which acts as a temporary buffer storage of
information prior to transmission. The bit TX9 will be zero (TX9=0) - which determines that the
transmission will be 8-bit transmission, so there is no need to address TX9D bit, which stores the
ninth bit of information.
The information before the transmission looks like this:

Transmitting 8 bit data


Now, lets define the receiver side to receive 8 bit information. To do so, the register RX9
will be zero (RX9=0). The received information will be stored in the RSR register, which acts as
a temporary buffer storage.
The received information will look like this:

Receiving 8 bit data


An example of 9-bit transmission:

Suppose we want to transmit the following information: 110010110. This information is


in the size of 9-bit, so there is not enough space to store all the information in the TXREG
register . Thus, we will store the low 8-bit in the register TXREG and the MSB in the TX9D bit.
We will set the TX9 = 1 - enabling transmission of 9-bit data. It is important to note, that
first we need to store the 9th bit and only later other 8-bits. This is important because the
information of 8 bits may be transmitted immediately once being inside the TXREG register. As
a result the transmitted information will be incorrect.
The information before the transmission will look like this:

Transmitting 9 bit data


Now, lets define the receiver side to receive 9 bit information. To do so, the register RX9
will be set (RX9=1). The received, lower 8-bit information, will be stored in the RSR register,

which acts as a temporary buffer storage. The higher bit information (MSB) will be stored in
RX9D.
The received information will look like this:

Receiving 9 bit data


Now lets continue the explanation. Each transmission is transmitted in the particular rate
(BAUD). The baud rate is measured in units of bps (bit per second) or kbps (kilo bit per second).
Calculating the value being placed in the SPBRG register

Lets assume we want to transmit using the BAUD rate of 1200bps. This is done by
setting the system clock to the value needed. To do so, we need to write a hexadecimal number
to the SPBRG register. The value written to the SPBRG register set the clock cycle to the value
we want for the BAUD rate.
The size of SPBRG register is 8-bit. As discussed previously, in asynchronous mode, the
baud rate of transmission of the information can be set to high speed or to low speed. The rate
selection, as already seen, is made by the BRGH bit in TXSTA register:

1 = High speed

0 = Low speed

For each baud rate we need to calculate the value being placed in the SPBRG differently:
SPBRG = (Fosc / (16 x Baud rate)) - 1, BRGH = 1 High Speed
SPBRG = (Fosc / (64 x Baud rate)) - 1, BRGH = 0 Low Speed
The following outlines how the value which is placed in the SPBRG register is being
computed, in the case of a high baud rate and low baud rate.
For example:
We want to calculate the hex value that will be placed the register SPBRG, to get the
baud rate of 1.2kbps with low speed. The formula SPBRG = (Fosc / (64 x Baud rate)) - 1 was
chosen since, its describing the calculation needed for transmission in Low Speed:
SPBRG = (4MHz / (64x1200)) -1 = 51.08
Because it is not possible to write a number with a decimal point to the register, we take
only the whole part of the number and place inside the register SPBRG = 51.
The following tables are the BAUD RATES FOR ASYNCHRONOUS MODE BRGH=0 and
BRGH=1.
BRGH=0

BRGH=1

USART transmit block diagram

USART transmit block diagram

The information we want to transmit is loaded into the 8-bit register - TXREG. If you
want to transmit a 9-bit data, the 9th bit is loaded into TX9D. At the same time, the information
above is being loaded into the register TSR, which is used as a temporary buffer before that
information is transmitted.
Of course, using 2 registers allows faster the transmission of the data. Once the TXREG
register transfers the data to the TSR register, the TXREG register is empty and flag bit, TXIF is
set.

As mentioned earlier:

the register SPBRG sets the baud rate in the desired transmission

TXIE allows interrupts when TXREG is empty and TXIF is set

TXEN - Enabling SPBRG

USART receive block diagram

USART receive block diagram


The information is received in the register RSR. If there is a 9-bit transmission, the 9th bit
goes into RX9D. After receiving the data in the register RSR, the information is loaded at the
same time into the register RCREG. Obviously, using 2 registers allows faster receiving of
the data. While the information that was received being transferred into RCREG, the new
information has already been received into the register RSR. Of course, the CREN bit needs
to be set.
According to the USART TRANSMIT / RECEIVE BLOCK DIAGRAM, that the
information that was transmitted via pin RC6 in Port C, is received through the pin RC7 in
Port C

PIC interrupt
In this tutorial we will study about the Polling and especially on the PIC Interrupt. We will look
at:

the different types of PIC interrupts

the existing PIC interrupts

the settings of the required registers to work with PIC interrupts

the implementation of the external PIC interrupts (C program and a video)

Computer systems include microcontroller, which includes timers, serial communication


system, analog digital converter, and much more.
Many times it is also external systems, located outside the micro itself which are
communicating with micro through control lines.
An example of such a system is a digital thermometer, which is measure the temperature
and at the end of the measurements transmitting the results to the PIC micro
How does the processor know to get the required information from the
external system?

This operation can be performed in two ways:

using polling

using interrupts

A) The first method is the simple one - Polling:


Using this method, the microcontroller accesses at the exact time interval the external
device, and gets the required information. The user is the one who determines the time intervals
in which micro contacts the device. In the Polling method, the PIC microcontroller must
"access by himself" the device and ask for the information it needs for processing. In fact we
see that in the Polling method the external devices are not independent systems; they depend on
the microcontroller, and only the micro is entitled to obtain access to the information it needs.
The main Drawback of this method when writing program is waste of time of
microcontroller, which needs to wait and check whether the new information has arrived.
B) The second method is - Interrupt:

Interrupt is the signal sent to the micro to mark the event that requires immediate
attention. Interrupt is requesting" the processor to stop to perform the current program and to
make time to execute a special code. In fact, the method of interrupt defines the option to
transfer the information generated by internal or external systems inside the micro by them self!
Once the system has finished the task imposed on it, the processor will be notified that it can
access and receive the information and use it.
The request for the microcontroller to free itself to execute the interrupt could come from
several sources:

External hardware devices. Common example is pressing on the key on the


keyboard,

which

causes

to

the

keyboard

to

send

interrupt

to

the

microcontroller to read the information of the pressed key.

The processor can send interrupts to itself as a result of executing the


program, to report an error in the code. For example, division by 0 will causes
an interrupt.

In the multi-processor system, the processors can send to each other


interrupts as a way to communicate.

There are two types of PIC interrupts:

Software interrupts - come from a program that runs by the processor and request the
processor to stop running the program, go to make an interrupt and then to return to continue to
execute the program.
An example: Procedure - when there is a procedure call, the processor stops the execution
of the program, jumps to the place in memory that reserved for a procedure executes the
procedure and only then returns back to the program and continues to execute.
Hardware interrupts -these are sent to microcontroller by hardware devices as a third-party;
some of them can be blocked - (masking) by Interrupt Enable bit (IE). When the interrupt is
blocked, the PIC microcontroller does not "see" the request for the interrupt and will not

execute it. In fact the blocked interrupt will not be executed until it will be unblocked.

For example: The processor is in the middle of a calculation, and we do not want to write
into memory until the micro did not finish the calculation. In this situation, we will block the
"write to the memory" interrupt. We will unblock the interrupt only after the processor finished
the calculation, thus preventing him to write into the memory as long as it is in the middle of the
action. There are some interrupts that can not be masked/blocked - NMI - Non Mask able
Interrupts. They are used to report on critical hardware issues, such as the drop of voltage. In this
situation we are interested in immediate response from the processor without the ability to ignore
them.
Lets explore the existing interrupts within the PIC16F877 microcontroller:

The microcontroller has 14 interrupt sources. From the diagram below you can see all the
sources of the interrupts, when xxIF is an interrupt flag and xxIE is an Interrupt Enable bit.
Interrupt flag shows the result of an interrupt and interrupt enable bit is used to enable or to
block the interrupt. The interrupts on the left side of the figure below are low priority and all of
them together can be blocked by enabling bit interrupt PEIE = 0.
We can also determine whether to allow the system shown in figure below to treat or
block all of the interrupts. This is done by using the global interrupt enable bit - GIE. When the
GIE = 1 we are enabling the interrupts, and if the GIE = 0 we are blocking all of the interrupts.

How to set the required registers to work with interrupts?

The settings of the interrupts are done by using 3 interrupt control registers:

INTCON This register contains the status of the high-priority interrupts (see diagram
above) and general definitions.

PIE (PIE1, PIE2) This register contains the interrupt enabling bits of the low-priority
interrupts.

PIR (PIR1, PIR2) This register contains the interrupt flags of the low-priority
interrupts.

Writing a C language program to implement external interrupt

Lets write an example program, where we will explore the way we need to define the
external interrupt connected to PORTB pin RB0. The program will play a sound from a buzzer
that is located on the EduPIC development board, every time there is an external interrupt that is
generated through RB0 pin.
To make our live trouble-free we will not connect any external device to the PORTB0.
Instead, we will create an external interrupt using our program itself, by incrementing the

value

of

PORTB

by

1.

As explained above, when there is a logic change in the pin RB0, from "0" to "1", the external
interrupt flag will be set INTF = 1.
In this section of code, we will increase the value of PORTB by 1 (PORTB + + ). When
we are increasing the value by 1, the last bit (LSB) will vary each cycle of the program from "0"
to "1" and vice versa. Thus, any change in the last bit (which is actually a change to the pin RB0)
from "0" to "1" will cause the INTF flag to be set. The change in the value in the last bit of PortB
is described in the example below:
00000000
a change from 0 to 1
00000001
00000010
a change from 0 to 1
00000011
00000100
a change from 0 to 1
00000101
00000110
a change from 0 to 1
00000111

In order for us to work with the interrupts, we need to learn another function: interrupt
function. This function is a special function. So far functions were called from the main program
or other functions. The interrupt function is called by the hardware itself and operates by
following steps:

After the interrupt function is loaded into the memory, the function waits for a
moment for the interrupt to occur;

When the interrupt has occurred, the operating system stops the execution of
the main function and free itself to perform the interrupt function;

After the execution of the interrupt function, the operating system continues
to run the main function from the place it stopped before the interrupt has
occurred.

PIC Analog to Digital Converter:


The role of the ANALOG-TO-DIGITAL CONVERTER (A/D) is to convert analog
voltage values to digital values. Lets explore the principle of operation of the A/D
converter:

The ANALOG-TO-DIGITAL CONVERTER converts analog voltage to binary numbers.


These binary numbers can be in different length - 2, 4, 8, 10-bit. The more bits the binary
number has, the higher the resolution of the - A/D.
For example: Suppose that the voltage that supplied to the A/D converter varies from 0 to
5 volt, and the A/D converter converts the input voltage to a binary number of two-bits.
With two bits, we can ONLY display 4 different options:
00

01

10

11

That is, we can show the changes from 0 to 5 volt with 4 numbers, or more precisely four levels.
You can see the 4 levels in the following illustration:

BLUE line describes the changes in the input voltage of the ANALOG-TO-DIGITAL
CONVERTER (A/D) of the microcontroller. RED line represents the digital levels at the output
of the ANALOG-TO-DIGITAL CONVERTER (A/D) of the microcontroller.
We can see that the red signal far from being ideal, i.e. not close enough to the original
analog input voltage values. Thus, we can say that A/D with the binary number of two-bits has a
low resolution and there is a large gap between the real value of the analog input voltage and the
values represented by the A/D.
Now, suppose that the voltage that supplied to the A/D converter is still varies from 0 to 5
volt, however, the A/D converter converts the input voltage to a binary number of three-bits.
With three bits we can get 8 different options:
000

001

010

011

100

101

110

111

That is, we can show the changes from 0 to 5 volt with 8 numbers, or more precisely 8 levels.
You can see the eight levels in the following illustration:

Now we can see that the RED line represents the original signal better than the
previous RED line. The gap between the analog signal and the digital signal smaller compared to
the previous graph. Based on the "good" results that we received, we can say that current
A/D converter has a high-resolution compare to previous case.
Therefore we can say that the ANALOG TO DIGITAL CONVERTER (A/D) of the
microcontroller with a larger amount of bits has a higher resolution and better accuracy when
converting from analog signal to digital signal.
There is another fact to mention about the resolution of the A/D converter. Since the
converter converts the signals, it takes a certain time. The conversion time of the low resolution
A/D takes less time than the conversion time of the high resolution A/D.
When you are planning special systems, you have to take into account this fact. If you are
planning to build accurate and fast systems, you have to consider carefully which convert to
choose: if you select an analog to digital converter (A/D) with high resolution system will not
be as fast; but if you select an analog to digital converter (A/D) with high-speed response you
will loose the resolution of the system.

How to convert analog values to digital values:

If we decide to work with an analog to digital converter (A/D) with three-bit length, we
obtain eight different binary numbers which represent different voltage levels. For example:
Voltage levels [V]

Binary representation

0-0.62

000

0.621-1.25

001

1.251-1.87

010

1.871-2.5

011

2.51-3.12

100

3.121-3.75

101

3.751-4.37

110

4.371-5.00

111

In this example, the analog voltage values from 0v to 0.62v have a binary representation
of 000; the analog voltage values from 0.621v to 1.25v have a binary representation of 001 so on.
The Analog to Digital Converter (ADC) module located within the PIC
microcontroller has a resolution of ten-bit length. Therefore, the converter can
divide the analog input voltage between 0v and 5v to 2^ 10 levels, which are 1024
levels. We can say that the resolution of this component is very high.
How do we know what is the binary value/representation of the analog
input voltage?

We can use the triangle method to calculate/find the binary representation of an analog
input voltage. For example, lets calculate/find the binary value representation on the analog input
voltage of 3.65 volt:

The analog input voltage of 3.65v will be represented by decimal number 748 or by
binary number 1011101100.Using similar way we can find a binary representation for any
desired level of the analog input voltage.
The A/D module has four 8 bit registers. These registers are:

ADCON0 - A/D Control Register 0; determines the behavior of the A/D

ADCON1 - A/D Control Register 1; determines the configuration of the PORTA


and PORTE and how the result of conversion of A/D will be store

ADRESH - A/D Result High Register

ADRESL - A/D Result Low Register

The size of this register is one byte (8 bits). Each bit has an important role in the definition of the
component. Here's a breakdown of the bits role:

After we define the appropriate pins in the specific PORT to be analog inputs, we can sample the
analog input voltage using one of the following channels:

You can sample from PORTA each of the pins RA0 and RA5 except pin RA4 (used for other
purposes) as well as of PORTE.
GO/DONE: A/D Conversion Status bit
If ADON = 1:
1 = A/D conversion in progress (setting this bit starts the A/D conversion)
0 = A/D conversion not in progress (this bit is automatically cleared by hardware when the A/D
conversion is complete)
ADON: A/D On bit
1 = A/D converter module is operating
0 = A/D converter module is shut-off and consumes no operating current

The size of this register is one byte (8 bits). Each bit has an important role in the definition of the
component. Here's a breakdown of the bits role:
ADFM: A/D Result Format Select bit
1 = Right justified. 6 Most Significant bits of ADRESH are read as 0.
0 = Left justified. 6 Least Significant bits of ADRESL are read as 0.
As we said, the A/D converter has a resolution of ten bits, i.e., the result of the conversion
can not be stored in one register of eight bits. Therefore, the result is stored in two registers:

ADRESL and ADRESH. The size of each register is 8 bits long, so that we have 16 (2*8) bits all
together. We can store the result of the conversion which is 10 bits long using the two registers
ADRESL and ADRESH in the following 2 ways:

alignment to the left

alignment to the right

Alignment to the left the eight MSB bits are stored in the ADRESH, and the two LSB

bits are stored in ADRESL. In this case, the remaining six bits appear as - "0".
Left Justified
X

ADRESH

ADRESL

Alignment to the right the eight LSB bits are stored in ADRESL, and two MSB bits are

stored in the ADRESH. In this case six highest bits appear as - "0".
Right Justified
0

ADRESH

ADRESL

PCFG3:PCFG0: A/D Port Configuration Control bits:

With these bits we can control the pins of PORTA or PORTE. We can decide an analog (A) or
digital (D) mode.

If we want to work with the PORTA and PORTE as analog ports, then we select the
option PCFG3: PCFG0 = 0000; If we want to work with ports as digital, then we select the
option PCFG3: PCFG0 = 011x.
In general, after the specified desired behavior of the A/D converter unit and before we
start the conversion operation, we have to set up channel through which the analog information
will be received using TRIS command. To begin making the conversion, we have to set the
GO/DONE =1. This is done by using the command ADGO = 1. When the conversion ends, the
result will be loaded into 2 registers ADRESH: ADRESL. Status bit GO/DONE (the register
ADCON0) will be set to zero and the ADIF flag is set.

Analog to Digital BLOCK DIAGRAM

To summarize, the following steps should be followed for doing an A/D Conversion:
1. Configure the A/D module:
o

Configure analog pins/voltage reference and digital I/O (ADCON1)

Select A/D input channel (ADCON0)

Select A/D conversion clock (ADCON0)

Turn on A/D module (ADCON0)

2. Configure A/D interrupt (if desired):


o

Clear ADIF bit

Set ADIE bit

Set PEIE bit

Set GIE bit

3. Wait the required acquisition time.


4. Start conversion:
o

Set GO/DONE bit (ADCON0)

5. Wait for A/D conversion to complete, by either:


o

Polling for the GO/DONE bit to be cleared(with interrupts enabled); OR

Waiting for the A/D interrupt

6. Read A/D result register pair (ADRESH:ADRESL), clear bit ADIF if required.
7. For the next conversion, go to step 1 or step 2, as required.

CHAPTER-5
INTRODUCTION ABOUT SOFTWARE:

When starting a new project, simply select the microcontroller you use from
the Device Database and the Vision IDE sets all compiler, assembler,
linker, and memory options for you.
Numerous example programs are included to help you get started with the
most popular embedded 8051 devices.
The Keil Vision Debugger accurately simulates on-chip peripherals (IC,
CAN, UART, SPI, Interrupts, I/O Ports, A/D Converter, D/A Converter, and
PWM Modules) of your 8051 device. Simulation helps you understand
hardware configurations and avoids time wasted on setup problems.
Additionally, with simulation, you can write and test applications before
target hardware is available.
When you are ready to begin testing your software application with target
hardware, use the MON51, MON390, MONADI, or FlashMON51 Target
Monitors, the ISD51 In-System Debugger, or the ULINK USB-JTAG
Adapter to download and test program code on your target system.

CHAPTER-6
INTRODUCTION TO EMBEDDED SYSTEMS
An Embedded System is a computer system designed to do one or a few
dedicated and/or specific functions often with real-time computing constraints. It is
embedded as part of a complete device often including hardware and mechanical
parts. By contrast, a general-purpose computer, such as a personal computer (PC),
is designed to be flexible and to meet a wide range of end-user needs. Embedded
systems control many devices in common use today.
Since the embedded system is dedicated to specific tasks, design engineers
can optimize it to reduce the size and cost of the product and increase the reliability
and performance. Some embedded systems are mass-produced, benefiting from
economies of scale. It was built from transistor logic and had a hard disk for main
memory. Embedded systems contain processing cores that are being dedicated to
handle a particular task.
Physically, embedded systems range from portable devices such as digital
watches and MP3 players, to large stationary installations like traffic lights, factory
controllers, or the systems controlling nuclear power plants. Complexity varies
from low, with a single microcontroller chip, to very high with multiple units,
peripherals and networks mounted inside a large chassis or enclosure

The characteristics of embedded system are:

In-build intelligence

Immediate control of hardware.

Performs a specific task.

Respond to external events .Embedded systems are not always standalone devices.

Embedded system allowing the system hardware to reduce costs.

Processing power and memory Limitations.

Program is stored in non-volatile memory and it can be executed on power.

High performance

Reliability

Low power consumption

CLASSIFICATION OF EMBEDDED SYSTEM


SMALL SCALE EMBEDDED SYSTEM
Single 8-bit or 16-bit micro controller.
Little hardware and software complexity.
They may even be battery operated.
Usually C is used for developing these system.
The need to limit power dissipation when system is running
continuously.
Programming tools.
Editor, Assembler & Cross Assembler.
MEDIUM SCALE EMBEDDED SYSTEM

Both hardware and software complexity.

Programming tools:
RTOS, Source code Engineering Tool and Integrated Development
Environment (IDE).
Some systems provide user interface remotely with the help of a serial
(e.g RS-232, USB, IC, etc.) or network (e.g. Ethernet) connection.
Single or few 16 or 32 bit micro controllers or digital signal processors (DSP)
risk reduced instruction set computers (RISC).

SOPHISTICATED EMBEDDED SYSTEM


Enormous hardware and software complexity
Which may need scalable processor or configurable processor and
programming logic arrays?
Constrained by the processing speed available in their hardware
units.

Programming tools
For these systems may not be readily available at reasonable cost or
may not be available at all. A compiler or retarget able compiler
might have to be developed for this.
These languages are used in mobile phones, personal digital assistants, media
player, set-top boxes and other consumer electronics devices, networking
equipment, machine control, industrial automation, navigation equipments and
medical instruments.
POWER SUPPLY UNIT
A power supply unit (PSU) converts mains AC to low-voltage regulated DC
power for the internal components of a computer. Modern personal computers
universally use a switched-mode power supply. Some power supplies have a
manual selector for input voltage, while others automatically adapt to the supply
voltage.

Most modern desktop personal computer power supplies conform to the ATX
specification, which includes form factor and voltage tolerances. While an ATX
power supply is connected to the mains supply, it always provides a 5 V standby
(5VSB) voltage so that the standby functions on the computer and certain
peripherals are powered. ATX power supplies are turned on and off by a signal
from the motherboard. They also provide a signal to the motherboard to indicate
when the DC voltages are in spec, so that the computer is able to safely power up
and boot.
The desktop computer power supply changes alternating current from a wall socket
to low-voltage direct current to operate the processor and peripheral devices.
Several direct-current voltages are required, and they must be regulated with some
accuracy to provide stable operation of the computer. A power supply rail or
voltage rail refers to a single voltage provided by a power supply unit (PSU).
Although the term is generally used in electronic engineering, many people,
especially computer enthusiasts, encounter it in the context of personal computer
power supplies.

First-generation microcomputer and home computer power supply units used a


heavy step-down transformer and a linear power supply. Modern computers use
switched-mode power supplies (SMPS) with a ferrite-cored high frequency
transformer. The switched-mode supply is much lighter and less costly, and is more
efficient, than an equivalent linear power supply.
Computer power supplies may have short circuit protection, overpower (overload)
protection, overvoltage protection, undervoltage protection, overcurrent protection,
and over temperature protection.
Recent power supplies have a standby voltage available, to allow most of the
computer system to be powered off. When the computer is powered down but the
power supply is still on, it can be started remotely via Wake-on-LAN and Wakeon-ring or locally via Keyboard Power ON (KBPO) if the motherboard supports it.
Power supplies may have passive or active power factor correction (PFC). Passive
PFC is a simple way of increasing the power factor by putting a coil in series with
the primary filter capacitors. Active PFC is more complex and can achieve higher
PF, up to 99%.

MODULE 2: LCD
LCD
LCD Introduction

An HD44780 Character LCD is an industry standard liquid crystal display (LCD)


display device designed for interfacing with embedded electronics. These screens
come in common configurations of 8x1 characters, 16x2, and 20x4 among others.
The largest such configuration is 40x4 characters, but these are rare and are
actually two separate 20x4 screens seamlessly joined together.
These screens are often found in copiers, fax machines, laser printers, industrial
test equipment, networking equipment such as routers and storage devices, etc.
These are not the kind of screens one would find in a cell phone, portable
television, etc. They are limited to text only, with 8 customizable characters.
Character LCDs can come with or without backlights. Backlights can be LED,
fluorescent, or electroluminescent.
Character LCDs use a standard 14-pin interface. If the screen has a backlight, it
will have 16 pins. The pinouts are as follows:
1. Ground
2. VCC (+5V)
3. Contrast adjustment
4. Register Select (R/S)

5. Read/Write (R/W)
6. Clock (Enable)
7. Bit 0
8. Bit 1
9. Bit 2
10.Bit 3
11.Bit 4
12.Bit 5
13.Bit 6
14.Bit 7
Character LCDs can operate in 4-bit or 8-bit mode. In 4 bit mode, pins 7 through
10 are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending a nybble at a time.

The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4
Line LCDs which have only one controller and support at most 80 characters,
whereas LCDs supporting more than 80 characters make use of 2 HD44780
controllers. Apart from displaying some simple static characters you can create
animated text scripts and a lot more!

Lets start playing with them, but you will have to wait a little as these things
mentioned below will help you to create your own magical codes

Most LCDs with 1 controller has 14 Pins and 16 Pins (two extra pins are for backlight LED connections). Pin description is shown in the table below. (We may also
have 16 pins in 2 controllers, refer to the datasheet for exact details).

This may not match with the exact pin configuration for your LCD, check
application circuit in datasheet for exact configuration.
We will discuss here 8 bit mode first (that is data transfer through all the 8 data
pins), 4 bit mode will be discussed later on.
Read/Write (RW):
1.) RW= 0, the information is being written on LCD.
2.) RW=1, for reading from LCD. (Only one command that is Get LCD status is
read commands all others are write command)
It is a control line. When RW is low (0), the information on the data bus is being
written to the LCD. When RW is high (1), the program is effectively querying (or

reading from) the LCD. Only one instruction ("Get LCD status") is a read
command. All others are write commands--so RW will be low for majority of the
time.

Registers:
There are two very important registers in the LCD. The RS pin is used for their
selection.
1.) RS= 0; The Instruction command code register, allows the user to send
command such as clear display, cursor at home, etc.
2.) RS=1; the data register, allow user to send data to be displayed at LCD.

Enable (En) pin: is used to tell the LCD that we are sending it data. A high to low
pulse (of minimum length 450ns) before sending any command/data to LCD.

How many characters can we send to LCD?

Display data RAM (DDRAM) stores display data represented in 8-bit character
codes. Its extended capacity is 80 X 8 bits, or 80 characters. The area in display
data RAM (DDRAM) that is not used for display can be used as general data
RAM. So whatever you send on the DDRAM is actually displayed on the LCD.
{For LCDs like 1x16, only 16 characters are visible, so whatever you write after 16
chars is written in DDRAM but is not visible to the user.}

(DDRAM address for 2 line LCD)

How does the ASCII value change to characters?

The answer is CGROM i.e. character generator ROM, is used to convert ASCII
values send by C into 5 x 8 dot or 5 x 10 dot character patterns from 8-bit
character. (You can also add your own characters in the list!!)

How much time should there be in two consecutive Commands/Instructions?

The first method is to create a delay between two consecutive commands or


instructions. (Check the datasheet for exact time of execution of an
instruction). This may not be very appropriate as the delay is not very
accurate.
BUSY FLAG (BF): The MSB of the LCD data bus (D7) act as busy flag.
When BF = 1 means LCD is busy and will not accept next command or data
and BF = 0 means LCD is ready for the next command or data to process.
This flag is internally set by LCD & can be monitored by C for exact
amount of delay.

To read Busy Flag, the conditions RS = 0 and R/W = 1 must be met.

STEPS TO PROGRAM:
1) Initialize the LCD.
2) Select the command or instruction register.
3) Set RW low (to write).
4) Send a high to low pulse on Enable pin.
5) Check if the LCD is busy.
6) Move to instruction or command function.
7) Repeat steps 4-7.

POWER SUPPLY

Block Diagram
The ac voltage, typically 220V rms, is connected to a transformer, which steps that
ac voltage down to the level of the desired dc output. A diode rectifier then
provides a full-wave rectified voltage that is initially filtered by a simple capacitor
filter to produce a dc voltage. This resulting dc voltage usually has some ripple or
ac voltage variation.

A regulator circuit removes the ripples and also remains the same dc value even if
the input dc voltage varies, or the load connected to the output dc voltage changes.
This voltage regulation is usually obtained using one of the popular voltage
regulator IC units.

TRANSFORMER

RECTIFIER

FILTER

IC
REGULATOR

Fig 5.3 Block Diagram of Power supply

CHAPTER-7
WORKING PRINCIPLE

Transformer

LOAD

The potential transformer will step down the power supply voltage (0-230V) to (06V) level. Then the secondary of the potential transformer will be connected to the
precision rectifier, which is constructed with the help of opamp. The advantages
of using precision rectifier are it will give peak voltage output as DC, rest of the
circuits will give only RMS output.

Bridge rectifier
When four diodes are connected as shown in figure, the circuit is called as bridge
rectifier. The input to the circuit is applied to the diagonally opposite corners of the
network, and the output is taken from the remaining two corners.
Let us assume that the transformer is working properly and there is a positive
potential, at point A and a negative potential at point B. the positive potential at
point A will forward bias D3 and reverse bias D4.
The negative potential at point B will forward bias D1 and reverse D2. At this time
D3 and D1 are forward biased and will allow current flow to pass through them;
D4 and D2 are reverse biased and will block current flow.
The path for current flow is from point B through D1, up through RL, through D3,
through the secondary of the transformer back to point B. this path is indicated by
the solid arrows. Waveforms (1) and (2) can be observed across D1 and D3.
One-half cycle later the polarity across the secondary of the transformer reverse,
forward biasing D2 and D4 and reverse biasing D1 and D3. Current flow will now
be from point A through D4, up through RL, through D2, through the secondary of
T1, and back to point A. This path is indicated by the broken arrows. Waveforms
(3) and (4) can be observed across D2 and D4. The current flow through RL is

always in the same direction. In flowing through RL this current develops a voltage
corresponding to that shown waveform (5). Since current flows through the load
(RL) during both half cycles of the applied voltage, this bridge rectifier is a fullwave rectifier.
One advantage of a bridge rectifier over a conventional full-wave rectifier is that
with a given transformer the bridge rectifier produces a voltage output that is
nearly twice that of the conventional full-wave circuit.
This may be shown by assigning values to some of the components shown in views
A and B. assume that the same transformer is used in both circuits. The peak
voltage developed between points X and y is 1000 volts in both circuits. In the
conventional full-wave circuit shownin view A, the peak voltage from the center
tap to either X or Y is 500 volts. Since only one diode can conduct at any instant,
the maximum voltage that can be rectified at any instant is 500 volts.
The maximum voltage that appears across the load resistor is nearly-but never
exceeds-500 v0lts, as result of the small voltage drop across the diode. In the
bridge rectifier shown in view B, the maximum voltage that can be rectified is the
full secondary voltage, which is 1000 volts. Therefore, the peak output voltage
across the load resistor is nearly 1000 volts. With both circuits using the same
transformer, the bridge rectifier circuit produces a higher output voltage than the
conventional full-wave rectifier circuit.
IC voltage regulators
Voltage regulators comprise a class of widely used ICs. Regulator IC units contain
the circuitry for reference source, comparator amplifier, control device, and
overload protection all in a single IC. IC units provide regulation of either a fixed
positive voltage, a fixed negative voltage, or an adjustably set voltage. The
regulators can be selected for operation with load currents from hundreds of milli
amperes to tens of amperes, corresponding to power ratings from milli watts to
tens of watts.

Fig 2.6 Circuit Diagram Of Power Supply

A fixed three-terminal voltage regulator has an unregulated dc input voltage, Vi,


applied to one input terminal, a regulated dc output voltage, Vo, from a second
terminal, with the third terminal connected to ground.
The series 78 regulators provide fixed positive regulated voltages from 5 to 24
volts. Similarly, the series 79 regulators provide fixed negative regulated voltages
from 5 to 24 volts.
For ICs, microcontroller, LCD --------- 5 volts
For alarm circuit, op-amp, relay circuits ---------- 12 volts

Module 2: Ultrasonic Sensor:


Ultrasonic sensor:

Ultrasonic sensors (also known as tranceivers when they both send and
receive) work on a principle similar to radar or sonar which evaluate attributes of a
target by interpreting the echoes from radio or sound waves respectively.
Ultrasonic sensors generate high frequency sound waves and evaluate the echo
which is received back by the sensor. Sensors calculate the time interval between
sending the signal and receiving the echo to determine the distance to an object.
This technology can be used for measuring: wind speed and direction
(anemometer), fullness of a tank, and speed through air or water. For measuring
speed or direction a device uses multiple detectors and calculates the speed from
the relative distances to particulates in the air or water. To measure the amount of
liquid in a tank, the sensor measures the distance to the surface of the fluid. Further
applications include: humidifiers, sonar, medical ultrasonography, burglar alarms,
and non-destructive testing.

Systems typically use a transducer which generates sound waves in the


ultrasonic range, above 20,000 hertz, by turning electrical energy into sound, then
upon receiving the echo turn the sound waves into electrical energy which can be
measured and displayed.
The technology is limited by the shapes of surfaces and the density or
consistency of the material. For example foam on the surface of a fluid in a tank
could distort a reading.
Transducers
Sound field of a non focusing 4MHz ultrasonic transducer with a near field
length of N=67mm in water. The plot shows the sound pressure at a logarithmic
db-scale.
Sound pressure field of the same ultrasonic transducer (4MHz, N=67mm)
with the transducer surface having a spherical curvature with the curvature radius
R=30mm
An ultrasonic transducer is a device that converts energy into ultrasound, or
sound waves above the normal range of human hearing. While technically a dog
whistle is an ultrasonic transducer that converts mechanical energy in the form of
air pressure into ultrasonic sound waves, the term is more apt to be used to refer to
piezoelectric transducers that convert electrical energy into sound. Piezoelectric
crystals have the property of changing size when a voltage is applied, thus
applying an alternating current (AC) across them causes them to oscillate at very
high frequencies, thus producing very high frequency sound waves.
The location at which a transducer focuses the sound, can be determined by
the active transducer area and shape, the ultrasound frequency and the sound

velocity of the propagation medium.The example shows the sound fields of an


unfocused and a focusing ultrasonic transducer in water.
Detectors
Since piezoelectric crystal generate a voltage when force is applied to them,
the same crystal can be used as an ultrasonic detector. Some systems use separate
transmitter and receiver components while others combine both in a single
piezoelectric transceiver.
Alternative methods for creating and detecting ultrasound include
magnetostriction and capacitive actuation.
Use in medicine
Medical ultrasonic transducers (probes) come in a variety of different
shapes and sizes for use in making pictures of different parts of the body. The
transducer may be passed over the surface of the body or inserted into an body
opening such as the rectum or vagina. Clinicians who perform ultrasound-guided
procedures often use a probe positioning system to hold the ultrasonic transducer.
Use in industry
Ultrasonic sensors are used to detect the presence of targets and to measure
the distance to targets in many automated factories and process plants. Sensors
with an on or off digital output are available for detecting the presence of objects,
and sensors with an analog output which varies proportionally to the sensor to
target separation distance are commercially available.
Other types of transducers are used in commercially available ultrasonic
cleaning devices. An ultrasonic transducer is affixed to a stainless steel pan which

is filled with a solvent (frequently water or isopropanol) and a square wave is


applied to it, imparting vibrational energy on the liquid.

ISD1820 voice recording and playback module


1. Introduction

This module board is based on ISD18B20, which is a single-chip single-message


record/playback device. Recordings are stored into on-chip non-volatile memory,
providing zero-power message storage. With the embedded Flash memory
employed, data retention up to 100 years and typical 100,000 erase/record cycles
can be reached. Time for recording is 8-20 seconds

Features:
1. Power input: DC 2.4-5.5V
2. With internal audio amplifier, this board can drive 8 Ohm 0.5W speaker directly.
3. Microphone is on board
4. Board dimension: 54mm x 38mm
5. All the pins of ISD1820 are extended out with an connector, which can powered
and controlled by microprocessor directly
ISD1820 voice recording and playback module
This module board is based on ISD18B20, which is a single-chip single-message
record/playback device. Recordings are stored into on-chip non-volatile
memory,providing zero-power message storage. With the embedded Flash memory
employed, data retention up to 100 years and typical 100,000 erase/record cycles
can be reached. Time for recording is 8-20 seconds
Features:
1. Power input: DC 2.4-5.5V
2. With internal audio amplifier, this board can drive 8 Ohm 0.5W speaker directly.

3. Microphone is on board
4. Board dimension: 54mm x 38mm
5. All the pins of ISD1820 are extended out with an connector, which can powered
and controlled by microprocessor directly.
MAX 232:
Max 232:
The MAX232 is a dual driver/receiver that includes a capacitive voltage generator to supply RS
232 voltage levels from a single 5v supply. Each receiver converts RS-232 to 5v TTL/CMOS levels. Each
driver converts TLL/CMOS input levels into EIA-232 levels. The P3_0 (RX) and P3_1 (TX) pin of
controller is connected to the max 232 driver and the TX and RX pin of max 232 is connected to the GSM
modem or PC.

In this circuit the microcontroller transmitter pin is connected in the MAX232 T2IN pin which
converts input 5v TTL/CMOS level to RS232 level. Then T2OUT pin is connected to reviver pin of 9 pin
D type serial connector which is directly connected to PC.
In PC the transmitting data is given to R2IN of MAX232 through transmitting pin of 9 pin D type
connector which converts the RS232 level to 5v TTL/CMOS level. The R2OUT pin is connected to

receiver pin of the microcontroller. Likewise the data is transmitted and received between the
microcontroller and PC or other device vice versa.

CIRCUIT:

Module 8: Motor Driver:


DRIVER CIRCUIT:
The ULN2003 is a monolithic high voltage and high current Darlington transistor arrays. It
consists of seven NPN darlington pairs that features high-voltage outputs with common-cathode clamp
diode for switching inductive loads. The collector-current rating of a single Darlington pair is 500mA.
The darlington pairs may be paralleled for higher current capability. Applications include relay drivers,
hammer drivers, lamp drivers, display drivers (LED gas discharge), line drivers, and logic buffers.
The ULN2003 has a 2.7kW series base resistor for each Darlington pair for operation directly
with TTL or 5V CMOS devices.

FEATURES:
* 500mA rated collector current (Single output)
* High-voltage outputs: 50V
* Inputs compatible with various types of logic.
* Relay driver application

The ULN2003 series input resistors selected for operation directly with 5 V TTL or CMOS.
These devices will handle numerous interface needs particularly those beyond the capabilities of standard
logic buffers.
The ULN2003 have series input resistors for operation directly from 6 V to 15 VCMOS or PMOS
logic outputs. The ULN 2003 is the standard Darlington arrays.
The outputs are capable of sinking 500mA and will withstand at least 50 V in the OFF state.
Outputs may be paralleled for higher load current capability. The ULx2823A/LW and ULx2824A/LW
will withstand 95 V in the OFF state.
These Darlington arrays are furnished in 18-pin dual in-line plastic packages (suffix A) or 18lead small-outline plastic packages (suffix LW). All devices are pinned with outputs opposite inputs to
facilitate ease of circuit board layout. Prefix ULN devices are rated for operation over the temperature
range of -20C to +85C; prefix ULQ devices are rated for operation to -40 C.

Embedded C
BASICS

This Embedded C is extensive and contains many advanced concepts. The range of modules
covers a full introduction to C, real-time and embedded systems concepts through to the design
and implementation of real time embedded or standalone systems based on real-time operating
systems and their device drivers. Real time Linux (RTLinux) is used as an example of such a
system. The modules include an introduction to the development of Linux device drivers.
Predominantly intended to be taught to development teams at customer sites it is not expected
that any one course would cover the full range of modules in a typical five day period. For teams
without experience of C and high-end real time operating sytems it would typically require eight
to ten days of intensive training to give full coverage to the topics included here. The course
covers all of the important features of the C language as well as a good grounding in the
principles and practices of real-time systems development including the POSIX threads
(pthreads) specification.
The design of the modules is intended to provide an excellent working knowledge of the C
language and its application to serious real time or embedded systems. Those wanting in-depth
training specifically on RTLinux or Linux kernel internals should contact us to discuss their
requirements; this set of modules is geared more towards providing the groundwork for
approaching those domains rather than as in-depth training on a specific approach.
The Embedded C basics contains essential information for anyone developing embedded systems
such as microcontrollers, real-time control systems, mobile device, PDAs and similar
applications. This C course is based on many years experience of teaching C, extensive industrial
programming experience and also participation in the ANSI X3J11 and BSI standards bodies that
produced the standard for C. We focus on the needs of day-to-day users of the language with the
emphasis being on practical use and delivery of reliable software.

MATLAB CODING:

clc; % Clear command window.


clear; % Delete all variables.
close all; % Close all figure windows except those created by
imtool;
imtool close all;
vid = videoinput('winvideo', 1, 'YUY2_640x480');
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval =5;
start(vid)
s = serial('COM1');
set(s,'BaudRate',9600);
fopen(s);
if red==1
fprintf(s,1);
end
fclose(s);
delete(s);
clear s;
while(vid.FramesAcquired<=50)
imge = getsnapshot(vid);
gray=rgb2gray(imge);
ir=imge(:,:,1);
ig=imge(:,:,2);
[r c d]=size(imge);
for i=1:r
for j=1:c
if gray(i,j)>50 && gray(i,j)<100 && ir(i,j)>70 && ir(i,j)<180 && ig(i,j)>20

temp(i,j)=255;
else
temp(i,j)=0;
end
end
end
subplot(1,1,1);
imshow(temp);
title('')
end
stop(vid);
flushdata(vid);
clear all;

PIC CODING:
#include<pic.h>
#include"lcd.h"
#include "uart.h"
unsigned char temp;
static bit m1 @ ((unsigned) & PORTC*8+0);
static bit m2 @ ((unsigned) & PORTC*8+1);
static bit m3 @ ((unsigned) & PORTC*8+2);
static bit m4 @ ((unsigned) & PORTC*8+3);
sfr16 DPTR =0x82;
sbit trig=P3^5;
void send_pulse(void) //to generate 10 microseconds delay
{
TH0=0x00;TL0=0x00;
trig=1;
_nop_();_nop_();_nop_();_nop_();_nop_();

_nop_();_nop_();_nop_();_nop_();_nop_();
trig=0;
}
unsigned int get_range(void)
{
unsigned int range;
send_pulse();
while(!INT0);//

in sake of these lines you can generate a delay of 40 Milli seconds=40000

micro
while (INT0);//

seconds

DPH=TH0;DPL=TL0;
TH0=0xFF;TL0=0xFF;
if(DPTR<35000)//actually you need to use 38000 but the sensor may not work at higher levels
range=DPTR/59;
else
range=0; // indicates that there is no obstacle in front of the sensor
return range;
__CONFIG(HS & WDTDIS & BOREN & UNPROTECT & LVPDIS);
void main(){
TXSTA=0X20;
RCSTA=0X90;
SPBRG=25;
BRGH=1;
TXEN=1;
SPEN=1;
RCIE=1;
TRISD=0x00; PORTD=0x00;
TRISB=0x00; PORTB=0x00;
TRISC=0X80;

LCD_command(0x38);
LCD_command(0x0c);
LCD_command(0x06);
LCD_command(0x01);
LCD_command(0x80);
LCD_dis(" FLUX ROBOT ",16);
while(1){
while(RCIF==0);
temp=RCREG;
if(temp == 'F'){
LCD_command(0xC0);
LCD_dis(" MOVING FORWARD ",16);
m1=1;
m2=0;
m3=1;
m4=0;
}else if(temp == 'L'){
LCD_command(0xC0);
LCD_dis(" MOVING RIGHT ",16);
m1=0;
m2=1;
m3=1;
m4=0;
}else if(temp == 'R'){
LCD_command(0xC0);
LCD_dis(" MOVING LEFT ",16);
m1=1;
m2=0;
m3=0;
m4=1;
}else if(temp == 'B'){

LCD_command(0xC0);
LCD_dis(" MOVING REVERSE ",16);
m1=0;
m2=1;
m3=0;
m4=1;
}else if (temp == 'S'){
LCD_command(0xC0);
LCD_dis(" ROBOT STOPPED ",16);
m1=0;
m2=0;
m3=0;
m4=0;
}
}
}

CHAPTER-8
CONCLUTION:
There are several ways to help blind people .by using this technology we
will make them forgot their defect. Then easy understand and any obstacles find

then clearly say to identify the particular path. Our sensor detect that any
information of particular period understand and that search location to transfer the
information of blind people safely in our control. It use of blind people to locate
that place very kindly move that around the out of side ownly. Sensor detects that
image identification it our recommended of process to be used the blind people.

REFEENCES:
1.

A. Stenz and M Hebert, A Complete Navigation System for Goal


Acquisition in Unknown Environments, presented at ARPA image Understanding
Workshop, Monterey, CA, 1994.

2.

Y. Goto and A. Stenz, Mobile Robot Navigation: The CMU System, in IEEE
expert, Vol. Winter, 1987, pp. 44-54.
Abstract | Full Text: PDF (5499KB)

3.

Magnus Snorrason, Jeff Norris and Paul Backes, Vision based obstacle
detection and path planning for planetary rovers

4.

The 33rd Annual conference of the IEEE industrial Electronics society


(IECON), 5-8-2007, Taipei, Taiman Development of Autonomous Robotic
wheelchair controller using Embedded system.

5.

G. Bourhis, O. Horn and A. Pruski An autonomous vehicle for people with


Motor Disabilities, IEEE Robotics & automation magazine Vo1.8, pp. 20-8-2001 .