Microcontroller 8051
Training
-Pradip Bhandari
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 1
I assume every body is familiar with Basic C programming
Everybody is well known about basic Digital gates
Everybody knows Number Systems
Everybody has concept of basic electronics including RAM and
ROM memory
And all are expert in using computer
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 2
Contents
 Introduction
 Block Diagram and Pin Description of the 8051
 Environment setup (Proteus and Keil)
 Introduction to Proteus
 Simple LED Blink
 DEMO
 LCD Programming
 DEMO
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 3
Introduction
Microcontroller
• CPU, RAM, ROM, I/O and timer are all on a single chip
• fix amount of on-chip ROM, RAM, I/O ports
• for applications in which cost, power and space are critical
• single-purpose
RAM ROM
I/O
Port
Timer
Serial
COM
Port
Microcontroller
CPU
A single chip
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 4
Block Diagram
CPU
On-chip
RAM
On-chip
ROM for
program
code
4 I/O Ports
Timer 0
Serial
PortOSC
Interrupt
Control
External interrupts
Timer 1
Timer/Counter
Bus
Control
TxD RxDP0 P1 P2 P3
Address/Data
Counter
Inputs
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 5
Feature 8051 8052 8031
ROM (program space in bytes) 4K 8K 0K
RAM (bytes) 128 256 128
Timers 2 3 2
I/O pins 32 32 32
Serial port 1 1 1
Interrupt sources 6 8 6
Features and Comparison 8051
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 6
Pin Description of the 8051
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
RST
(RXD)P3.0
(TXD)P3.1
(T0)P3.4
(T1)P3.5
XTAL2
XTAL1
GND
(INT0)P3.2
(INT1)P3.3
(RD)P3.7
(WR)P3.6
Vcc
P0.0(AD0)
P0.1(AD1)
P0.2(AD2)
P0.3(AD3)
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A14)
P2.5(A13)
P2.4(A12)
P2.3(A11)
P2.2(A10)
P2.1(A9)
P2.0(A8)
8051
(8031)
PORT 0
PORT 2
PORT 1
PORT 3
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 7
Pins of 8051(1/4)
• Vcc(pin 40):
• Vcc provides supply voltage to the chip.
• The voltage source is +5V.
• GND(pin 20):ground
• XTAL1 and XTAL2(pins 19,18):
• These 2 pins provide external clock.
• Way 1:using a quartz crystal oscillator
• Way 2:using a TTL oscillator
• Example 4-1 shows the relationship between XTAL and the
machine cycle.
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 8
XTAL Connection to 8051
C2
30pF
C1
30pF
XTAL2
XTAL1
GND
• Using a quartz crystal oscillator
• We can observe the frequency on the XTAL2 pin.
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 9
XTAL Connection to an External Clock
Source
N
C
EXTERNAL
OSCILLATOR
SIGNAL
XTAL2
XTAL1
GND
• Using a TTL oscillator
• XTAL2 is unconnected.
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 10
Pins of 8051(2/4)
• RST(pin 9):reset
• It is an input pin and is active high(normally low).
• The high pulse must be high at least 2 machine cycles.
• It is a power-on reset.
• Upon applying a high pulse to RST, the microcontroller will
reset and all values in registers will be lost.
• Reset values of some 8051 registers
• Way 1:Power-on reset circuit
• Way 2:Power-on reset with debounce
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 11
Power-On RESET Circuit
30 pF
30 pF
8.2 K
10 uF
+
Vcc
11.0592 MHz
EA/VPP
X1
X2
RST
31
19
18
9
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 12
Power-On RESET with Debounce
EA/VPP
X1
X2
RST
Vcc
10 uF
8.2 K
30 pF
9
31
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 13
Pins of 8051(3/4)
• /EA(pin 31):external access
• There is no on-chip ROM in 8031 and 8032 .
• The /EA pin is connected to GND to indicate the code is stored externally.
• /PSEN & ALE are used for external ROM.
• For 8051, /EA pin is connected to Vcc.
• “/” means active low.
• /PSEN(pin 29):program store enable
• This is an output pin and is connected to the OE pin of the ROM.
• See Chapter 14.
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 14
Pins of 8051(4/4)
• ALE(pin 30):address latch enable
• It is an output pin and is active high.
• 8051 port 0 provides both address and data.
• The ALE pin is used for de-multiplexing the
address and data by connecting to the G
pin of the 74LS373 latch.
• I/O port pins
• The four ports P0, P1, P2, and P3.
• Each port uses 8 pins.
• All I/O pins are bi-directional.
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 15
Pins of I/O Port
• The 8051 has four I/O ports
• Port 0 (pins 32-39):P0(P0.0~P0.7)Bit address (0x80~0x87)
• Port 1(pins 1-8) :P1(P1.0~P1.7) Bit address (0x90~0x97)
• Port 2(pins 21-28):P2(P2.0~P2.7) Bit address (0xA0~0xA7)
• Port 3(pins 10-17):P3(P3.0~P3.7) Bit address (0xB0~0xB7)
• Each port has 8 pins.
• Named P0.X (X=0,1,...,7), P1.X, P2.X, P3.X
• Ex:P0.0 is the bit 0(LSB)of P0
• Ex:P0.7 is the bit 7(MSB)of P0
• These 8 bits form a byte.
• Each port can be used as input or output (bi-direction).

