Lab Manual 8051

46
STUDY OF 8051 MICRO CONTROLLER ARCHITECTURE Ex no:1 Date: Aim: To study about 8051 micro controller architecture 8051 microcontroller pins PIN1-8: Port 1 each of these pins can be configured as input or output PIN 9: Rs logical one on this pin stop microcontroller’s operating and erases the contents of most registers. By applying the logical zero to the pin, the program starts execution from the beginning. In other words, a positive voltage pulse on this pin resets the microcontroller. PINS 10-17: Port3 similar to port 1, each of these pins can serve as universal input or output. Besides, all of them have alternative functions PIN 10: Rxd serial asynchronous communication input or serial synchronous communication input PIN 11: 1

Transcript of Lab Manual 8051

Page 1: Lab Manual 8051

STUDY OF 8051 MICRO CONTROLLER ARCHITECTURE

Ex no:1

Date:

Aim:

To study about 8051 micro controller architecture 8051 microcontroller pins

PIN1-8:

Port 1 each of these pins can be configured as input or output

PIN 9:

Rs logical one on this pin stop microcontroller’s operating and erases the contents of most registers. By applying the logical zero to the pin, the program starts execution from the beginning. In other words, a positive voltage pulse on this pin resets the microcontroller.

PINS 10-17:

Port3 similar to port 1, each of these pins can serve as universal input or output. Besides, all of them have alternative functions

PIN 10:

Rxd serial asynchronous communication input or serial synchronous communication input

PIN 11:

txd serial asynchronous communication output or serial synchronous communication output

PIN 12: int0 interrupt 0 input

PIN13: int1 interrupt 1 input

PIN14: t0 counter 0 clock input

PIN15: t1 counter 1 clock input

PIN16: wr signal for writing to external (additional) ram

PIN 17: RD signal for reading from external RAM

1

Page 2: Lab Manual 8051

Block Diagram of 8051

PIN 18, 19:

X2, X1 internal oscillator input and output. A quartz crystal is connected to these pins to generate operating frequency

PIN 20: Ground

PIN 21-28:

Port 2 configured as inputs and outputs. In the case of external memory being used these offer the address A8-A15.

PIN 29:

PSEN if external ROM is used for storing program then it has logic 0 value every time the microcontroller reads from memory.

2

Page 3: Lab Manual 8051

Pin diagram of 8051

PIN 30:

ALE prior to each reading from external memory, the controller will set the low address on P0 and after that activates the output ALE. In the second part of the microcontroller machine cycles, a signal stops and P0 is used for data transmission.

PIN 31:

EA by applying logic zero to this pin ,P2 and P3 are used for data and address transmission with no regard to whether there is internal memory or not. That means even if program is there on the controller it will not be executed. Applying logic one to EA the controller will use both the memories.

PIN 32: Port 0 is similar to port 2, if external memory is accessed.P0 provides the lower address byte (A0-A7).

PIN 40: Vcc Power supply +5v.

3

Page 4: Lab Manual 8051

SPECIAL FUNCTION REGISTER:

These registers are a kind of control table used for running and monitoring the microcontroller operation. There are only 21 registers of this type.

Accumulator:

A general purpose register for storing immediate values during operation.

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

B register:

It is used during multiplication and division along with the A register.

R Register (R0-R7):

Common general purpose registers used during any operation of the microcontroller.

PSW Registers:

The Program Status Register contain several bits that reflect the current state of the CPU.

CY AC F0 RS1 RS0 OV - P

CY-carry

AC-Auxillary carry

RS1,RS0 –Register Bank Select

OV –Over flag

P-Parity.

DATA POINTER REGISTER (DPTR):

These are 16-bits wide for external memory addressing. They are divided into DPH (Data Pointer High) and DPL (Data Pointer Low).

4

Page 5: Lab Manual 8051

Stack Pointer(SP):

It points to the RAM and permits the stack availability .It is 8-bit wide. After reset it points to address of 7 of the memory.

Counter and Timers:

The 8051 has 2 timer, each 16-bit wide. their main purpose is for counting occurrences of external events and measuring the time.

