Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
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...
Contents
 Introduction
 Block Diagram and Pin Description of the 8051
 Environment setup (Proteus and Keil)
 Introduct...
Introduction
Microcontroller
• CPU, RAM, ROM, I/O and timer are all on a single chip
• fix amount of on-chip ROM, RAM, I/O...
Block Diagram
CPU
On-chip
RAM
On-chip
ROM for
program
code
4 I/O Ports
Timer 0
Serial
PortOSC
Interrupt
Control
External i...
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...
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
2...
Pins of 8051(1/4)
• Vcc(pin 40):
• Vcc provides supply voltage to the chip.
• The voltage source is +5V.
• GND(pin 20):gro...
XTAL Connection to 8051
C2
30pF
C1
30pF
XTAL2
XTAL1
GND
• Using a quartz crystal oscillator
• We can observe the frequency...
XTAL Connection to an External Clock
Source
N
C
EXTERNAL
OSCILLATOR
SIGNAL
XTAL2
XTAL1
GND
• Using a TTL oscillator
• XTAL...
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 ...
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 Roboti...
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...
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...
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-...
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)...
Pull Up Resistor
• Pull-up resistor pulls the voltage of the signal it is connected to
towards its voltage source level
• ...
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 ...
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 th...
Environment Setup
Proteus Installation (Proteus 8.1 SP1)(Recommend to use latest version)
 1. Exact the provided package
...
Keil Installation
• I recommend to use latest version of keil(version 4 for 51)
• Install the Provided Keil software(trial...
Proteus
Isis should be highlighted (Clickable)
Click it to open to initiate design
Tuesday, July 14, 2015 Robotics Club, I...
1
2
3
1. Component mode, Click here
to enable Component mode
so that we can browse any
basic component from 2(pick
device)...
Create a basic Led Blink Circuit
1
2
1. Click Component mode 3. Type at89c52
2. Click pick device 4. Select the first one
...
Pick the LED
1
2
3
4
1. Type Keyword led
2. Select Optoelectronics in Category
3. Select LEDs in sub-category
4. Select LE...
Led blink circuit
1. Pick At89c52
microcontroller from
device selector
2. Also pick led as shown in
figure and wire them
3...
LED blink Program in Keil using C
1. Open keil
2. Goto Project>New uvision Project> give it a name as Blink (file
extensio...
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....
Simple LED BLINk.C
#include<reg51.h>
sbit out = P2^0;
void msdelay(unsigned int);
void main()
{
while(1)
{
out=1;
msdelay(...
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, Cl...
Uploading HEX File
1
2
3
1. Double Click at Microcontroller
AT89C52 to open Edit
Component Dialog Box
2. Browse for HEX fi...
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 = P...
Liquid Crystal Display (LCD):-
LCD is finding widespread use replacing LEDs because
 The declining prices of LCD
 The ab...
Pin Descriptions for LCD
Pin Symbol I/O Descriptions
1 VSS ----- Ground
2 VCC ----- +5 v power supply
3 VEE ----- Power su...
Instruction VS Data
• Instruction Register (IR) and Data Register (DR)
• Instruction is a Command, Data is a displaying Va...
LCD PROTEUS SIMULATION
1.Lcd is named as LM016L in Component
Mode Pick Device i.e Library
2. Connect P2.0~P2.7 of microcon...
Before using the LCD for display purpose, LCD has to be initialized either
by the internal reset circuit or sending set of...
Some Points to note while Programming
A high to low pulse should be provided in an enable pin for Write
Operation
A low ...
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 pr...
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;
...
Sending Command To LCD
void lcdcmd(unsigned char value)
{
lcdbusy(); //Wait for LCD to process the command
ldata=value; //...
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; //Fu...
Sending String Data To LCD
void lcdstr(unsigned char msg[15]) //to print string in lcd
{
unsigned char i=0;
while(msg[i]!=...
SELECTING FIRST AND SECOND ROW
void lcdfirst()
{
lcdcmd(0x38);
lcdcmd(0x0e);
msdelay(50);
lcdcmd(0x01);// clear
lcdcmd(0x0...
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...
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;
...
void lcdcmd(unsigned char value)
{
lcdbusy();
ldata=value;
rs=0;
rw=0;
en=1;
msdelay(1);
en=0;
return;
}
void lcddata(unsi...
void lcdfirst()
{
lcdcmd(0x38); //2 lines and 5x7 matrix
lcdcmd(0x0e);
msdelay(50); //cursor blink
lcdcmd(0x01); //clear d...
void lcdstr(unsigned char msg[]) //to print string in lcd
{
unsigned char i=0;
while(msg[i]!='0')
{
if(i>16)
{
msdelay(10)...
ANY QUESTION?
Tuesday, July 14, 2015 Robotics Club, IOE, WRC 54
Próxima SlideShare
Cargando en…5
×

5

Compartir

Descargar para leer sin conexión

Microcontroller 8051 training

Descargar para leer sin conexión

This slides includes all the necessary steps to Program 8051 family micro-controller. A fresher will be able to simulate LCD in Proteus Using C in Keil !!

Microcontroller 8051 training

  1. 1. Microcontroller 8051 Training -Pradip Bhandari Tuesday, July 14, 2015 Robotics Club, IOE, WRC 1
  2. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 23. Proteus Isis should be highlighted (Clickable) Click it to open to initiate design Tuesday, July 14, 2015 Robotics Club, IOE, WRC 23
  24. 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. 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. 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. 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. 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. 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. 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. 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. 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. 33. DEMO Tuesday, July 14, 2015 Robotics Club, IOE, WRC 33
  34. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 44. LCD Command Codes Tuesday, July 14, 2015 Robotics Club, IOE, WRC 44
  45. 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. 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. 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. 48. OVERALL PROGRAM FOR LCD Tuesday, July 14, 2015 Robotics Club, IOE, WRC 48
  49. 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. 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. 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. 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. 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. 54. ANY QUESTION? Tuesday, July 14, 2015 Robotics Club, IOE, WRC 54
  • 87468781

    Apr. 11, 2018
  • aravind10anbu

    Sep. 21, 2015
  • PrakashAryal3

    Jul. 15, 2015
  • yogendra48

    Jul. 14, 2015
  • bishalbhattarai1

    Jul. 14, 2015

This slides includes all the necessary steps to Program 8051 family micro-controller. A fresher will be able to simulate LCD in Proteus Using C in Keil !!

Vistas

Total de vistas

1.522

En Slideshare

0

De embebidos

0

Número de embebidos

14

Acciones

Descargas

127

Compartidos

0

Comentarios

0

Me gusta

5

×