You are on page 1of 102

www.EmbeddedMarket.

com

Robot Controls using 8051

Presented by: Pratik Deshpande

www.EmbeddedMarket.com

Workshop Objective
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Understand the real world development using Microcontrollers Explore the features of microcontroller and use them in real life applications

Use 89V51RD2 microcontroller to control a Hobby Robot

www.EmbeddedMarket.com

Details of Workshop
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Your Basic Preparation Interface 8051 with various circuits Use built-in features of 8051 Apply above said learning to control a hobby robot This workshop is to learn the control techniques. Mechanical aspects will not be discussed.

www.EmbeddedMarket.com

Microcontroller & Computer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Basic Parts of a Computer Processor Hard disk RAM Monitor Keyboard Mouse Ports

www.EmbeddedMarket.com

Microcontroller & Digital Circuits


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Microcontroller has built in Processor Memory to Store Program Memory to Store Data Ports for Input & Outputs Flexible Multipurpose

www.EmbeddedMarket.com

Why to use a Microcontroller?


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Why use Microcontroller instead of PC? Why use Microcontroller instead of Digital Circuits?

www.EmbeddedMarket.com

Products using Microcontroller


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

www.EmbeddedMarket.com

Embedded Vs IT Sector
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Microcontroller is entry point to the Embedded Development Embedded is Hardware + Software IT is Software only Recent Global Economic downturn has less effect on Embedded Related companies
www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

You should know: Internals of microcontrollers Writing programs to create application Programming languages Bits , Bytes and Address Binary, Decimal & Hexadecimal Numbers Details of Interface (Input / Output circuits) Built-in Features of Microcontroller

www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

8051 Microcontroller AT89S51 AT89S52 P89V51RD2 Differs in Program memory Size Data Memory Size Certain built-in features

www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Internals of 89V51RD2 8 Bit processor 64 KB Flash (Memory to store program) 1 KB RAM (Memory to store data) Special Function Registers (SFR Used for Configuration of Built-in Features) 32 I/O Lines

www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Writing programs to create application


Assign value to a Port Read value from a Port Process input values Configure, Enable & disable Built-in Features

www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Programming languages For Microcontrollers


Human readable programming language
Assembly Language C Language Basic Language

Start:

JB P2.0,Start
JB P1.0,MakeItON SETB P1.0

Machine Code
Hex File

Assembler Software

:1000000020A0FD209004D2908002C290 30A0FD80FC :01001000EF00 :00000001FF www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Copy Hex File to Microcontroller


HEX File Programmer Device

www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Bits , Bytes and Address

MSB
1 0 1 0 1 0 1 0

LSB
Value 0th Bit 1 Byte
Binary = 10101010b Decimal = 170d Hexadecimal = AAh www.EmbeddedMarket.com

7th

Bit

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Bits , Bytes and Address 02d 2Ah 220d 122d

128 Byte RAM

07h 06h 05h 04h 03h 02h 01h 00h

25d
10111001b

22h
22d
www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Details of Interface

(Input / Output circuits)

LED Interfacing Seven Segment Interfacing Reading Input from Switch Display text to LCD Drive DC Motor using L293D Drive Stepper Motor using ULN2803 Driver Relay using ULN2803 Send text to PC using RS232 Serial Communication Transmit Infrared Receive Infrared Signal

www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Built-in Features of Microcontroller Timer Counter Serial Communication Interrupts

www.EmbeddedMarket.com

Lets get prepared


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

Flash memory & Data memory Program is written in Assembly Language Assembler software converts it to HEX file Hex File is downloaded to Microcontroller via Programming Device Hex File is Stored in Microcontrollers Flash memory Variables used by this program are stored in Microcontrollers Data memory (RAM)
www.EmbeddedMarket.com

www.DeccanRobots.com www.EmbeddedMarket.com

Time to See a Demo


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Running LEDs Seven Segment Display showing Numbers 0 to 9

www.EmbeddedMarket.com

Are you prepared now?


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