T0: when timer 0 is equal to 0 then both registers will include 0 value.

If the timer register contains a value of then accordingly its value is either used for counting or for timing.

TMOD Register:

Gate1 C/T TM1 TM0 Gate0 C/T TM1 TM0

Writing into these will select the timer and their mode of operation.

TM1 TM0 Mode description

0 0 0 13-bit timer

0 1 1 16-bit timer

1 0 2 8-bit auto reload

1 1 3 Split mode

Gate: starts the timer 1 using a signal provided to the pin INTO(P3.2)

C/T0 =1; timer operation else counter operation

TCON REGISTER:

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0

5

Page 6: Lab Manual 8051

TF1-automatically set when timer1 overflows

TR1=1; timer1 on else timer off

TF0-automatically set when timer0 overflows

TR0=1; timer1 on else timer0 off

UART:

It’s a duplex port for serial communication which means it can receive and transmit data serially. Serial data is sent by writing into SBUF register. SBUF is an 8-bit register. All bits used for controlling the serial communication is done with the help of the SCON register.

SM0 SM1 SM2 REN TB8 RB8 TI RI

SMO,SM1,SM2 –For mode selection

REN-receive enable

TI-set during transmission

RI-set during reception

SM0 SM1 MODE Description Baud Rate

0 0 0 8-bit shift register

1/12 quartz frequency

0 1 1 8-bit uart From timer 1

1 0 2 9-bit uart 1/32 quartz frequency

1 1 3 9-bit uart From timer 1

RESET: Reset occurs when RS=1.Here all internal registers are reset by the microcontroller

6

Page 7: Lab Manual 8051

Keil µ VISION2 SOFTWARE

EXP.NO:2

DATE:

AIM:

To study about the Keil software and its features.

Keil µ Vision2 IDE:

Keil tools can be used to generate embedded applications for all 8051

family.

This software can be used for functions like

Compiling codes

Assembling the assembly source file

Linking and locating objects modules and libraries

Creating hex files

Debugging the target program

It is a combined tool for project management source code editing and program

debugging in single environment

C51 ANSI and A51 macro assembler creates the relocatable object modules

from 8051 ASM code.

BL51 linker/locator combines the relocatable object modules

LIB51 library manager combines the object modules.

OH51 object Hex creates the Intel hex files

7

Page 8: Lab Manual 8051

FTX51 RTOS simplifies the design of complex time critical software

project.

C51 Compiler & A51 Assembler :

Source files are created by the µ Vision2 IDE and are passed to the

C51Compiler or A51 Assembler .The compiler and assembler process source

files and create relocatable object files. This id full ANSI implementation of C

programming in addition to numerous features

LIB51 Library Manager:

Allows you to create object library from object files created by compiler

and assembler. Libraries are specially formatted, ordered program collections of

object modules that may be the linker at later time.

BL51 Linker/Locator:

It creates an absolute object module using the object module extracted

from libraries and those created by compiler and assembler. All code and data

are reside at fixed memory location.

µ Vision2 Debugger:

The µVision2 symbolic, source –level debugger is ideally suited for fast,

reliable program debugging. The debugger includes a high-speed simulator that

let you simulate 8051 system including on-chip peripherals and external

hardware. Provides several ways for you to test programs on real target

hardware.

Monitor51:

The monitor program resides in memory of your target and communicates

with µVision2 debugger using the serial port of 8051 and COM port of your PC.

8

Page 9: Lab Manual 8051

RTX51 RTOS:

The RTX51 RTOS is multitasking kernel for the 8051 microcontroller

family. It simplifies the system design, programming and debugging of complex

application where fast reaction to time critical events are essentials. Task

description tables and operating system consistency are automatically controlled

by BL51.

PK51 Professional Development Kit:

Includes everything the developer needs. It can be configured for all 8051

members

CA51 Comiler Kit:

It is the best choice for developers who need a C compiler but not a

debugging system. The kit has everything you need to create an embedded

application.

A51 Assembler Kit:

A51 assembler Kit includes an assembler and all the utilities you need to

