80
A MAJOR PROJECT SYNOPSIS ON GESTURE CONTROL ROBOT CAR SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE AWARD OF THE DEGREE OF BACHELOR OF TECHNOLOGY -+IN ELECTRONICS & COMMUNICATION ENGINEERING Submitted By Abhinav roll no. 1811802 Rupesh roll no. 1811224 Gourav roll no. 1811241 under the guidance of er. Vivek kamboj 1

A Aaaaaaaaaaaaaaa

Embed Size (px)

DESCRIPTION

PROJECT

Citation preview

Page 1: A Aaaaaaaaaaaaaaa

A

MAJOR PROJECT SYNOPSIS

ON

GESTURE CONTROL ROBOT CAR

SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE

AWARD OF THE DEGREE OF

BACHELOR OF TECHNOLOGY

-+IN

ELECTRONICS & COMMUNICATION ENGINEERING

Submitted By

Abhinav roll no. 1811802

Rupesh roll no. 1811224

Gourav roll no. 1811241

under the guidance of

er. Vivek kamboj

(2011-2015)

1

Page 2: A Aaaaaaaaaaaaaaa

Haryana Engineering CollegeJagadhri

(Kurukshetra University, Kurukshetra)

ACKNOWLEDGEMENT

This project involved the collection and analysis of information from a wide variety of sources

and the efforts of many people beyond me. Thus it would not have been possible to achieve the

results reported in this document without their help, support and encouragement.

I will like to express my gratitude to the following people for their help in the work leading to

this report:

Ms. Medhavi Singh training supervisors: for their useful comments on the subject matter and for

the knowledge I gained by sharing ideas with them.

2

Page 3: A Aaaaaaaaaaaaaaa

CERTIFICATE

3

Page 4: A Aaaaaaaaaaaaaaa

ABSTRACT

The primary role of the Microchip PIC® and other embedded microcontrollers is to provide

inexpensive, programmable logic control and interfacing to external devices. This means they

typically are not required to provide highly complex functions—they can’t replace the Opteron

processor in your ISP’s server. They are well suited to monitoring a variety of inputs, including

digital signals, button presses, and analog inputs, and responding to them using the

preprogrammed instructions that are executed by the built-in computer processor. An embedded

microcontroller can respond to these inputs with a wide variety of outputs that are appropriate

for different devices. These capabilities are available to you at a very reasonable cost without a

lot of effort.

4

Page 5: A Aaaaaaaaaaaaaaa

List of Figures

Sr No. Title Page No.

Pic MicroController 11

Pin Diagram 14

5

Page 6: A Aaaaaaaaaaaaaaa

Core Architecture 17

MickroC Compiler 20

Program Formation in compiler 22

LED Interfacing 24

7-Segment Display 25

Interfacing & Control Of Stepper Motor 27

Interfacing Of LCD 28

Temperature Monitoring 29

ADCON0 Register 30

ADCON1 Register 31

Switching Action Of PIC Pins 32

Interfacing Of Keyboard Matrix 33

Serial Comm. b/w PC &MicroController 35

TXSTA Register 37

MikroC UART Terminal Work 38

PCB Desinging& Simulation Tools 40

OrCad Layout Plus 42

TINA PRO 45

CHAPTER - 16

Page 7: A Aaaaaaaaaaaaaaa

EMBEDDED SYSTEM

What is Embedded System?Embedded system employs a combination of software & hardware to perform a specific

function. It is a part of a larger system which may not be a “computer” Works in a reactive &

time constrained environment.

Any electronic system that uses a CPU chip, but that is not a general-purpose workstation,

desktop or laptop computer is known as embedded system. Such systems generally use

microprocessors; microcontroller or they may use custom-designed chips or both.

They are used in automobiles, planes, trains, space vehicles, machine tools, cameras, consumer

and office appliances, cell phones, PDAs and other handhelds as well as robots and toys. The

uses are endless, and billions of microprocessors are shipper every year for a myriad of

applications.

In embedded systems, the software is permanently set into a read-only memory such as a ROM

or flash memory chip, in contrast to a general-purpose computer that loads its programs into

RAM each time. Sometimes, single board and rack mounted general-purpose computers are

called "embedded computers".

An embedded system is a computer system designed for specific control functions within a

larger system, 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.

An Embedded System is a processor based system that is embedded as a subsystem, in a larger

system.Embedded Systems are computing systems with tightly coupled software & hardware

integration that are designed to perform a dedicated task or functions

7

Page 8: A Aaaaaaaaaaaaaaa

Embedded systems contain processing cores that are typically either microcontrollers or digital

signal processors (DSP) .The key characteristic, however, is being dedicated to handle a

particular task. 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.

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.

EMBEDDED HARDWARE+ SOFTWAREFINAL SYSTEM

PERIPHERALS

8

Specific taskSoftwareHardware

interfaces(serial, network,

etc)programmable

logic

processormemory

Page 9: A Aaaaaaaaaaaaaaa

i. Embedded Systems talk with the outside world via peripherals, such as:

II. Serial Communication Interfaces (SCI): RS-232, RS-422, RS-485 etc.

III. Synchronous Serial Communication Interface: I2C, SPI, SSC and ESSI

(Enhanced Synchronous Serial Interface)

IV. Universal Serial Bus  (USB)

V. Multi Media Cards (SD Cards, Compact Flash etc.)

VI. Networks: Ethernet, LonWorks, etc.

VII. Fieldbuses : CAN-Bus, LIN-Bus, PROFIBUS, etc.

VIII. Timers: PLL(s), Capture/Compare and Time Processing Units

IX. Discrete IO: aka General Purpose Input/Output (GPIO)

X. Analog to Digital/Digital to Analog (ADC/DAC)

XI. Debugging: JTAG, ISP, ICSP, BDM Port, BITP, and DP9 ports.

Embedded System Applications:-I. Consumer electronics, e.g., cameras, cell phones etc.