Tuesday, July 14, 2015 Robotics Club, IOE, WRC 16
PORT P0 (PIN 39 TO 32)
Port P0 has got three functionalities.(I/O port, lower order address(A0 to A7)
and data (D0 to D7).
It can be used for input or output , each pin must be connected externally to a
10K ohm pull-up resistor.
ALE indicates if P0 has address or data
When ALE=0, it provides data D0-D7
When ALE=1, it has address A0-A7
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 17
Pull Up Resistor
• Pull-up resistor pulls the voltage of the signal it is connected to
towards its voltage source level
• Pull-up resistor ensures that the wire is at a defined logic level even if
no active devices are connected to it
• At reset condition the port zero will be at floating
condition ,i.e no 0 no 1 something other
state which we cannot predict so to ensure
proper logic level we use Pull-up resistor
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 18
PORT P1 (PIN 1 TO 8)
Port P1 is simple I/O port .
Internal pull up resistor is provided.
PORT P2(PIN 21 TO 28)
Port P2 has dual functionality.( I/o port and higher order address(A8
to A15)
Port 2 must be used along with P0 to provide the 16-bit address for
the external memory.
 Internal pull up resistor is provided.
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 19
PORT P3 (PIN 10 TO 17)
Port 3 can be used as input or output.
Port 3 does not need any pull-up resistors.
Port 3 has the additional function of providing some extremely important
signals.
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 20
Environment Setup
Proteus Installation (Proteus 8.1 SP1)(Recommend to use latest version)
 1. Exact the provided package
 2. Open LICENSE.EXE
 3. Change the attribute of Key.lxk to no hidden and no readonly
 4. Browse for key -> Select Key.lxk
 5. Install key
 6. Close LICENSE.EXE
 7. Install Proteus 8.1 SP1.exe
 8. Do not run after installation
 9. Copy "BIN" To Installation Folder (C:Program Files (x86)Labcenter ElectronicsProteus 8 Professional)
 10. Copy "MODELS" To ProgramData (C:ProgramDataLabcenter ElectronicsProteus 8 Professional)
 11. Run Proteus and enjoy!
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 21
Keil Installation
• I recommend to use latest version of keil(version 4 for 51)
• Install the Provided Keil software(trial version or cracked )
• Provide the basic information
• Done
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 22
Proteus
Isis should be highlighted (Clickable)
Click it to open to initiate design
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 23
1
2
3
1. Component mode, Click here
to enable Component mode
so that we can browse any
basic component from 2(pick
device)
2. Pick Device, Click here to pick
any require component into
our workspace
3. Terminal Nodes, terminal
nodes like Ground, Power
source etc is available over
here
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 24
Create a basic Led Blink Circuit
1
2
1. Click Component mode 3. Type at89c52
2. Click pick device 4. Select the first one
3
4
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 25
Pick the LED
1
2
3
4
1. Type Keyword led
2. Select Optoelectronics in Category
3. Select LEDs in sub-category
4. Select LED-RED or LED-GREEn or LED-
BLUE in Results
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 26
Led blink circuit
1. Pick At89c52
microcontroller from
device selector
2. Also pick led as shown in
figure and wire them
3. Pick a ground from
terminal nodes
4. Zoom the workspace as
per your easiness
5. Now save your work and
give it a name Blink
6. Now its time to write
program in keil
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 27
LED blink Program in Keil using C
1. Open keil
2. Goto Project>New uvision Project> give it a name as Blink (file
extension not needed)and save it
3. From CPU Database select Atmel > AT89C52 press ok and click No
to not to copy start up files
4. Goto file menu and select new(or press ctrl + N)
5. Save it as Blink.c (don’t forget to include file extension as .c)
6. Under project > Target 1 > Source group 1 add Blink.c (double click
Source group 1 to add blink.c)
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 28
Creating HEX file
6. Under Flash menu goto Configure Flash Tools…
7. 1
2
3
4
5
1. Select Target
2. Enter Xtal value as 12.0
3. Check Use On-chip ROM
4. Select Output
5. Check Create HEX File
Click OK
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 29
Simple LED BLINk.C
#include<reg51.h>
sbit out = P2^0;
void msdelay(unsigned int);
void main()
{
while(1)
{
out=1;
msdelay(500);
out=0;
msdelay(500);
}
}
void msdelay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<=time;i++)
for(j=0;j<=1275;j++);
}
1.To Address Port we use sfr or #define keyword
sfr ldata = P1; // P must be Capital
sfr ldata = 0x90;
#define ldata P1 // no equals to, no semicolon
2. To Address A single bit of a Port we use sbit keyword
sbit out = P2^0; // it indicates P2.0
sbit enable = P2^1; // P must be Capital
sbit buttonChech = P2^2;
3. At initial stage or at reset condition the output of
each port or port bit(pin) will be 1(high)
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 30
Compile and Build
1
2
3
1. Make a Habit to save your
work all the time, press
(Ctrl+S) to save
2. Compile or Translate, Click it
to compile your code to
check errors and
warning(Ctrl+f7)
3. Press Build or Rebuild to
generate HEX file
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 31
Uploading HEX File
1
2
3
1. Double Click at Microcontroller
AT89C52 to open Edit
Component Dialog Box
2. Browse for HEX file that you
created earlier
3. Press Ok
4. Run Your Simulation
4
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 32
DEMO
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 33
To make a port or single pin as an input we need to declare it as HIGH or 1
#include<reg51.h>
sbit out = P2^0;
sbit in = P2^1;
void msdelay(unsigned int);
void main()
{
in = 1;
P2=0;
while(1)
{
if( in == 1){
out=1;
}
else {
out=0;
}
}
}
void msdelay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<=time;i++)
for(j=0;j<=1275;j++);
}
Search Button in
Component search box
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 34
Liquid Crystal Display (LCD):-
LCD is finding widespread use replacing LEDs because
 The declining prices of LCD
 The ability to display numbers, characters and graphics