By now you know Difference between microcontroller, PC and digital circuit Internals of microcontrollers Writing programs to create application Programming languages Bits , Bytes and Address Binary, Decimal & Hexadecimal Numbers Details of Interface (Input / Output circuits) Built-in Features of Microcontroller You have seen one demo
www.EmbeddedMarket.com

www.DeccanRobots.com www.EmbeddedMarket.com

?
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Are you prepared to learn How to write a program in Assembly Language?

www.EmbeddedMarket.com

Assembly Language
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

We will learn (Limited Scope to fit available time) Assigning Byte values Assigning Bit values Logical Operations on Bytes Logical Operations on Bits Rotate Values Increment & Decrement Values Direct Jumps Conditional Jumps For Bytes Calls Conditional Jumps For Bits
www.EmbeddedMarket.com

www.DeccanRobots.com www.EmbeddedMarket.com

Assembly Language
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Assigning & Copy Byte values MOV R0, #55h MOV A, R0 MOV A, #55h MOV 90h, A MOV 90h, #33h

www.EmbeddedMarket.com

Assembly Language
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Assigning Bit values SETB 00h CLR 00h CPL 00h Copy Bit values MOV C, 00h MOV 00h, C

www.EmbeddedMarket.com

Assembly Language
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Logical operations on Byte ANL A, R0 ANL A, 90h ANL A, #55h ANL 90h, A ANL 90h, #55h Same format applies for ORL XRL
www.EmbeddedMarket.com

Assembly Language
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Logical Operations on Bits ANL C, 00h ORL C, 00h

www.EmbeddedMarket.com

Assembly Language
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Rotate Values RL A 10101100

RR A 10101100

www.EmbeddedMarket.com

Assembly Language
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Increment & Decrement values INC A INC R0 INC 00h DEC A DEC R0 DEC 00h

www.EmbeddedMarket.com

Assembly Language
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Following types of commands will be covered during further demos Direct Jumps Conditional Jumps For Bytes Calls Conditional Jumps For Bits

www.EmbeddedMarket.com

Why 89V51RD2?
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Reasons for selecting 89V51RD2 8051 compatible No expensive programmer device required Big Flash memory size to store large program hex Easily available

www.EmbeddedMarket.com

Free Gift & Purchase


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Register yourself to www.EmbeddedMarket.com Facebook.com/EmbeddedMarket

www.EmbeddedMarket.com

PCB Design & Manufacturing


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Email your schematics and get the price estimate for PCB Design & manufacturing Payment by DD Delivery by courier Delivery time 6-10 days Single & Double Side Designs Email ID: support@deccanrobots.com

www.EmbeddedMarket.com

Get, Set, Go
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Lets begin the real learning Its time to write your First program To Glow One LED
CLR P1.0

To Glow alternate 4 LEDs ON and 4 LEDs OFF


MOV P1, #55h

Refer next slide for LED circuit. How to write this code? Where to write this code? How to convert it to HEX?

www.EmbeddedMarket.com

Get, Set, Go
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

LED Circuit on 89V51RD2 Starter Kit

www.EmbeddedMarket.com

8051IDE & FlashMagic


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

4 1 89V51RD2 COM1 2400 2 Check this

Select Hex File Start After Hardware Setup is ready

www.EmbeddedMarket.com

89V51RD2 Starter Kit


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

2 1 4 8 5

12 10 9 11

www.EmbeddedMarket.com

89V51RD2 Starter Kit


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Connect Serial Cable

9-12V DC

Hardware Setup to Program


www.EmbeddedMarket.com

89V51RD2 Internals
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

64KB Flash memory 1KB Data RAM Special Function Registers 4 Ports

www.EmbeddedMarket.com

89V51RD2 Internals
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Internal Memory Organization

Configuration Registers, Port Registers, Maths registers

Memory from 00h to 07h is also termed as R0 to R7 www.EmbeddedMarket.com

Memory to Store values of variables. e.g. Count is 12

89V51RD2 Internals
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