create embedded applications.

9

Page 10: Lab Manual 8051

SIMULATION PROGRAM

EXP.NO.3

DATE:

AIM:

To simulate the following program by writing AlP or C program.

Search the number X in the given set of numbers

Sort the numbers

To design a simple calculator

COMPONENTS REQUIRED:

PC installed with Keil software

10

Page 11: Lab Manual 8051

TOGGLING OF THE INPUT AND OUTPUT PORT PINS

EX NO:4

DATE:

AIM:

To design a C51 Program for toggling input and output pins.

COMPONENTS REQUIRED:

Microcontroller IC P89C51RD2

Max 232 IC & 9 –pin RS232 female connector.

Bread board & connecting wires.

Resistors 8.2KΩ, 1kΩ

Crystal Oscillator 11.0592 MHz.

Capacitor 10µf, 33pf, 0.1µf.

Switch & power supply.

LED

PROCEDURE:

The hardware connections are done as per the circuit diagram.

The software program has been written by using Keil microvision-2

software.

Port 1 (P1.4) is connected to LED through 1kΩ resistor.

Toggling has been observed.

11

Page 12: Lab Manual 8051

Basic circuitry using 8051 and its verification by toggling the LED

12

Page 13: Lab Manual 8051

13

Page 14: Lab Manual 8051

SEVEN SEGMENT DISPLAY

EXP.NO.5

DATE:

AIM:

To write a assembly language program for seven segment display.

COMPONENTS REQUIRED:

8051 microcontroller

RS232

Seven segment display

Bread board

Regulated power supply

Connectors

Reset switch

Capacitor

Resistors

Crystal oscillator

Connecting wires

DESCRIPTION:

Connections are given as per the circuit diagram. The +5V supply is

connected to the common anode of the seven segment display. The pins of the

seven segment are connected to the ports of the 8051 Microcontroller. The

program is downloaded to the microcontroller with the help of Flash magic and

the output is displayed in the seven segment.

14

Page 15: Lab Manual 8051

SEVEN SEGMENT

DISPLAY:

RESISTOR VALUE: 4.7 KILO Ω

15

Page 16: Lab Manual 8051

16

Page 17: Lab Manual 8051

LCD INTERFACE

EX.NO:6

DATE:

AIM:

To design a C51 program for LCD interface.

COMPONENTS REQUIRED:

LCD (JMD 162A)

Microcontroller IC P89C51RD2.

Max 232 IC & 9 –pin RS232 female connector.

Bread board & connecting wires.

Resistors 1KΩ

10KΩ potentiometer.

Crystal Oscillator 11.0592 MHz.

Capacitor 10µf, 33pf, 0.1µf.

Switch & power supply.

PROCEDURE:

The hardware connections are done as per the circuit diagram shown.

The software program has been written by using Keil microvision-2.

Port 0(p0.0 to p0.7) is connected to lcd data pins and port 2(p2.4 to p2.6)

is connected to control pins (RS, R/W, E).

The corresponding given data has been displayed in the lcd.

17

Page 18: Lab Manual 8051

LCD DISPLAY

18

Page 19: Lab Manual 8051

KEYPAD INTERFACE

19

Page 20: Lab Manual 8051

EX.NO:7

Date:

AIM:

To design a C51 program for (4*4) matrix keypad interface with

IC P89C51RD2.

COMPONENTS REQUIRED:

Keypad.(4*4 matrics).

Interface card. (8-pin female single row).

Microcontroller Ic P89C51RD2.

Max 232 Ic & 9 –pin RS232 female connector

Bread board & connecting wires.

Resistors 8.2KΩ

Crystal Oscillator 11.0592 MHz.

Capacitor 10µf, 33pf, 0.1µf.

Switch & power supply.

PROCEDURE:

20

Page 21: Lab Manual 8051

The hardware connections are done as per the circuit diagram shown in

figure.

The software program has been written by using Keil microvision-2

software.

Port 1(p1.0 to p1.3) is connected to rows and port 2(p2.0 to p2.3) is

connected to columns.