Ease of programming for characters and graphics
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 35
Pin Descriptions for LCD
Pin Symbol I/O Descriptions
1 VSS ----- Ground
2 VCC ----- +5 v power supply
3 VEE ----- Power supply to contrast
4 RS I Register Select( 0 for command register and 1
for data register)
5 __
R /W
I 1 for Read
0 for write
6 E I/O Enable
7-14 DB0-DB7 I/O The 8-bit data bus
15 LED + ----- Usually Connected t0 +5v of power supply
16 LED- ----- Connected to Ground
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 36
Instruction VS Data
• Instruction Register (IR) and Data Register (DR)
• Instruction is a Command, Data is a displaying Value
• There are two 8-bit registers in Our LCD controller IC, Instruction and
Data register. Instruction register corresponds to the register where
you send commands to LCD e.g LCD shift command, LCD clear, LCD
address etc. and Data register is used for storing data which is to be
displayed on LCD.
• Only the instruction register (IR) and the data register (DR) of the LCD
can be controlled by our 8051 microcontroller
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 37
LCD PROTEUS SIMULATION
1.Lcd is named as LM016L in Component
Mode Pick Device i.e Library
2. Connect P2.0~P2.7 of microcontroller to
D0~D7 of LCD respectively
3. Connect P3.0 to RS, P3.1 to RW and P3.2
to E
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 38
Before using the LCD for display purpose, LCD has to be initialized either
by the internal reset circuit or sending set of commands to initialize the
LCD. It is the user who has to decide whether an LCD has to be initialized
by instructions or by internal reset circuit. we will dicuss both ways of
initialization one by one.
We need to initialize LCD to define type of LCD, Cursor Position, Home
Location etc
Type includes like 16x2 or 14x1 or 20x2 etc
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 39
Some Points to note while Programming
A high to low pulse should be provided in an enable pin for Write
Operation
A low to high pulse should be provided in an enable pin for Read
Operation
Bit D7 of LCD is busy flag which can be used to check if LCD is busy in its
own internal operation
Busy flag can be read when R/W =1 and RS=0 and a L to H pulse in enable
pin
NOTE:- It is recommended to check busy flag before writing any data to LCD.
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 40
LCD BUSY CHECK (BF-FLAG)
• Busy Flag is an status indicator flag for LCD. When we send a
command or data to the LCD for processing, this flag is set (i.e BF =1)
and as soon as the instruction is executed successfully this flag is
cleared (BF = 0). This is helpful in producing and exact amount of
delay. for the LCD processing.
• To read Busy Flag, the condition RS = 0 and R/W = 1 must be met and
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.
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 41
BUSY CHECK
void lcdbusy()
{
busy=1; // declaring D7 of LCD as input to check busy flag
rw=1;
rs=0;
while(busy==1)
{
en=0;
msdelay(1);
en=1;
}
return;
}
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 42
Sending Command To LCD
void lcdcmd(unsigned char value)
{
lcdbusy(); //Wait for LCD to process the command
ldata=value; //Function set: 2 Line, 8-bit, 5x7 dots
rs=0; //Selected command register
rw=0; //We are writing in instruction register
en=1; //Enable H->L
msdelay(1);
en=0; //Enable H->L
return;
}
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 43
LCD Command Codes
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 44
Sending Data To LCD
void lcddata(unsigned char value)
{
lcdbusy(); //Wait for LCD to process the command
ldata=value; //Function set: 2 Line, 8-bit, 5x7 dots
rs=1; //Selected data register
rw=0; //We are writing in data register
en=1; //Enable H->L
msdelay(1);
en=0; //Enable H->L
return;
}
// we will pass the character to display as argument to function
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 45
Sending String Data To LCD
void lcdstr(unsigned char msg[15]) //to print string in lcd
{
unsigned char i=0;
while(msg[i]!='$')
{
if(i>16)
{
msdelay(10);
lcdcmd(0x07); //shift display to left
}
if(msg[i]==' ')
msdelay(50);
if(i==15)
lcdcmd(0x07);
lcddata(msg[i]);
i++;
}
}Tuesday, July 14, 2015 Robotics Club, IOE, WRC 46
SELECTING FIRST AND SECOND ROW
void lcdfirst()
{
lcdcmd(0x38);
lcdcmd(0x0e);
msdelay(50);
lcdcmd(0x01);// clear
lcdcmd(0x06);
lcdcmd(0x80);
}
void lcdsecond()
{
lcdcmd(0x38);
lcdcmd(0x0e);
msdelay(50);
lcdcmd(0x06);
lcdcmd(0xc0);
}
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 47
OVERALL PROGRAM FOR LCD
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 48
#include<reg51.h>
#define ldata P2 //lcd data
sbit rs=P3^0; //lcd signals
sbit rw=P3^1;
sbit en=P3^2;
sbit busy=P2^7;
void lcdbusy(); //to check if lcd is busy or not
void lcdcmd(unsigned char) ; // to give lcd commands
void lcddata(unsigned char); //to give data to the lcd
void lcdfirst(); // first line of lcd initialization
void lcdsecond(); // second line of lcd initialization
void lcdstr(unsigned char[]); // to display string
void msdelay (unsigned char);
void main()
{
P2=0;
P3=0;
while(1)
{
lcdfirst();
lcdstr("Hello");
msdelay(1000);
lcdsecond();
lcdstr("Pokhara1");
msdelay(1000);
}
}
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 49
void msdelay(unsigned char time)
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<=1275;j++);
}
void lcdbusy()
{
busy=1;
rw=1;
rs=0;
while(busy==1)
{
en=0;
msdelay(1);
en=1;
}
return;
}
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 50
void lcdcmd(unsigned char value)
{
lcdbusy();
ldata=value;
rs=0;
rw=0;
en=1;
msdelay(1);
en=0;
return;
}
void lcddata(unsigned char value)
{
lcdbusy();
ldata=value;
rs=1;
rw=0;
en=1;
msdelay(1);
en=0;
return;
}
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 51
void lcdfirst()
{
lcdcmd(0x38); //2 lines and 5x7 matrix
lcdcmd(0x0e);
msdelay(50); //cursor blink
lcdcmd(0x01); //clear display screen
lcdcmd(0x06); //shift cursor to right
lcdcmd(0x80);
}
void lcdsecond()
{
lcdcmd(0x38); //2 lines and 5x7 matrix
lcdcmd(0x0e);
msdelay(50); //cursor blink
lcdcmd(0x06); //shift cursor to right
lcdcmd(0xc0);
}
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 52
void lcdstr(unsigned char msg[]) //to print string in lcd
{
unsigned char i=0;
while(msg[i]!='0')
{
if(i>16)
{
msdelay(10);
lcdcmd(0x07);
}
if(msg[i]==' ')
msdelay(50);
if(i==15)
lcdcmd(0x07);
lcddata(msg[i]);
i++;
}
}
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 53
ANY QUESTION?
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 54