List of Special Function Registers (SFR) Math A, B Interrupt IE Timer Control TMOD, TCON Timer / Counter TH0, TL0, TH1, TL1 Serial Communication SCON, SBUF PORT P0, P1, P2, P3

www.EmbeddedMarket.com

89V51RD2 Pin details


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

+5V

www.DeccanRobots.com www.EmbeddedMarket.com

P1

P0

P3

P2 Crystal GND www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Crystal 11.0592 MHz

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Crystal Frequency is 11.0592 MHz 1 Machine cycle = Crystal frequency/12 i.e. 12 clocks makes one machine cycle Machine cycle is time required to
Fetch instruction from Flash Memory + Execute the instruction

Every microcontroller has different Machine cycle time

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

How much time is require to fill this glass? Depends on Water Speed & Glass size

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

89V51RD2 has 3 Timers built-in They are Timer0, Timer1, Timer2 Lets use Timer0 to Generate a delay of approximate 1 second Timer0 is built-in feature of 89V51RD2 SFRs related to Timer0 are: TH0, TL0 (Call it as T0) TMOD TCON
www.EmbeddedMarket.com

www.DeccanRobots.com www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Special Function register TH0 and TL0 is like empty glass Combined size of TH0 and TL0 is 16 Bits i.e. T0 is of 16 bit size Now you know the size of empty Glass Next Task is to calculate the Time required to fill these 16bits.

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

1 Machine cycle Frequency =11.0592MHz /12 = 0.9216 MHz

T=1/ F T (Time required for 1 machine cycle) =1/0.9216 =1.0850694 =1.085 Micro Seconds (Round Off)

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

In other words we can say that with 11.0592 MHZ Crystal Connected, Timers value will increment every 1.085 micro seconds. T0 is of 16 bit size, thus it can store 65536 drops of water. T0 will take 65536 x 1.085= 71106.56 Micro Sec Or 71.10 MiliSec to overflow

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

If we want to count 1 second then we have to overflow timer approximately 14 times. Because 1 sec = 1000 mili sec 1000 / 71.1 =14.06 = 14 times approx

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Now lets configure the SFRs TMOD


Timer 1 7 6 5 4 3 Timer 0 2 1 0

Gate C/T M1 M0 Gate C/T M1 M0

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

TMOD register is divided into 2 identical parts. Bit M0 and M1 are used to set Mode of timer Bit C/T is used to specify if you want a timer or counter Gate Bit will allow you to use timer as stopwatch, i.e. timer will run only if externally a switch is pressed. Timer 1 7 6 5 4 3 Timer 0 2 1 0

Gate C/T M1 M0 Gate C/T M1 M0


www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

What will be value of TMOD to generate 1 Second delay? Gate = 0 (We dont want a stop watch) C/T = 0 (We want timer, not counter) M1=0 (*) M0=1 (*) * M1=0 and M0=1 configures the Timer1 as 16bit timer. Other settings are 13 bit timer, 8 Bit timer, Split Timer. The 16 bit timer mode is most suitable for our application.

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Now we have configured the Timer0 in 16bit timer mode We know that Timer0 must overflow 14 times to generate 1 second delay But how to Start the Timer?

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Use SFR named TCON to start timer TR0 is used to start and stop the Timer0 Lets see our partial code now
7 6 5 4 3 2 1 0

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Used for Timer Control
www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Partial Code to generate 1 Second delay MOV TMOD,#00000001b SETB TR0 Now how to monitor the 14 times overflow?

www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

TF0 is set to 1 automatically as T0 Overflows after 71.1 mili sec Thus we should count 14 such overflows by monitoring TF0. See full code on the next page
7 6 5 4 3 2 1 0

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Used for Timer Control
www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

Delay: MOV R0,#14d Configure TMOD MOV TMOD,#00000001b Tstart: Start Timer0 SETB TR0 Loop: Wait for one Overflow JNB TF0,Loop Clear Overflow CLR TF0 Stop Timer CLR TR0 Do it for 14 Times DJNZ R0,Tstart RET
www.EmbeddedMarket.com