II. Consumer products, e.g. washers, microwave ovens etc.

III. Automobiles (anti-lock braking, engine control etc.)

IV. Industrial process controller & defense applications.

V. Computer/Communication products, e.g. printers, FAX machines etc.

VI. Medical Equipments.

VII. ATMs

VIII. Aircrafts

9

Page 10: A Aaaaaaaaaaaaaaa

DIFFERENCE BETWEEN MICROPROCESSORS AND

MICROCONTROLLERS:

I. A Microprocessor is a general purpose digital computer central processing unit

(C.P.U) popularly known as CPU on the chip. The Microprocessors contain no

RAM, no ROM, and no I/PO/P ports on the chip itself.

II. On the other hand a Microcontroller has a C.P.U(microprocessor)in addition to a

fixed amount of RAM, ROM, I/O ports and a timer all on a single chip.

10

Page 11: A Aaaaaaaaaaaaaaa

III. In order to make a Microprocessor functional we must add RAM,ROM, I/O Ports

and timers externally to them, i.e. any amount of external memory can be added

to it.

IV. But in controllers there is a fixed amount of memory which makes them ideal for

many applications.

V. The Microprocessors have many operational codes(opcodes) for moving data

from external memory to the C.P.U

VI. Whereas Microcontrollers may have one or two operational codes.

DISADVANTAGES OF MICROPROCESSORSOVER

MICROCONTROLLERS

I. System designed using Microprocessors are bulky.

II. They are expensive than Microcontrollers.

III. We need to add some external devices such as PPI chip, Memory, Timer/counter

chip, Interrupt controller chip, etc. to make it functional.

11

Page 12: A Aaaaaaaaaaaaaaa

TYPES OF MICROCONTROLLER ARCHITECTURE:There are two types of Microcontroller architecture designed for embedded

system development. These are:

I. RISC- Reduced instruction set computer.

II. CISC- Complex instruction set computer

DIFFERENCE BETWEEN CISC AND RISC:

CISC stands for Complex Instruction Set Computer. Most PC's use CPU based on this

architecture. For instance Intel and AMD CPU's are based on CISC architectures. Typically

CISC chips have a large amount of different and complex instructions. In common CISC chips

are relatively slow (compared to RISC chips)per instruction, but use little (less than RISC)

instructions. MCS-51 family microcontrollers based on CISC architecture. RICS stands for

Reduced Instruction Set Computer. The philosophy behind it is that almost no one uses complex

assembly language instructions as used by CISC, and people mostly use compilers which never

12

Page 13: A Aaaaaaaaaaaaaaa

use complex instructions. Therefore fewer, simpler and faster instructions would be better, than

the large, complex and slower CISC instructions. However, more instructions are needed .

I. PIC Microcontroller

PIC 18 Series – PIC18F458:

PIC is a family of modified Harvard

architecture microcontrollers made by Microchip

Technology, derived from the PIC1650 originally

developed by General Instrument's Microelectronics

Division. The name PIC initially referred to "Peripheral

Interface Controller".

PICs are popular with both industrial developers and

hobbyists alike due to their low cost, wide availability,

large user base, extensive collection of application notes,

availability of low cost or free development tools, and serial programming (and re-programming

with flash memory) capability.

Microchip announced on September 2011 the shipment of its ten billionth PIC processor.

Under 8bit comes: - PIC10XXXX, PIC12XXXX, PIC16XXXX, PIC18XXXX (12 bit

instruction set).

Under 16 bit comes: - PIC24H, DSPIC30, DSPIC33 (14bit instruction set).

Under 32 bit comes: - PIC32XXXX.

PICs are popular with developers and hobbyists alike due to their low cost, wide availability,

large user base, extensive collection of application notes, availability of low cost and free

13

Page 14: A Aaaaaaaaaaaaaaa

development tools, and serial programming (and re-programming with flash memory)

capability.

Special Microcontroller Features:

I. High-Performance RISC CPU

II. Linear data memory addressing to 1536 bytes

III. Linear program memory addressing to 32 kbytes

IV.    DC - 40 MHz clock input

V.     16-bit wide instructions, 8-bitwide data path

VI.    Priority levels for interrupts

VII.   8 x 8 Single-Cucle Hardware Multiplier

VIII.  Up to 10 MIPS operation

IX. 4 MHz-10 MHz oscillator/clock input with PLL active

Peripheral FeaturesI. High current sink/source 25 mA/25 mA

II. Three external interrupt pins

III. Two 16-bit timer/counter (TMR1, TMR3)

IV. One 8-bit/16-bit timer/counter with prescaler

V. One 8-bit timer/counter with 8-bit period register

VI. Capture 16-bit, max. resolution 6.25 ns.(TCY/16)

VII. Compare 16-bit, max. resolution 100 ns.

VIII. Secondary oscillator clock option - Timer1/Timer3

IX. I ²C Master and Slave mode

X. 1,2 or 4 PWM outputs

XI. Selectable PWM polarity

XII. 3-wire SPI

14

Page 15: A Aaaaaaaaaaaaaaa

XIII. Supports interrupt-on-address bit

Special Microcontroller FeaturesI. Power-On Reset (POR)

II. Power-up Timer (PWRT) and Oscillator Start-Up Timer (OST)

III. Power-On Reset

IV. Watchdog Timer (WDT) with its own On-Chip RC oscillator

V. Programmable code protection

VI. Power-saving SLEEP mode

VII. 4X Phase Lock Loop (of primary oscillator)

VIII. Secondary Oscillator (32kHz) clock input

IX. In-Circuit Debug (ICD)

Advanced Analog Features

I. 10-bit, up to 8-channel Analog-to-Digital Converter module (A/D)

II. Programmable input and output multiplexing

III. Programmable Brown-out Reset(BOR)

IV. Supports interrupt-on-Low-Voltage Detection

V. Compiles with ISO CAN Conformance Test