More Related Content

PPT
8051 microcontroller
PPTX
8051 microprocessor
PDF
1 8051 microcontroller intr
PPT
8051
PPTX
Microcontroller ppt
PPTX
Presentation On: "Micro-controller 8051 & Embedded System"
PPT
Microcontroller 8051
PDF
Microprocessor 8051
8051 microcontroller
8051 microprocessor
1 8051 microcontroller intr
8051
Microcontroller ppt
Presentation On: "Micro-controller 8051 & Embedded System"
Microcontroller 8051
Microprocessor 8051

What's hot (20)

PPTX
8051 Microcontroller
PPTX
8051 Microcontroller ppt
PDF
Microcontroller 8051 basics (part I)
PPTX
8051 microcontroller
PPTX
8051 Microcontroller
PDF
Lecture SOHIL LUHAR
PPT
8051 MICROCONTROLLER
PDF
8051 microcontroller
PPT
Microcontroller 8051
PPT
8051 Microcontroller
PPTX
Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
PPT
Microcontroller 8051
PPTX
Architecture of the Intel 8051 Microcontroller
PPT
Microcontroller 8051
PPTX
8051 presentation
PPT
Embedded systems, 8051 microcontroller
PDF
MICROCONTROLLER - INTEL 8051
DOCX
Study of 8051 microcontroller
PPTX
Unit iv introduction to 8051 microcontroller ppts
8051 Microcontroller
8051 Microcontroller ppt
Microcontroller 8051 basics (part I)
8051 microcontroller
8051 Microcontroller
Lecture SOHIL LUHAR
8051 MICROCONTROLLER
8051 microcontroller
Microcontroller 8051
8051 Microcontroller
Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Microcontroller 8051
Architecture of the Intel 8051 Microcontroller
Microcontroller 8051
8051 presentation
Embedded systems, 8051 microcontroller
MICROCONTROLLER - INTEL 8051
Study of 8051 microcontroller
Unit iv introduction to 8051 microcontroller ppts
Ad

Viewers also liked (6)

PDF
What is POR,LVD,WDT ?
PDF
High Speed, Low Offset, Low Power, Fully Dynamic Cmos Latched Comparator
PDF
8051 smd kit_manual
PPTX
Embedded system 8051 Microcontroller
PDF
Embedded c programming guide e book atmel 8051 / 89c51 /89c52
PPSX
Programming ATmega microcontroller using Embedded C
What is POR,LVD,WDT ?
High Speed, Low Offset, Low Power, Fully Dynamic Cmos Latched Comparator
8051 smd kit_manual
Embedded system 8051 Microcontroller
Embedded c programming guide e book atmel 8051 / 89c51 /89c52
Programming ATmega microcontroller using Embedded C
Ad

Similar to Microcontroller 8051 training (20)

DOC
Gesture based vehicle movements control and alerting system docu
PDF
Atmega tutorial
PDF
Microcontroladores: Programación con microcontrolador PIC
PDF
Programming with PIC microcontroller
PPT
Picmico
PPT
Microcontroller 8051 gs
PPT
Microcontroller 8051 1
PDF
Ht usb5130-v2
PPT
4221-Microcontroller-8051 89c52 51-1.ppt
PPTX
fdgfgsdfhgdfhdhdgjgjfjdfhsdfharyerygardh.pptx
PDF
Pic microcontroller step by step your complete guide
PPT
13223971.ppt
PPTX
8051 microcontroller
PDF
Larson and toubro
PPTX
Micro c lab2(led patterns)
PPT
Microcontroller 8051
PPT
8051 Microcontroller architecture and operation
PPTX
G9-Robotics-Lessons. pptx..............o
PPTX
3-8051 Microcontroller-28-01-2024 (1).pptx
PPT
Microcontroller 8051 By Mitesh kumar
Gesture based vehicle movements control and alerting system docu
Atmega tutorial
Microcontroladores: Programación con microcontrolador PIC
Programming with PIC microcontroller
Picmico
Microcontroller 8051 gs
Microcontroller 8051 1
Ht usb5130-v2
4221-Microcontroller-8051 89c52 51-1.ppt
fdgfgsdfhgdfhdhdgjgjfjdfhsdfharyerygardh.pptx
Pic microcontroller step by step your complete guide
13223971.ppt
8051 microcontroller
Larson and toubro
Micro c lab2(led patterns)
Microcontroller 8051
8051 Microcontroller architecture and operation
G9-Robotics-Lessons. pptx..............o
3-8051 Microcontroller-28-01-2024 (1).pptx
Microcontroller 8051 By Mitesh kumar

Recently uploaded (20)