www.DeccanRobots.com www.EmbeddedMarket.com

Generate Delay using Timer


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

SETB P1.0 Start: LCALL Delay CPL P1.0 SJMP Start


Delay: MOV R0,#14d MOV TMOD,#00000001b Tstart: SETB TR0 Loop: JNB TF0,Loop CLR TF0 CLR TR0 DJNZ R0,Tstart RET

www.EmbeddedMarket.com

Read Switch Input


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

www.EmbeddedMarket.com

Read Switch Input


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

MOV P2,#00h Start: JB P1.0,Start CPL P2.0 Wait: JNB P1.0,Wait Sjmp Start

www.EmbeddedMarket.com

DC Motor Control
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Try connecting DC Motor here

+ H H
OFF

H L
CLK

L L

ANTI OFF CLK

- +

Lets now control it using 89V51RD2 Microcontroller www.EmbeddedMarket.com

DC Motor Control
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

L293D DC Motor Driver Circuit

www.EmbeddedMarket.com

DC Motor Control
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Refer source Code

www.EmbeddedMarket.com

Seven Segment Display


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

www.EmbeddedMarket.com

Seven Segment Display


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Board mapping on the next screen. Refer source code

8 9 V 5 1 R D 2
www.EmbeddedMarket.com

Seven Segment Display


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

www.EmbeddedMarket.com

Stepper Motor Driver


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

Demonstrated using MITSUMI Make Stepper Motor M35SP-8 Step Angle 7.5o Thus requires 360/7.5 = 48 Steps to complete one full rotation. Stepper motors are used for their accuracy. Stepper motors have no Speed or RPM parameter Most common use is in CNC machines
www.EmbeddedMarket.com

www.DeccanRobots.com www.EmbeddedMarket.com

Stepper Motor Driver


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

+V

B1

A1

B1

A1
www.EmbeddedMarket.com

Stepper Motor Driver


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

+V

A
ON

B1

OFF

ON

B
A B A1 B1

OFF

A1
1 www.EmbeddedMarket.com1 0 0

Stepper Motor Driver


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

+V

A
OFF

B1

OFF

ON

B
A B A1 B1

ON

A1
0 www.EmbeddedMarket.com1 1 0

Stepper Motor Driver


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

+V

A
OFF

B1

ON

OFF

B
A B A1 B1

ON

A1
0 www.EmbeddedMarket.com0 1 1

Stepper Motor Driver


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

+V

A
ON

B1

ON

OFF

B
A B A1 B1

OFF

A1
1 www.EmbeddedMarket.com0 0 1

Stepper Motor Driver


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

VCC

www.EmbeddedMarket.com

Stepper Motor Driver


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Refer Source code

www.EmbeddedMarket.com

Interrupts
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

www.EmbeddedMarket.com

Interrupts
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

An interrupt is some event which interrupts normal program execution


Normal Program Running | Interrupt Received | Normal Program Halted | Sub-Routine Executed as expected by the Interrupt | Normal Program Continues
www.EmbeddedMarket.com

Interrupts
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

This subroutine, called an interrupt handler, is only executed when a certain event (interrupt) occurs. Types of interrupts Timer 0 Overflow. Timer 1 Overflow. Timer 2 Overflow Reception/Transmission of Serial Character. External Event 0. External Event 1.

www.EmbeddedMarket.com

External Interrupt
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

This subroutine must be written at specific flash memory address.


External 0 at Program memory address 0003h External 1 at Program memory address 0013h Timer 0 at Program memory address 000Bh Timer 1 at Program memory address 001Bh Serial Tx/Rx at Program memory address 0023h

www.EmbeddedMarket.com

External Interrupt
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

How to Enable Interrupt


7 EA 6 5 4 3 2 1 0

ES ET1 EX1 ET0 EX0

IE