To avoid the Key debouncing we have give the delay for the program

For different key press, different ASCII values are determined.

KEYPAD INTERFACE

PROGRAM TO INTERFACE A STEPPER MOTOR

21

Page 22: Lab Manual 8051

EXP.NO.8

DATE:

AIM :

To write a Program to interface a stepper motor with 8051µc using keil

software.

COMPONENTS REQUIRED:

8051 µC

Stepper motor

Resistor 4.7k

Max232 IC

Power Supply (0-5v)

DESCRIPTION:

Here we interface stepper motor with 8051 microcontroller using

ULN2003. ULN2003 is used to convert digital data to analog data to control

stepper motor. Separate power supply is needed for both microcontroller &

stepper motor.

22

Page 23: Lab Manual 8051

STEPPER MOTOR INTERFACE

23

Page 24: Lab Manual 8051

SERIAL COMMUNICATION

EXP.NO:9

DATE:

AIM:

To write a C program for serial communication using 8051 microcontroller

COMPONENTS REQUIRED:

8051 µC

Max232 IC

Power Supply (0-5v)

Bread Board and Connecting wires

DIAGRAM

24

Page 25: Lab Manual 8051

Serial Communication

SRAM INTERFACE

25

Page 26: Lab Manual 8051

Ex. No:10

Date :

AIM:

To design a C51 program to interface the SRAM.

COMPONENTS REQUIRED:

MicroContoller-P89C51RD2xx

32 Kb RAMHY62256 (15-address lines)

Latch74LS373

Bread Board and Connecting Wires

RS232

PROCEDURE:

The hardware connections are done as per the circuit diagram

shown.

The software program has been written by using Keil microvision-

3 software.

Port0 (p0.1 to po.7) is connected to SRAM through the latch

74Ls373.

Port2 (p2.0 to p2.7) is connected to the remaining 7 Address pins

of SRAM.

The corresponding outputs have been observed.

26

Page 27: Lab Manual 8051

SRAM INTERFACING

27

Page 28: Lab Manual 8051

ANALOG-DIGITAL CONVERSION USING 8051

EXP.NO.11

DATE:

AIM:

To design a program for ADC 0804 using 8051 Microcontroller

COMPONENTS REQUIRED:

MicroController-P89C51RD2xx

ADC 0804

Bread Board and Connecting Wires

RS232

DIAGRAM:

ADC 0804

28

Page 29: Lab Manual 8051

PPI INTERFACE TO MCS51 FOR PARALLEL COMMUNICATION

EXP.NO.12

DATE:

AIM:

To establish parallel connection between two DTE’s.

EXPERIMENTAL SETUP:

Connect the power supply and switch on

Connect the parallel cable to both parallel ports on DTE’s and lock the

connectors

PROCEDURE:

Download the tx_pp.hex file to Node-1 NVRAM as explained in

configuration of hardware section.

Download the rx_pp.hex file to Node-2 NVRAM as explained in

configuration of hardware section.

After successfully downloading the code, execute the code in both the

nodes as explained in configuration of hardware section.

Transmitting Node-1 accepts the data from the keyboard and transmits to

the receiver through 8255 port configured as output.

On the reception of a byte on the receiver node ,the byte is displayed on

LCD

The program gets executed in an infinite loop for transmission and

reception till controller is reset

OBSERVATIONS:

29

Page 30: Lab Manual 8051

We learn from this

1. The initialization of 8255 PPI for input and output modes.

2. Acquiring the data from keyboard, transmission of the data

through parallel port.

RS 485 EXPERIMENTS

30

Page 31: Lab Manual 8051

EXP.NO:13

DATE:

AIM:

To understand how to use RS485 physical layer, set up two 8051 controller

boards as nodes of RS-485 network. Transmit the data from one board and

receive the same on the other row boards.

EXPERIMENTAL SETUP:

Make the connection as shown in figure

Insert the EEPROM labelled as “BOOT LOADER” to 8051 main

controller cards

Connect RS485 cable to RS485 ports of microcontroller boards.