PDF
2- Physical Layer (06).pdfgshshshbsbshshshhs
PDF
Tcl Scripting for EDA.pdf
PPTX
Group 4 [BSIT-1C] Computer Network (1).pptx
PDF
SAHIL PROdhdjejss yo yo pdf TOCOL PPT.pdf
PPTX
New professional education PROF-ED-7_103359.pptx
PPTX
Pin configuration and project related to
PPTX
AIR BAG SYStYEM mechanical enginweering.pptx
PPTX
Growth Capital Investment - Espresso Capital.pptx
PDF
20A LG INR18650HJ2 3.6V 2900mAh Battery cells for Power Tools Vacuum Cleaner
PPTX
AI_ML_Internship_WReport_Template_v2.pptx
PDF
2_STM32&SecureElements2_STM32&SecureElements
PPTX
RTS MASTER DECK_Household Convergence Scorecards. Use this file copy.pptx
PPTX
ELETRONIC-PRODUCTS-ASSEMBLY-AND-SERVICING-NC-II-WEEK-1-Copy.pptx
PPTX
unit1d-communitypharmacy-240815170017-d032dce8.pptx
PDF
Topic-1-Main-Features-of-Data-Processing.pdf
PPTX
Subordinate_Clauses_BlueGradient_Optimized.pptx
PPTX
Clauses_Part1.hshshpjzjxnznxnxnndndndndndndndnndptx
PPT
System Unit Components and its Functions
PPTX
Chapter no 8 output devices dpart 2.pptx
PPTX
vortex flow measurement in instrumentation
2- Physical Layer (06).pdfgshshshbsbshshshhs
Tcl Scripting for EDA.pdf
Group 4 [BSIT-1C] Computer Network (1).pptx
SAHIL PROdhdjejss yo yo pdf TOCOL PPT.pdf
New professional education PROF-ED-7_103359.pptx
Pin configuration and project related to
AIR BAG SYStYEM mechanical enginweering.pptx
Growth Capital Investment - Espresso Capital.pptx
20A LG INR18650HJ2 3.6V 2900mAh Battery cells for Power Tools Vacuum Cleaner
AI_ML_Internship_WReport_Template_v2.pptx
2_STM32&SecureElements2_STM32&SecureElements
RTS MASTER DECK_Household Convergence Scorecards. Use this file copy.pptx
ELETRONIC-PRODUCTS-ASSEMBLY-AND-SERVICING-NC-II-WEEK-1-Copy.pptx
unit1d-communitypharmacy-240815170017-d032dce8.pptx
Topic-1-Main-Features-of-Data-Processing.pdf
Subordinate_Clauses_BlueGradient_Optimized.pptx
Clauses_Part1.hshshpjzjxnznxnxnndndndndndndndnndptx
System Unit Components and its Functions
Chapter no 8 output devices dpart 2.pptx
vortex flow measurement in instrumentation