EA: All interrupt enable ES: Enable Serial Interrupt ET1: Enable Timer 1 Interrupt EX1: Enable External 1 Interrupt ET0: Enable Timer 0 Interrupt

EX0: Enable External 0 Interrupt


www.EmbeddedMarket.com

External Interrupt
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Refer Source Code

P3.2

www.EmbeddedMarket.com

Counter
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

TMOD
Timer 1

MOV TMOD,#00000101b

Timer 0

P3.4

Gate C/T M1 M0 Gate C/T M1 M0

TCON
SETB TR0

7 6 5 4 3 2 1 0 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Used for Timer Control

www.EmbeddedMarket.com

Counter
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

start:

MOV TMOD,#00000101b
SETB TR0

Loop:
MOV P2,TL0

SJMP Loop

www.EmbeddedMarket.com

Relay Interfacing
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

+V
N/C C N/O

Use a Switch to ON & Off Relay, Observe the Tick sound generated when Relays magnet is energized

www.EmbeddedMarket.com

Relay Interfacing
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

230V Ph

www.DeccanRobots.com www.EmbeddedMarket.com

+V
N/C C N/O

www.EmbeddedMarket.com

LCD Interfacing
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

LCD Circuit

www.EmbeddedMarket.com

LCD Interfacing
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

www.EmbeddedMarket.com

TSOP1738 RC5 Remote


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

38KHZ Industrial Grade IR receiver

www.EmbeddedMarket.com

TSOP1738 RC5 Remote


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

www.EmbeddedMarket.com

TSOP1738 RC5 Remote


Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Refer Source Code

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Use RS232 to communicate between a PC and embedded product Data logger is common example of it

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Rx & Tx Pins

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Steps to Communicate Both devices (PC & embedded product) must decide on common speed of communication, This speed is called as baud rate We will use 2400 baud rate i.e. 2400 bits per second

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

SFRs required for Serial Comunication SCON PCON SBUF TMOD Baud rate settings TCON TL1 TH1

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

SCON register is used to specify RS232 communication settings:


7 6 5 4 3 2 1 0

SM0SM1SM2REN TB8 RB8 TI


Mode of RS232

RI
Indicates that Data is received

I want to receive data over RS232

Indicates that Data is transmitted

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Mode of serial communication


SM0 0 0 1 1 SM1 0 1 0 1 Serial Mode 0 1 2 3 Explanation 8-bit Shift Register 8-bit UART 9-bit UART 9-bit UART Baud Rate Oscillator / 12 Set by Timer 1 Oscillator / 32 Set by Timer 1

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Baud rate = 2400. Mode type = Mode 1 of serial communication. In this mode we can send and receive 8 bit data. Baud rate to send this data can be set using Timer 1.

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Timer 1 is used in 8-bit auto reload mode to generate required BAUD rate. We can not use Timer 0. There no such internal provision to do so

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Lets understand Timer 1 Configurations:


TMOD = 00100000b (8-bit auto reload mode) In 8 bit auto-reload mode, Timer 1 acts as 8 bit and not 16 bits. 8 bits of TL1 are used to increment timer value. 8 bits of TH1 are used to tell TL1 to start incrementing again from this value as it overflows. This is called as auto-reload.

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

This re-load value for TH1 will be calculated using this formula: TH1 = 256 - ((Crystal / 384) / Baud) TH1 = 256 - ((11059000 / 384) / 2400 ) TH1 = 256 - ((28,799) /2400) TH1 = 256 11.99 = 244.00042= =244d

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

TMOD = 00100000b (8-bit auto reload mode)

TH1= 244d (as per formula)


Remember to make 7th bit of PCON register to 0. If it is set to 1 then speed will be doubled. This bit is also called as SMOD.

www.EmbeddedMarket.com

RS232
Microcontroller, Arduino & Embedded Kits available at EmbeddedMarket.com Microcontroller Kits Available at www.DeccanRobots.com

www.DeccanRobots.com www.EmbeddedMarket.com

Refer Source Code

www.EmbeddedMarket.com

You might also like