Make the jumper connections for JP6 as shown below for RS232

communication to download the hex file to NVRAM

Connect RS232 download the cable between the main controller RS232

port and PC comport for all three nodes

Switch ON the power supply to the main controller card

Now download “485tx.hex” to node1

Now download “485rx.hex” to node2 and node3.

PROCEDURE:

31

Page 32: Lab Manual 8051

After successfully downloading the code, remove the jumpers and now

execute the code on all three nodes as explained

After the execution of the code place jumpers forRS485 communication

Now key in data on transmitter node-1 and this data is transmitted in

RS485 mode

On the receiver Node-2 and Node-3 the received data is displayed

RS485 COMMUNICATION

OBSERVATION:

32

Page 33: Lab Manual 8051

The RS485 is physical layer implementation with a common

bus running between all nodes .if more than one node transmits at the same

time, then collision occurs thereby receiving junk data.

CAN AUTOMATION

33

Page 34: Lab Manual 8051

Exp. No:14

DATE

AIM:

To Design of SJA1000 Standalone interface with micro controller for

CAN interface.

COMPONENTS REQUIRED:

Microcontroller -P80C31RD2xx

SJA1000

PCA82C250\251

Bread Board and Connecting Wires

CAN bus

PROCEDURE:

The hardware connections are done as per the circuit diagram.

The software program has been written by using Keil microvision-3

software.

Data has been transmitted between the two controller through the CAN

bus.

The Received data has been observed in the microcontroller

34

Page 35: Lab Manual 8051

REGISTERS IN CAN CONTROLLER:

CONTROL REGISTER (CR)

The contents of the control register are used to change the behaviour of the

CAN controller. Bits may be set or reset by the attached microcontroller which

uses the control register as a read/write memory.

CLOCK DIVIDER REGISTER (CDR)

The clock divider register is used to select the CAN mode of operation (Basic

CAN/ Peli-CAN). Therefore one of the reserved bits within the PCA82C200 is

used. Writing a value between 0 and 7, as allowed for the PCA82C200, will

enter the Basic CAN mode. The default state is divide by 12 for Motorola mode

and divide by 2 for Intel mode.

35

Page 36: Lab Manual 8051

INTERRUPT REGISTER (IR)

The interrupt register allows the identification of an interrupt source. W hen

one or more bits of this register are set the INT pin is activated (LOW). After

this register is read by the microcontroller, all bits are reset what results in a

floating level at INT. The interrupt register appears to the microcontroller as a

read only memory.

ACCEPTANCE CODE REGISTER (ACR)

This register can be accessed (read/write), if the reset request bit is set HIGH

(present). The acceptance code bits (AC.7 to AC.0) and the eight most

significant bits of the message’s identifier (ID.10 to ID.3) must be equal to

those bit positions which are marked relevant by the acceptance mask bits

(AM.7 to AM.0).

MODE REGISTER (MOD)

The contents of the mode register are used to change the behaviour of the CAN

controller. Bits may be set or reset by the CPU which uses the control register as

a read/write memory. Reserved bits are read as logic 0.

COMMAND REGISTER (CMR)

A command bit initiates an action within the transfer layer of the CAN

controller. This register is write only; all bits will return a logic 0 when being

read. Between two commands at least one internal clock cycle is needed in

order to proceed. The internal clock is half of the external oscillator frequency.

STATUS REGISTER (SR)

The content of the status register reflects the status of the CAN controller. The

status register appears to the CPU as a read only memory.

36

Page 37: Lab Manual 8051

INTERRUPT ENABLE REGISTER (IER) The register allows us to enable

different types of interrupt sources which are indicated to the CPU. The

interrupt enable register appears to the CPU as a read/write memory.

ARBITRATION LOST CAPTURE REGISTER (ALC)

This register contains information about the bit position of losing arbitration.

The arbitration lost capture register appears to the CPU as a read only memory.

Reserved bits are read as logic 0.

ERROR CODE CAPTURE REGISTER (ECC)

This register contains information about the type and location of errors on the

bus. The error code capture register appears to the CPU as a read only memory.

37