VI. Message bit rates up to 1 Mbps

VII. 8-byte message length

VIII. 29-bit Identifier Fields

IX. 3 Transmit Message Buffers with prioritization

X. 6 full, 29-bit Acceptance Filters

XI. Advanced Error Management Features

XII. Low-power, high-speed Enhanced Flash technology

XIII. Fully static design

XIV. Wide operating voltage range (2.0V to 5.5V)

15

Page 16: A Aaaaaaaaaaaaaaa

XV. Industrial and Extended temperature ranges

CMOS Technology:

I. Low power, high speed CMOS FLASH technology.

II. Fully Static Design.

III. Wide operating voltage range: 2.0V to 5.5V

IV. High Sink/Source Current: 25mA.

V. Industrial Temperature Range.

VI. Low power consumption (<2mA typical at 5V, 4MHz).

II. PIN DIAGRAM

16

Page 17: A Aaaaaaaaaaaaaaa

PIN Description

I. MCLR – (Pin 1):PIC16F7X devices have noise filter in the MCLR reset path. The

filter will detect and ignore small pulses. It should be noted that a WDT Reset does not

drive MCLR pin low. The behavior of the ESD protection on the MCLR pin has been

altered from previous devices of this family. Voltages applied to the pin that exceed its

specification can result in both MCLR Resets and excessive current beyond the device

specification during the ESD event. For this reason, Microchip recommends that the

MCLR pin no longer be tied directly to VDD.

II. RESET:The PIC16F7X differentiated between various kinds of RESET:

Power-on Reset (POR)

MCLR Reset during normal operation

MCLR Reset during SLEEP

WDT Reset (during normal operation)

WDT Wake-up (during SLEEP)

Brown-out Reset (BOR)17

Page 18: A Aaaaaaaaaaaaaaa

Some registers are not affected in any RESET condition. Their status is unknown on

POR and unchanged on any other RESET. Most others registers are reset to a RESET

state on Power-on Reset (POR), on the MCLR and WDT Reset, on MCLR Reset during

SLEEP, and Brown-out Reset (BOR). They are not affected by a WDT Wake-up, which

is viewed as the resumption of normal operation. The TO and PD bits are set or cleared

differently in different RESET situations, as indicated.

III. PORT A – (pin 2 to 7) & TRISA Register:PORT-A is a 6-bit wide, bi-

directional port. The corresponding data direction register is TRISA. Setting a TRISA bit

(= ‘1’) will make the corresponding PORTA pin an input (i.e. put the corresponding

output driver in a Hi-Impedance mode). Clearing a TRISA bit (= ‘0’) will make the

corresponding PORT-A pin an output (i.e. put contents of the output latch on the

selected pin). Reading the PORT-A register reads the status of the pins, whereas writing

to it will write to the port latch.

All write operations are read-modify-write operations. Therefore, a write to a port

implies that the port pins are read; the value is modified and then written to the port data

latch.

IV. GND – (pin-8):Provide Ground to it.

V. OSC1/CLKIN – (pin-9):Oscillator crystal input/external clock source input.

VI. OSC2/CLKOUT – (pin-10):Oscillator crystal output connects to crystal or

resonator in Crystal Oscillator mode. In RC mode, the OSC2 pin outputs CLKOUT

which has ¼ the frequency of OSC1, and denotes the instruction cycle rate.

Oscillator Types:i. Low Power (LP) crystal.

ii. XT Crystal/Resonator

iii. HS high speed crystal/resonator

18

Page 19: A Aaaaaaaaaaaaaaa

iv. RC Resistor/Capacitor

VII. PORT-C and the TRISC Register (pin 15 – 18 and 23-26):PORT-C is an 8-

bit, bi-directional port. The corresponding data direction register is TRISC. Setting a

TRISC bit (= ‘1’) will make the corresponding PORTC pin an input (i.e. put the

corresponding output driver in a Hi-Impedance mode). Clearing a TRISC bit (= ‘0’) will

make the corresponding PORT pin an output (i.e. put the contents of the output latch on

selected pin). PORT-C is multiplexed with several peripheral functions PORT-C pins

have Schmitt Trigger input buffers. When enabling peripheral functions, care should be

taken in defining TRIS bits for each PORT-C pin.

VIII. VSS (pin 12): Ground reference for logic and I/O pins.

IX. VDD (pin 11):Positive supply for logic and I/O pins.

X. PORT-B and the TRISB Register (pin 33-40):PORT-B is an 8-bit wide, bi-

directional port. The corresponding data direction register is TRISB. Setting a TRISB bit

(= ‘1’) will make the corresponding PORTB pin an input (i.e. put the corresponding out

driver in a Hi-Impedance mode). Clearing a TRISB bit (= ‘0’) will make corresponding

PORTB pin an output (i.e. put the contents of the output latch on the selected pin).

Each of the PORT-B pins has a week internal pull-up. A single control bit can turn on

the pull-ups. The weak pull-up is automatically turned off when the port pin is

configured as an output. The pull ups are disabled on Power-on Reset.

III. PIC MICROCONTROLLER

CORE ARTITECTURE

19

Page 20: A Aaaaaaaaaaaaaaa

PIC is a family of modified Harvard architecture microcontrollers made by Microchip

Technology, derived from the PIC1650 originally developed by General Instrument's

Microelectronics Division. The name PIC initially referred to "Peripheral Interface

Controller".

PICs are popular with both industrial developers and hobbyists alike due to their low cost, wide

availability, large user base, extensive collection of application notes, availability of low cost or

free development tools, and serial programming (and re-programming with flash memory)

capability.

Microchip announced on September 2011 the shipment of its ten billionth PIC processor.

CORE ARCHITECTUR

20

Page 21: A Aaaaaaaaaaaaaaa

Figure: Showing a typical microcontroller device and its different subunits.

The PIC architecture is distinctively minimalist. It is characterized by the following features:

i. Separate code and data spaces (Harvard Architecture).