Microcontroller 8051 training

  • 1. Microcontroller 8051 Training -Pradip Bhandari Tuesday, July 14, 2015 Robotics Club, IOE, WRC 1
  • 2. I assume every body is familiar with Basic C programming Everybody is well known about basic Digital gates Everybody knows Number Systems Everybody has concept of basic electronics including RAM and ROM memory And all are expert in using computer Tuesday, July 14, 2015 Robotics Club, IOE, WRC 2
  • 3. Contents  Introduction  Block Diagram and Pin Description of the 8051  Environment setup (Proteus and Keil)  Introduction to Proteus  Simple LED Blink  DEMO  LCD Programming  DEMO Tuesday, July 14, 2015 Robotics Club, IOE, WRC 3
  • 4. Introduction Microcontroller • CPU, RAM, ROM, I/O and timer are all on a single chip • fix amount of on-chip ROM, RAM, I/O ports • for applications in which cost, power and space are critical • single-purpose RAM ROM I/O Port Timer Serial COM Port Microcontroller CPU A single chip Tuesday, July 14, 2015 Robotics Club, IOE, WRC 4
  • 5. Block Diagram CPU On-chip RAM On-chip ROM for program code 4 I/O Ports Timer 0 Serial PortOSC Interrupt Control External interrupts Timer 1 Timer/Counter Bus Control TxD RxDP0 P1 P2 P3 Address/Data Counter Inputs Tuesday, July 14, 2015 Robotics Club, IOE, WRC 5
  • 6. Feature 8051 8052 8031 ROM (program space in bytes) 4K 8K 0K RAM (bytes) 128 256 128 Timers 2 3 2 I/O pins 32 32 32 Serial port 1 1 1 Interrupt sources 6 8 6 Features and Comparison 8051 Tuesday, July 14, 2015 Robotics Club, IOE, WRC 6
  • 7. Pin Description of the 8051 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 RST (RXD)P3.0 (TXD)P3.1 (T0)P3.4 (T1)P3.5 XTAL2 XTAL1 GND (INT0)P3.2 (INT1)P3.3 (RD)P3.7 (WR)P3.6 Vcc P0.0(AD0) P0.1(AD1) P0.2(AD2) P0.3(AD3) P0.4(AD4) P0.5(AD5) P0.6(AD6) P0.7(AD7) EA/VPP ALE/PROG PSEN P2.7(A15) P2.6(A14) P2.5(A13) P2.4(A12) P2.3(A11) P2.2(A10) P2.1(A9) P2.0(A8) 8051 (8031) PORT 0 PORT 2 PORT 1 PORT 3 Tuesday, July 14, 2015 Robotics Club, IOE, WRC 7
  • 8. Pins of 8051(1/4) • Vcc(pin 40): • Vcc provides supply voltage to the chip. • The voltage source is +5V. • GND(pin 20):ground • XTAL1 and XTAL2(pins 19,18): • These 2 pins provide external clock. • Way 1:using a quartz crystal oscillator • Way 2:using a TTL oscillator • Example 4-1 shows the relationship between XTAL and the machine cycle. Tuesday, July 14, 2015 Robotics Club, IOE, WRC 8
  • 9. XTAL Connection to 8051 C2 30pF C1 30pF XTAL2 XTAL1 GND • Using a quartz crystal oscillator • We can observe the frequency on the XTAL2 pin. Tuesday, July 14, 2015 Robotics Club, IOE, WRC 9
  • 10. XTAL Connection to an External Clock Source N C EXTERNAL OSCILLATOR SIGNAL XTAL2 XTAL1 GND • Using a TTL oscillator • XTAL2 is unconnected. Tuesday, July 14, 2015 Robotics Club, IOE, WRC 10
  • 11. Pins of 8051(2/4) • RST(pin 9):reset • It is an input pin and is active high(normally low). • The high pulse must be high at least 2 machine cycles. • It is a power-on reset. • Upon applying a high pulse to RST, the microcontroller will reset and all values in registers will be lost. • Reset values of some 8051 registers • Way 1:Power-on reset circuit • Way 2:Power-on reset with debounce Tuesday, July 14, 2015 Robotics Club, IOE, WRC 11
  • 12. Power-On RESET Circuit 30 pF 30 pF 8.2 K 10 uF + Vcc 11.0592 MHz EA/VPP X1 X2 RST 31 19 18 9 Tuesday, July 14, 2015 Robotics Club, IOE, WRC 12
  • 13. Power-On RESET with Debounce EA/VPP X1 X2 RST Vcc 10 uF 8.2 K 30 pF 9 31 Tuesday, July 14, 2015 Robotics Club, IOE, WRC 13
  • 14. Pins of 8051(3/4) • /EA(pin 31):external access • There is no on-chip ROM in 8031 and 8032 . • The /EA pin is connected to GND to indicate the code is stored externally. • /PSEN & ALE are used for external ROM. • For 8051, /EA pin is connected to Vcc. • “/” means active low. • /PSEN(pin 29):program store enable • This is an output pin and is connected to the OE pin of the ROM. • See Chapter 14. Tuesday, July 14, 2015 Robotics Club, IOE, WRC 14
  • 15. Pins of 8051(4/4) • ALE(pin 30):address latch enable • It is an output pin and is active high. • 8051 port 0 provides both address and data. • The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the 74LS373 latch. • I/O port pins • The four ports P0, P1, P2, and P3. • Each port uses 8 pins. • All I/O pins are bi-directional. Tuesday, July 14, 2015 Robotics Club, IOE, WRC 15
  • 16. Pins of I/O Port • The 8051 has four I/O ports • Port 0 (pins 32-39):P0(P0.0~P0.7)Bit address (0x80~0x87) • Port 1(pins 1-8) :P1(P1.0~P1.7) Bit address (0x90~0x97) • Port 2(pins 21-28):P2(P2.0~P2.7) Bit address (0xA0~0xA7) • Port 3(pins 10-17):P3(P3.0~P3.7) Bit address (0xB0~0xB7) • Each port has 8 pins. • Named P0.X (X=0,1,...,7), P1.X, P2.X, P3.X • Ex:P0.0 is the bit 0(LSB)of P0 • Ex:P0.7 is the bit 7(MSB)of P0 • These 8 bits form a byte. • Each port can be used as input or output (bi-direction).  Tuesday, July 14, 2015 Robotics Club, IOE, WRC 16
  • 17. PORT P0 (PIN 39 TO 32) Port P0 has got three functionalities.(I/O port, lower order address(A0 to A7) and data (D0 to D7). It can be used for input or output , each pin must be connected externally to a 10K ohm pull-up resistor. ALE indicates if P0 has address or data When ALE=0, it provides data D0-D7 When ALE=1, it has address A0-A7 Tuesday, July 14, 2015 Robotics Club, IOE, WRC 17
  • 18. Pull Up Resistor • Pull-up resistor pulls the voltage of the signal it is connected to towards its voltage source level • Pull-up resistor ensures that the wire is at a defined logic level even if no active devices are connected to it • At reset condition the port zero will be at floating condition ,i.e no 0 no 1 something other state which we cannot predict so to ensure proper logic level we use Pull-up resistor Tuesday, July 14, 2015 Robotics Club, IOE, WRC 18
  • 19. PORT P1 (PIN 1 TO 8) Port P1 is simple I/O port . Internal pull up resistor is provided. PORT P2(PIN 21 TO 28) Port P2 has dual functionality.( I/o port and higher order address(A8 to A15) Port 2 must be used along with P0 to provide the 16-bit address for the external memory.  Internal pull up resistor is provided. Tuesday, July 14, 2015 Robotics Club, IOE, WRC 19
  • 20. PORT P3 (PIN 10 TO 17) Port 3 can be used as input or output. Port 3 does not need any pull-up resistors. Port 3 has the additional function of providing some extremely important signals. Tuesday, July 14, 2015 Robotics Club, IOE, WRC 20
  • 21. Environment Setup Proteus Installation (Proteus 8.1 SP1)(Recommend to use latest version)  1. Exact the provided package  2. Open LICENSE.EXE  3. Change the attribute of Key.lxk to no hidden and no readonly  4. Browse for key -> Select Key.lxk  5. Install key  6. Close LICENSE.EXE  7. Install Proteus 8.1 SP1.exe  8. Do not run after installation  9. Copy "BIN" To Installation Folder (C:Program Files (x86)Labcenter ElectronicsProteus 8 Professional)  10. Copy "MODELS" To ProgramData (C:ProgramDataLabcenter ElectronicsProteus 8 Professional)  11. Run Proteus and enjoy! Tuesday, July 14, 2015 Robotics Club, IOE, WRC 21
  • 22. Keil Installation • I recommend to use latest version of keil(version 4 for 51) • Install the Provided Keil software(trial version or cracked ) • Provide the basic information • Done Tuesday, July 14, 2015 Robotics Club, IOE, WRC 22
  • 23. Proteus Isis should be highlighted (Clickable) Click it to open to initiate design Tuesday, July 14, 2015 Robotics Club, IOE, WRC 23
  • 24. 1 2 3 1. Component mode, Click here to enable Component mode so that we can browse any basic component from 2(pick device) 2. Pick Device, Click here to pick any require component into our workspace 3. Terminal Nodes, terminal nodes like Ground, Power source etc is available over here Tuesday, July 14, 2015 Robotics Club, IOE, WRC 24
  • 25. Create a basic Led Blink Circuit 1 2 1. Click Component mode 3. Type at89c52 2. Click pick device 4. Select the first one 3 4 Tuesday, July 14, 2015 Robotics Club, IOE, WRC 25
  • 26. Pick the LED 1 2 3 4 1. Type Keyword led 2. Select Optoelectronics in Category 3. Select LEDs in sub-category 4. Select LED-RED or LED-GREEn or LED- BLUE in Results Tuesday, July 14, 2015 Robotics Club, IOE, WRC 26
  • 27. Led blink circuit 1. Pick At89c52 microcontroller from device selector 2. Also pick led as shown in figure and wire them 3. Pick a ground from terminal nodes 4. Zoom the workspace as per your easiness 5. Now save your work and give it a name Blink 6. Now its time to write program in keil Tuesday, July 14, 2015 Robotics Club, IOE, WRC 27
  • 28. LED blink Program in Keil using C 1. Open keil 2. Goto Project>New uvision Project> give it a name as Blink (file extension not needed)and save it 3. From CPU Database select Atmel > AT89C52 press ok and click No to not to copy start up files 4. Goto file menu and select new(or press ctrl + N) 5. Save it as Blink.c (don’t forget to include file extension as .c) 6. Under project > Target 1 > Source group 1 add Blink.c (double click Source group 1 to add blink.c) Tuesday, July 14, 2015 Robotics Club, IOE, WRC 28
  • 29. Creating HEX file 6. Under Flash menu goto Configure Flash Tools… 7. 1 2 3 4 5 1. Select Target 2. Enter Xtal value as 12.0 3. Check Use On-chip ROM 4. Select Output 5. Check Create HEX File Click OK Tuesday, July 14, 2015 Robotics Club, IOE, WRC 29
  • 30. Simple LED BLINk.C #include<reg51.h> sbit out = P2^0; void msdelay(unsigned int); void main() { while(1) { out=1; msdelay(500); out=0; msdelay(500); } } void msdelay(unsigned int time) { unsigned int i,j; for(i=0;i<=time;i++) for(j=0;j<=1275;j++); } 1.To Address Port we use sfr or #define keyword sfr ldata = P1; // P must be Capital sfr ldata = 0x90; #define ldata P1 // no equals to, no semicolon 2. To Address A single bit of a Port we use sbit keyword sbit out = P2^0; // it indicates P2.0 sbit enable = P2^1; // P must be Capital sbit buttonChech = P2^2; 3. At initial stage or at reset condition the output of each port or port bit(pin) will be 1(high) Tuesday, July 14, 2015 Robotics Club, IOE, WRC 30
  • 31. Compile and Build 1 2 3 1. Make a Habit to save your work all the time, press (Ctrl+S) to save 2. Compile or Translate, Click it to compile your code to check errors and warning(Ctrl+f7) 3. Press Build or Rebuild to generate HEX file Tuesday, July 14, 2015 Robotics Club, IOE, WRC 31
  • 32. Uploading HEX File 1 2 3 1. Double Click at Microcontroller AT89C52 to open Edit Component Dialog Box 2. Browse for HEX file that you created earlier 3. Press Ok 4. Run Your Simulation 4 Tuesday, July 14, 2015 Robotics Club, IOE, WRC 32
  • 33. DEMO Tuesday, July 14, 2015 Robotics Club, IOE, WRC 33
  • 34. To make a port or single pin as an input we need to declare it as HIGH or 1 #include<reg51.h> sbit out = P2^0; sbit in = P2^1; void msdelay(unsigned int); void main() { in = 1; P2=0; while(1) { if( in == 1){ out=1; } else { out=0; } } } void msdelay(unsigned int time) { unsigned int i,j; for(i=0;i<=time;i++) for(j=0;j<=1275;j++); } Search Button in Component search box Tuesday, July 14, 2015 Robotics Club, IOE, WRC 34
  • 35. Liquid Crystal Display (LCD):- LCD is finding widespread use replacing LEDs because  The declining prices of LCD  The ability to display numbers, characters and graphics Ease of programming for characters and graphics Tuesday, July 14, 2015 Robotics Club, IOE, WRC 35
  • 36. Pin Descriptions for LCD Pin Symbol I/O Descriptions 1 VSS ----- Ground 2 VCC ----- +5 v power supply 3 VEE ----- Power supply to contrast 4 RS I Register Select( 0 for command register and 1 for data register) 5 __ R /W I 1 for Read 0 for write 6 E I/O Enable 7-14 DB0-DB7 I/O The 8-bit data bus 15 LED + ----- Usually Connected t0 +5v of power supply 16 LED- ----- Connected to Ground Tuesday, July 14, 2015 Robotics Club, IOE, WRC 36
  • 37. Instruction VS Data • Instruction Register (IR) and Data Register (DR) • Instruction is a Command, Data is a displaying Value • There are two 8-bit registers in Our LCD controller IC, Instruction and Data register. Instruction register corresponds to the register where you send commands to LCD e.g LCD shift command, LCD clear, LCD address etc. and Data register is used for storing data which is to be displayed on LCD. • Only the instruction register (IR) and the data register (DR) of the LCD can be controlled by our 8051 microcontroller Tuesday, July 14, 2015 Robotics Club, IOE, WRC 37
  • 38. LCD PROTEUS SIMULATION 1.Lcd is named as LM016L in Component Mode Pick Device i.e Library 2. Connect P2.0~P2.7 of microcontroller to D0~D7 of LCD respectively 3. Connect P3.0 to RS, P3.1 to RW and P3.2 to E Tuesday, July 14, 2015 Robotics Club, IOE, WRC 38
  • 39. Before using the LCD for display purpose, LCD has to be initialized either by the internal reset circuit or sending set of commands to initialize the LCD. It is the user who has to decide whether an LCD has to be initialized by instructions or by internal reset circuit. we will dicuss both ways of initialization one by one. We need to initialize LCD to define type of LCD, Cursor Position, Home Location etc Type includes like 16x2 or 14x1 or 20x2 etc Tuesday, July 14, 2015 Robotics Club, IOE, WRC 39
  • 40. Some Points to note while Programming A high to low pulse should be provided in an enable pin for Write Operation A low to high pulse should be provided in an enable pin for Read Operation Bit D7 of LCD is busy flag which can be used to check if LCD is busy in its own internal operation Busy flag can be read when R/W =1 and RS=0 and a L to H pulse in enable pin NOTE:- It is recommended to check busy flag before writing any data to LCD. Tuesday, July 14, 2015 Robotics Club, IOE, WRC 40
  • 41. LCD BUSY CHECK (BF-FLAG) • Busy Flag is an status indicator flag for LCD. When we send a command or data to the LCD for processing, this flag is set (i.e BF =1) and as soon as the instruction is executed successfully this flag is cleared (BF = 0). This is helpful in producing and exact amount of delay. for the LCD processing. • To read Busy Flag, the condition RS = 0 and R/W = 1 must be met and 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. Tuesday, July 14, 2015 Robotics Club, IOE, WRC 41
  • 42. BUSY CHECK void lcdbusy() { busy=1; // declaring D7 of LCD as input to check busy flag rw=1; rs=0; while(busy==1) { en=0; msdelay(1); en=1; } return; } Tuesday, July 14, 2015 Robotics Club, IOE, WRC 42
  • 43. Sending Command To LCD void lcdcmd(unsigned char value) { lcdbusy(); //Wait for LCD to process the command ldata=value; //Function set: 2 Line, 8-bit, 5x7 dots rs=0; //Selected command register rw=0; //We are writing in instruction register en=1; //Enable H->L msdelay(1); en=0; //Enable H->L return; } Tuesday, July 14, 2015 Robotics Club, IOE, WRC 43
  • 44. LCD Command Codes Tuesday, July 14, 2015 Robotics Club, IOE, WRC 44
  • 45. Sending Data To LCD void lcddata(unsigned char value) { lcdbusy(); //Wait for LCD to process the command ldata=value; //Function set: 2 Line, 8-bit, 5x7 dots rs=1; //Selected data register rw=0; //We are writing in data register en=1; //Enable H->L msdelay(1); en=0; //Enable H->L return; } // we will pass the character to display as argument to function Tuesday, July 14, 2015 Robotics Club, IOE, WRC 45
  • 46. Sending String Data To LCD void lcdstr(unsigned char msg[15]) //to print string in lcd { unsigned char i=0; while(msg[i]!='$') { if(i>16) { msdelay(10); lcdcmd(0x07); //shift display to left } if(msg[i]==' ') msdelay(50); if(i==15) lcdcmd(0x07); lcddata(msg[i]); i++; } }Tuesday, July 14, 2015 Robotics Club, IOE, WRC 46
  • 47. SELECTING FIRST AND SECOND ROW void lcdfirst() { lcdcmd(0x38); lcdcmd(0x0e); msdelay(50); lcdcmd(0x01);// clear lcdcmd(0x06); lcdcmd(0x80); } void lcdsecond() { lcdcmd(0x38); lcdcmd(0x0e); msdelay(50); lcdcmd(0x06); lcdcmd(0xc0); } Tuesday, July 14, 2015 Robotics Club, IOE, WRC 47
  • 48. OVERALL PROGRAM FOR LCD Tuesday, July 14, 2015 Robotics Club, IOE, WRC 48
  • 49. #include<reg51.h> #define ldata P2 //lcd data sbit rs=P3^0; //lcd signals sbit rw=P3^1; sbit en=P3^2; sbit busy=P2^7; void lcdbusy(); //to check if lcd is busy or not void lcdcmd(unsigned char) ; // to give lcd commands void lcddata(unsigned char); //to give data to the lcd void lcdfirst(); // first line of lcd initialization void lcdsecond(); // second line of lcd initialization void lcdstr(unsigned char[]); // to display string void msdelay (unsigned char); void main() { P2=0; P3=0; while(1) { lcdfirst(); lcdstr("Hello"); msdelay(1000); lcdsecond(); lcdstr("Pokhara1"); msdelay(1000); } } Tuesday, July 14, 2015 Robotics Club, IOE, WRC 49
  • 50. void msdelay(unsigned char time) { unsigned int i,j; for(i=0;i<time;i++) for(j=0;j<=1275;j++); } void lcdbusy() { busy=1; rw=1; rs=0; while(busy==1) { en=0; msdelay(1); en=1; } return; } Tuesday, July 14, 2015 Robotics Club, IOE, WRC 50
  • 51. void lcdcmd(unsigned char value) { lcdbusy(); ldata=value; rs=0; rw=0; en=1; msdelay(1); en=0; return; } void lcddata(unsigned char value) { lcdbusy(); ldata=value; rs=1; rw=0; en=1; msdelay(1); en=0; return; } Tuesday, July 14, 2015 Robotics Club, IOE, WRC 51
  • 52. void lcdfirst() { lcdcmd(0x38); //2 lines and 5x7 matrix lcdcmd(0x0e); msdelay(50); //cursor blink lcdcmd(0x01); //clear display screen lcdcmd(0x06); //shift cursor to right lcdcmd(0x80); } void lcdsecond() { lcdcmd(0x38); //2 lines and 5x7 matrix lcdcmd(0x0e); msdelay(50); //cursor blink lcdcmd(0x06); //shift cursor to right lcdcmd(0xc0); } Tuesday, July 14, 2015 Robotics Club, IOE, WRC 52
  • 53. void lcdstr(unsigned char msg[]) //to print string in lcd { unsigned char i=0; while(msg[i]!='0') { if(i>16) { msdelay(10); lcdcmd(0x07); } if(msg[i]==' ') msdelay(50); if(i==15) lcdcmd(0x07); lcddata(msg[i]); i++; } } Tuesday, July 14, 2015 Robotics Club, IOE, WRC 53
  • 54. ANY QUESTION? Tuesday, July 14, 2015 Robotics Club, IOE, WRC 54