ii. A small number of fixed length instructions.

21

Page 22: A Aaaaaaaaaaaaaaa

iii. Most instructions are single cycle execution (4 clock cycles), with a single delay cycles upon

branches and skips.

iv. A single accumulator (W), the use of which (as source operand) is implied (i.e. is not encoded in

the opcode).

v. All RAM locations functions are registers as both source and/or destination of math and other

functions.

vi. A hardware stack for storing return addresses.

vii. A fairly small amount of addressable data space (typically 256 bytes), extended through

banking.

viii. Data space mapped CPU, port and peripheral registers.

ix. The program counter is also mapped into the data space and writable (this is used to implement

indirect jumps).

Unlike most other CPU’s there is no distinction between memory space and register space

because the RAM serves the job of both memory and registers, and the RAM is usually just

referred to as the register file or simply as the registers.

Advantages

The PIC architectures have these advantages:

I. instruction set to learn22

Page 23: A Aaaaaaaaaaaaaaa

II. RISC architecture

III. Built in oscillator with selectable speeds

IV. Easy entry level, in circuit programming plus in circuit debugging pic kit units available from

Microchip.com for less than $50

V. Inexpensive microcontrollers

VI. Wide range of interfaces including PC, SPI, USB, USART, a/d, programmable

comparators, PWM,  can Small, PSP, and Ethernet.

Limitations

The PIC architectures have these limitations:

I. One accumulator.

II. Register-bank switching is required to access the entire RAM of many devices

III. Operations and registers are not orthognal; some instructions can address RAM

and/or immediate constants, while others can only use the accumulato

IV. PROGRAMMING OF PIC

Compiler Used: - MikroC PRO

23

Page 24: A Aaaaaaaaaaaaaaa

Introduction to mikroC:mikroC is a powerful, feature rich development tool for PIC micros.

It is designed to provide the programmer with the easiest possible solution for developing

applications for embedded systems, without compromising performance or control.

MikroC IDE: PIC and C fit together well; PIC is the most popular 8-bit chip in the world,

used in a wide variety of applications and C prized for its efficiency, is the natural choice for

developing embedded systems. MikroC provides a successful match featuring highly advanced

IDE, ANSI compliant compiler, broad set of hardware libraries, comprehensive documentation,

and plenty of ready-to-run examples.

Features:mikroC allows you to quickly develop and deploy complex applications:

i. Write your C source code using the built-in Code Editor (Code and Parameter Assistants,

Syntax Highlighting, Auto Correct, Code Templates and more…)

24

Page 25: A Aaaaaaaaaaaaaaa

ii. Use the included mikroC libraries to dramatically speed up the development: data acquisition,

memory, displays, conversions, communications… practically all P12, P16 and P18 chips are

supported.

iii. Monitor your program structure, variables and functions in the code explorer.

iv. Generate commented, human-readable assembly, and standard HEX compatible with all

programmers.

v. Inspect program flow and debug executable logic with the integrated debugger.

vi. Get detailed reports and graphs: RAM and ROM map, code statistics, assembly listing, calling

tree and more.

vii. We have provided plenty of examples for you to expand, develop and use as building bricks in

your projects. Copy them entirely if you deem fit – that’s why we included them with the

compiler.

Projects:mikroC organizes applications into projects, consisting of a single project file

(extension .ppc) and one or more source files (extension .c). You can compile source files only

if they are part of a project.

The Project file carries the following information:

i. Project name and optional description.

ii. Target device

iii. Device flags (config word).

iv. Device Clock.

25

Page 26: A Aaaaaaaaaaaaaaa

New Project:T he easiest way to create project is by means of New Project Wizard, drop-

down menu Project > New Project. Just fill the dialog with desired values (project name and

description, location, device, clock, config word) and mikroC will create the appropriate project

file. Also the empty source file named after the project will be created by default. MikroC does

not require you to have source file named same as the project, it’s just a matter of convenience.

Edit Project: Later, you can change project settings from the drop down menu Project > Edit

Project. You can rename the project; modify its description, change chip, clock, config word,

etc.

Also mikroC has some pre-defined functions:

Commonly used is:

delay_ms(time): It provides a delay of specified time in ms.

Its internal code is similar to code given below:

26

Page 27: A Aaaaaaaaaaaaaaa

voiddelay_ms(time) {

while(time !=0)

{

time--;

}

V. PROGRAMMING AND INTERFACING

Advantages of mikroC over Assemble Language programming:

27

Page 28: A Aaaaaaaaaaaaaaa

I. Knowledge of the processor instruction set is not required.

II. Details like register allocation and addressing of memory and data is managed by the compiler.

III. Programs get a formal structure and can be divided into separate functions.

IV. Programming and program test time is drastically reduced, this increases efficiency.

V. Keywords and operational functions can be used that come closer to how humans think.

VI. The supplied and supported C libraries contain many standard routines such as numeric

conversions.

VII. Reusable code: Existing program parts can be more easily included into new programs, because

of the comfortable modular program construction.

VIII. The C language based on the ANSI standard is very portable. Existing programs can be quickly

adapted to other processors as needed.

I: LED interfacing and its blinking (PORT Programming).

28

Page 29: A Aaaaaaaaaaaaaaa

The interfacing of LED’s shown in the figure above. It is given VCC through resistors of 330E,

also a darlington pair IC is also used i.e. ULN 2803 which shift the DC level of voltage coming

from the port PIC microcontroller.

Now to glow the desired LED, proper hexadecimal code for its binary is programmed in PIC.

E.g.: To glow alternative LED’s, the binary given code will be 10101010 and its corresponding

hexadecimal code will be 0xAA. So 0xAA is fed to controller with coding.

Also PIC has an internal TRIS register which controls the flow of instructions from the

corresponding port i.e. PORT will behave as input (if =1) and as output (if=0).

29

Page 30: A Aaaaaaaaaaaaaaa

CODE FOR BLINKING:

void main()

{

TRISC = 0x00; //Configure PORTC as output

PORTC = 0x00; //initialize PORTC

while(1)

{

PORTC = 0xAA; //gives code 10101010 to PORT-C

delay_ms(1000); //one second delay

}

}

Thus LED blinking practical is done successfully

II: Seven Segment interfacing and display.

A Seven segment display consists of seven LED’s arranged in a pattern of digit like 8.

We use BCD to seven segment decoder which saves a pin of microcontroller from seven (one

for each LED) to four. So we have to give BCD code for desired digit to be displayed on it.

Now also we can display more than one seven segment display simultaneously but it will take a

number of pins of controller, so we use two pins from controller to control the display of seven

30

Page 31: A Aaaaaaaaaaaaaaa

segment display one by one from port such that it appears to be displaying simultaneously. This

is done by providing a very small delay such that our eyes can’t even detect the change over

from one display to another.

Coding for Display:

void main()

{

inti,j;

unsigned chararr[10]={0x3f,0x06,0x5b,0x4f,0x66 , 0

x6d,0x7d,0x07,0x7f,0x6f};

while(1)

{

trisb=0x00;

trisc=0x00;

for(i=0;i<=9;i++)

{ portc=arr[i];

for(j=0;j<=9;j++)

{

portb=arr[j];

delay_ms(100);

}

}

}

}

Or

void main() {

inti;

31

Page 32: A Aaaaaaaaaaaaaaa

unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

while(1)

{

trisb=0x00;

for(i=0;i<=9;i++)

{

portb=arr[i];

delay_ms(300);

}

}

}

III: Interfacing and Control of Stepper Motor with PIC18F458.

32

Page 33: A Aaaaaaaaaaaaaaa

Stepper motor is that which rotates in steps like all motors it is also based on electromagnetic

induction i.e. electric field produces a magnetic field whose variation causes a torque which

rotates the motor.

A Stepper motor is brushless, synchronous electric motor that can divide a full rotation into

large number of steps. The motor’s position can be controlled precisely, without any feedback

mechanism. Stepper motors are similar to switched reluctance motors, which are very large

stepping motors with a reduced pole count and generally are closed loop commutated.

Fundamentals of Operation: Stepper motors operate much differently from normal DC motors,

which rotate when voltage is applied to their terminals. Stepper motors, on the other hand,

effectively have multiple “toothed” electromagnets (a.k.a. phases) arranged around a central

gear-shaped piece of iron. The electromagnets are energized by an external control circuit, such

as microcontroller. To make the motor shaft turn, first 1 electromagnet is given power, which

makes the gear’s teeth magnetically attracted to the electromaget’s teeth.

33

Page 34: A Aaaaaaaaaaaaaaa

When the gear’s teeth are thus aligned to the first electromagnet, they are slightly offset from

the next electromagnet. So when the next electromagnet is turned on and the first is turned off,

the gear rotates slightly to align with the next one, and from the process is repeated. Each of

those slight rotations is called a “step”. In that way, the motor can be turned a precise angle.

Now to run the motor we have to feed the binary code to turn on the current of that winding.

For pair 1st – 0b00000011 – 0x03

For pair 2nd – 0b00000110 – 0x06

For pair 3rd – 0b00001100 – 0x0c

For pair 4th – 0b00011000 – 0x09

34

Page 35: A Aaaaaaaaaaaaaaa

MikroC code:

#define sw1 portb.rb3

#define sw2 portb.rb4

#define sw3 portb.rb5

#define sw4 portb.rb6

#define sw5 portb.rb7

void main()

{

while(1)

{

trisb=0xff;

trisc=0x00;

sw1=sw2=sw3=sw4=sw5=0;

if(sw1==1)

{

portc=0x0a; //move forward

}

else if(sw2==1)

{

portc=0x05; //move backward

}

else if(sw3==1)

{

portc=0x08; //move left

}

else if (sw4==1)

{

portc=0x02; //move right

}

35

Page 36: A Aaaaaaaaaaaaaaa

else if(sw5==1)

{

portc=0x00; //stop

}

else

{

portc=0x00;

}

}

}

The above code will rotate the motor first in forward direction and then in reverse direction.

The stepper motor has been studied successfully.

36

Page 37: A Aaaaaaaaaaaaaaa

IV: LCD interfacing with PIC18F73.

LCD Stands for Liquid Crystalline

Display. To run it via PIC18F73, we

need command signals and supply

voltage. The signal that is required to

display character is produced by an IC

which is already embedded on it which is

HD44780.

PIN Description of the LCD is provided

below in the table:

37

Page 38: A Aaaaaaaaaaaaaaa

LCD PIC DESCRIPTION

Probably this very post should have come before the number of other posts related to 8051 LCD

interfacing, but its never too late. This post will describe you about the pins of LCD normally

available in the market. It looks almost like the one shown below. As you guys can see that

there are 8 data pins along with 3 control pins. One ground and two power pins are also there.

Lets study about these pins of LCD

VSS, VDD and VEE

Pin 1 (VSS) is a ground pin and it is certainly needed that this pin  should be grounded for LCD

to work properly. VEE and VDD are given +5 vlots normally. However VEE may have a

 Pin No

 Function  Name

1 Ground (0V) Ground

2 Supply voltage; 5V (4.7V – 5.3V)  Vcc

3 Contrast adjustment; through a

variable resistor

 VEE

4 Selects command register when

low; and data register when high

Register Select

5 Low to write to the register; High Read/write

38

Page 39: A Aaaaaaaaaaaaaaa

to read from the register

6 Sends data to data pins when a

high to low pulse is given

Enable

7

8-bit data pins

DB0

8 DB1

9 DB2

10 DB3

11 DB4

12 DB5

13 DB6

14 DB7

15 Backlight VCC (5V) Led+

16 Backlight Ground (0V) Led-

potentiometer voltage divider network to get the contrast adjusted. But VDD is always at +5V.

RS, R/W and E 

These three pins are numbered 4, 5 and 6 as shown above. RS is used to make the selection

between data and command register. For RS=0, command register is selected and for RS=1 data

register is selected.

R/W gives you the choice between writing and reading. If set (R/W=1) reading is enabled.

R/W=0 when writing.

Enable pins is used by the LCD to latch information presented to its data pins. When data is

supplied to data pins, a high to low pulse must be applied to this pin in-order for the LCD to

latch in the data present at the data pins. It maybe noted here that the pulse must be of minimum

450ns wide. 

39

Page 40: A Aaaaaaaaaaaaaaa

D0-D7 

The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of

LCD's internal register.

The following paragraph is taken and included from "Muhammad Ali Mazidi", 

"To display letters and numbers, we send ASCII code for the letters A-Z, a-z and numbers 0-9

while making RS=1. We also use RS=0 to check the busy flag bit to see if the LCD is ready to

receive information. The busy flag is D-7 and can be read when R/W=1 and RS=0, as follows: if

R/W=1, RS=0. When D7=1 (busy flag=1), the LCD is busy taking care of internal operations

and will not accept any new information. When D7=0, the LCD is ready to receive new

information. It is recommended to check the busy flag before writing any data to LCD"

MikroC Code:

void main()

{

TRISB = 0x00; //Set PORTB as Output

LCD_Init(&PORTB); //Initialize LCD connected to PORTB

LCD_CMD(LCD_CLEAR); //Clear Display

LCD_CMD(LCD_CURSOR_OFF); //Turn Cursor off

LCD_OUT(1, 5, “Hello”); //Print Hello to LCD, 1st ROW, 5th Column

}

The above code will display Hello on LCD.

The functions like LCD_INIT(), LCD_CMD(), LCD_OUT() are predefined functions in

MikroC which initialize, gives command and display results on LCD respectively. It is also

possible to scroll characters on LCD and also you can put custom characters on LCD.

40

Page 41: A Aaaaaaaaaaaaaaa

MikroC Code for Scrolling:char *text = “HELLO”;

char *text1 = “ECE”;

void main()

{

TRISB = 0x00;

LCD_INIT(&PORTB);

LCD_CMD(LCD_CLEAR);

LCD_CMD(LCD_CURSOR_OFF);

LCD_OUT(1, 1, text);

LCD_OUT(2, 1, text1);

while(1)

{

LCD_CMD(LCD_SHIFT_RIGHT);

delay_ms(1000);

}

}It will shift the character to right with a delay of 1 second between it. Thus LCD Display

studied successfull

41

Page 42: A Aaaaaaaaaaaaaaa

V: Built In ADC of PIC16F73 (Temperature Monitoring):

PIC16F73 consists of 5 ADC. These are externally connected to microcontroller AT89S51

which don’t have inbuilt ADC. Now PIC16XXX has got the feature of inbuilt ADC so there is

no need to connect externally. PIC16XXX is feature with 8 bit ADC so we can convert an

analog value to 8 bit binary or from 0 to 255 in decimal range. 8 bit analog-to-digital converter

module has five inputs for the PIC16F73/76 and 8 for PIC16F74/77.

The A/D allows conversion of an analog input signal to a corresponding 8-bit digital number.

The output of sample and hold is the input to the converter, which generates the result via

successive approximation, the analog reference voltage is software selectable to either the

device’s positive supply voltage (VDD), or the v/g level on the RA3/AN3/VREF pin.

The A/D converter has a unique feature of being able to operate while the device is in SLEEP

mode. To operate in SLEEP, the A/D conversion clock must be derived from the A/D internal

RC oscillator. The A/D module has three registers. These registers are:

i. A/D Result Register (ADRES)

ii. A/D Control Register 0 (ADCON0)

iii. A/D Control Register 1 (ADCON1)

The ADCON0 register, shown in Register11-1, controls the operation of A/D module. The

ADCON1 register, shown in register 11-2, configures the functions of the port pins. The port

pins can be configured as analog inputs (RA3 can also be a voltage reference), or as digital I/O.

42

Page 43: A Aaaaaaaaaaaaaaa

ADCON0 Register

ADCON0 Register – PIC 16F877A

ADCS1 and ADCS2 are used to select A/D Conversion Clock. It should be selected in

accordance with device clock.

CH2, CH1 and CH0 are used to select one of the analog input channel out of eight channels.

GO/DONE is the A/D Conversion Status bit. Setting this bit initializes A/D Conversion and

will be automatically cleared when the conversion is complete.

ADON is used to switch on/off the ADC Module. When it is 1, the ADC Module turns ON and

when it is 0, the ADC Module will be OFF.

43

Page 44: A Aaaaaaaaaaaaaaa

ADCON1 Register

ADCON1 Register – PIC 16F877A

ADFM is the ADC Result Format select bit. Two 8 bit register (ADRESH and ADRESL) are

provided to store the 10-bit result of A/D Conversion, thus we need’t use 6 bits. When ADFM is

1, the result will be right justified, ie Most Significant Bits of ADRESH will be read as 0. When

ADFM is 0, the result will be left justified, ie Least Significant Bits of ADRESL will be read as

zero.

ADCS2 is used to select A/D Conversion Clock in association with ADCS1 and ADC2 of

ADCON0 register.

PCFG3 – PCFG0 are the A/D Port Configuration Control bits. Each pin amoung AN0 – AN7 is

configured as analog, digital or reference voltage inputs according to the status of these

configuration bits as given below

MikroC Code for Temp. Sensor:

voidascii(unsigned int digit);

unsigned char table [] = {‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’};

void main()

{

PORTB = 0x00;

unsignedint e, f;

LCD_INIT(&PORTB);

LCD_CMD(LCD_CLEAR);

LCD_CMD(LCD_CURSOR_OFF);44

Page 45: A Aaaaaaaaaaaaaaa

LCD_OUT(1, 1, “Sensor Temp=”);

ADCON0 = 0x45;

ADCON1 = 0x01;

TRISA = 0xFF;

while(1)

{

e = ADC_READ(1);

ascii(e);

delay_ms(1000);

}

}

voidascii (unsigned int digit)

{

unsigned char temp;

if(digit<100)

{

temp=digit/10;

LCD_CHR(1, 1, table[temp]);

temp = digit – temp*10;

LCD_CHR(1, 2, table[temp]);

}

}

45

Page 46: A Aaaaaaaaaaaaaaa

VI: To study the switching actions of PIC pins.

As in AT89S51, the way of addressing pins is by p0.0, p0.1……. so on. Similarly in PIC it is

possible to address pins using syntax:

PORT(NAME).F(0-7)

Now pin can be put ON or OFF according to user by the above addressing in the program of

PIC. Internally when the pin is high its flip flop is set. When external switch is closed, it forces

no current or voltage to enter to pin and also lowers the pin from 1 to 0. Thus when the switch is

pressed, the pin becomes zero. The switches whose one end is connected to pins of controlled

are shown below:

MikroC Code is as follows:

#define S0 PORTC.F0

46

Page 47: A Aaaaaaaaaaaaaaa

#define S1 PORTC.F1

#define S2 PORTC.F2

#define S3 PORTC.F3

#define S4 PORTC.F4

#define rs porte.re0

#define rw porte.re1

#define en porte.re2

#define sw1 portb.rb3

#define sw2 portb.rb4

#define sw3 portb.rb5

#define sw4 portb.rb6

unsigned char arr1[5]={0x06,0x80,0x01,0x38,0x0e};

unsigned char arr2[8]={"forward"};

unsigned char arr3[9]={"backward"};

unsigned char arr4[5]={"left"};

unsigned char arr5[6]={"right"};

unsigned char arr6[5]={"stop"};

void command()

{ rs=rw=0;

en=0;

delay_ms(100);

en=1;

}

void display()

{

rs=1;

rw=0;

en=1;

delay_ms(100);

en=0;

}47

Page 48: A Aaaaaaaaaaaaaaa

void main()

{

inti;

while(1)

{

trisb=0xf8;

trisc=trisd=0x00;

trise=0x00;

adcon1=0x07;

sw1=sw2=sw3=sw4=0;

for(i=0;i<=4;i++)

{ portd=arr1[i];

command();

}

if(sw1==1)

{

portc=0x0a; //move forward

for(i=0;i<=7;i++)

{ portd=arr2[i];

display();

}

}

else if(sw2==1)

{

portc=0x05; //move backward

for(i=0;i<=8;i++)

{ portd=arr3[i];

display();

}

}

else if(sw3==1)48

Page 49: A Aaaaaaaaaaaaaaa

{

portc=0x08; //move left

for(i=0;i<=4;i++)

{ portd=arr4[i];

display();

}

}

else if (sw4==1)

{

portc=0x02; //move right

for(i=0;i<=4;i++)

{ portd=arr5[i];

display();

}

}

else

{

portc=0x00; //stop

for(i=0;i<=10;i++)

{ portd=arr6[i];

display();

}

}

}

49

Page 50: A Aaaaaaaaaaaaaaa

VII: Interfacing Keyboard Matrix

As in last practical, we use one switch per pin of controller, so to use 8 pins for 8 switches.

While if it is desired to have more options for a pin, a matrix is formed in which row and

column are made such that each pin can control more than one switch or vice versa.

H/w connections are:

The coding for keyboard (4*4) matrix is as follows:

#define R1 PORTB.F0

#define R2 PORTB.F1

#define R3 PORTB.F2

#define R4 PORTB.F3

#define C1 PORTB.F4

#define C2 PORTB.F5

#define C3 PORTB.F6

#define C4 PORTB.F7

void main()

{

TRISB=0XFF;50

Page 51: A Aaaaaaaaaaaaaaa

TRISC=0X00;

PORTC=0X00;

PORTB=0XFF;

while(1)

{

if(R1==0 && C1==0)

{

PORTC=1;

}

if(R1==0 && C2==0)

{

PORTC=2;

}

if(R1==0 && C3==0)

{

PORTC=3;

}

if(R1==0 && C4==0)

{

PORTC=4;

}

if(R2==0 && C1==0)

{

PORTC=5;

}

if(R2==0 && C2==0)

{

PORTC=6;

}

if(R2==0 && C3==0)

{51

Page 52: A Aaaaaaaaaaaaaaa

PORTC=7;

}

if(R2==0 && C4==0)

{

PORTC=8;

}

if(R3==0 && C1==0)

{

PORTC=9;

}

if(R3==0 && C2==0)

{

PORTC=10;

}

if(R3==0 && C3==0)

{

PORTC=11;

}

if(R3==0 && C4==0)

{

PORTC=12;

}

if(R4==0 && C1==0)

{

PORTC=13;

}

if(R4==0 && C2==0)

{

PORTC=14;

}

if(R4==0 && C3==0)52

Page 53: A Aaaaaaaaaaaaaaa

{

PORTC=15;

}

if(R4==0 && C4==0)

{

PORTC=16;

}

}

}

Thus, the keyboard matrix practical is performed.

53

Page 54: A Aaaaaaaaaaaaaaa

VIII: Serial Communication B/W PC and Microcontroller

To send data via single line through a bit stream is known as serial communication. Reception is

of type SIPO-Serial Input Parallel Output. Transmission is of type PISO-Parallel Input Serial

Output. Clock used in serial communication is called BAUD RATE.PIC has two buffers and it

allows full duplex communication. To change settings we have to re configure TXSTA register.

The Universal Synchronous Asynchronous Receiver Transmitter (USART) module is one of the

two serial I/O modules. (USART is also known as a Serial Communications Interface or SCI.)

The USART can be configured. as a full duplex asynchronous system that can communicate

with peripheral devices, such as CRT terminals and personal computers, or it can be configured

as a half-duplex synchronous system that can communicate with peripheral devices, such as

A/D or D/A integrated circuits, serial EEPROMs, etc.

The USART can be configured in the following modes:

54

Page 55: A Aaaaaaaaaaaaaaa

i. Asynchronous (full duplex)

ii. Synchronous - Master (half duplex)

iii. Synchronous - Slave (half duplex)

Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order to configure pins

RC6/TX/CK and RC7/RX/DT as the Universal Synchronous Asynchronous Receiver

Transmitter.

TXSTA: TRANSMIT STATUS AND CONTROL REGISTER (ADDRESS 98h)

TXSTA Register Role: (Transmit Status and Control Register)

          It is an 8-bit register.

Bit7:          CSRC – Clock Source Select (not used in asynchronous mode, so D7 = 0)

Bit6:          TX9 – 9-bit Transmit Enable

1 – Select 9-bit transmission

0 - Select 8-bit transmission (we use this option, so D6 = 0)

Bit5:          TXEN – Transmit Enable

1 – Transmit enabled

0 - Transmit Disabled

Bit4:          SYNC – USART mode select

1 – Synchronous mode

55

Page 56: A Aaaaaaaaaaaaaaa

0 - Asynchronous mode (we use this mode, so D4 = 0)

Bit2:          BRGH – High Baud Rate select

0 – Low Speed (Default)

1 – High Speed

Bit1:          TRMT – Transmit Shift Register (TSR) status

1 – TSR empty

0 – TSR full

Bit0:         TXD9 – 9th bit of transmit data (we use 8-bit option, so D0 = 0)

MikroC UART terminal work as shown below:

56

Page 57: A Aaaaaaaaaaaaaaa

Now coding

I. To transmitdata from pc

unsigned char arr[]="cetpainfotech"

void main() {

while(1)

{

inti;

spbrg=0x0f;

rcsta.SPEN=1;

txsta.txen=1;

while(pir1.TXIF==0);

for(i=0;i<=26;i++)57

Page 58: A Aaaaaaaaaaaaaaa

{

txreg=arr[i];

}

II. }To read data from pc:#define rs portc.rc0

#define rw portc.rc1

#define en portc.rc2

unsigned char arr[5]={0x38,0x0e,0x01,0x80,0x06};

void command();

void display();

void main()

{

inti;

trisb=0x00;

trisc=0xf0;

for(i=0;i<=4;i++)

{

portb=arr[i];

command();

}

while(1)

{

spbrg=15;

rcsta=0x90;

while(pir1.rcif==0);

portb=rcreg;

display();58

Page 59: A Aaaaaaaaaaaaaaa

}

}

void command()

{

rs=rw=0;

en=1;

delay_ms(100);

en=0;

}

void display()

{

rs=1;

rw=0;

en=1;

delay_ms(100);

en=0;

}

Thus serial communication has been studied successfully.

PCB DESIGNING AND SIMULATION TOOL

OrCAD:

OrCAD is a powerful tool for designing a PCB (Printed Circuit Board). As in today’s world, the

PCB’s are used everywhere in electronics industries for the manufactures of the products.

Various equipment we use in our daily life contains PCB’s such as Cell Phones, Computers,

Chargers, and Digital Watches etc. all these contains various forms of PCB’s and components

applied on them which make them work according to our needs. These PCB’s can be designed

using various tools and OrCAD is one of them. However OrCAD uses two major tools to do

this, Capture CIS and Layout Plus.

59

Page 60: A Aaaaaaaaaaaaaaa

OrCAD Capture CIS:Capture CIS tool in the OrCAD is programmed to design the

schematics of a circuit. i.e. using this tool, we can design the circuit diagram of any circuit and

select various components we want to apply in that circuit. Capture CIS contains all the

components (Active and Passive) that we need to make a circuit. A circuit designed in Capture

CIS is shown below:

OrCAD Layout Plus: In Capture CIS, we can only make the circuit diagram of the circuit we

want to create PCB of. Here is the 2nd major tool of OrCAD which we use to create PCB design.

Layout Plus imports the files from capture CIS and design the circuit accordingly. The file it

imports is a NETLIST file which contains the information of the nets (wires) and components

attached to them. With the help of information contained in the NETLIST file, layout plus

creates the components footprints and hence it forms the PCB design. A PCB designed in layout

plus is shown as below:

60

Page 61: A Aaaaaaaaaaaaaaa

61

Page 62: A Aaaaaaaaaaaaaaa

TINA Pro:

TINA Pro is a software which we can use to test the circuit diagram or the circuit we created.

This is a very useful tool in case of industries. We can test the working of circuit, take its DC

analysis, AC analysis, Transient Responses, Step Responses and Transient Single Shot

Responses etc.

TINA pro also offers us the various measure tools i.e. voltmeter, ampere meter, galvanometer,

multi-meter, oscilloscope etc. using these tools, we can view the voltage, current and other

respective values in the circuit. This will save the cost of the industry which may employ when

a circuit is burnt or damaged. We can test the working of the circuit, simulate it and then make

the final PCB of the circuit without any error. Also the reduction of errors are there in TINA

pro.

The simple circuit simulated in TINA pro is shown in the fig. below:

62

Page 63: A Aaaaaaaaaaaaaaa

63

Page 64: A Aaaaaaaaaaaaaaa

REFERENCE

Online Sources:

Google – http://encrypted.google.com

Wikipedia – http://www.wikipedia.com

Engineer garage – http://www.engineergarage.com

How Stuff Works – http://www.howstuffworks.com

Offline Sources:

MicroC Manuals

TINA Pro Help

PIC Datasheets

PIC Microcontrollers for Beginners

The Art of Electronics by Paul Horowitz & Winfield Hill

PIC Microcontroller & Embedded System by Muhammad Ali Mazidi

64