Lab Manual 8051
Lab Manual 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 microcontrollers 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: PIN13: PIN14: PIN15: PIN16: int0 interrupt 0 input int1 interrupt 1 input t0 counter 0 clock input t1 counter 1 clock input wr signal for writing to external (additional) ram
PIN 17:
PIN 18, 19: X2, X1 internal oscillator input and output. A quartz crystal is connected to these pins to generate operating frequency PIN 20: 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: Ground
PSEN if external ROM is used for storing program then it has logic 0 value every time the microcontroller reads from memory.
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:
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).
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 0 0 1 1 TM0 0 1 0 1 Mode 0 1 2 3 description 13-bit timer 16-bit timer 8-bit reload auto
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
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: Its 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 0 0 1 SM1 0 1 0 MODE 0 1 2 Description Baud Rate
8-bit shift 1/12 quartz register frequency 8-bit uart 9-bit uart From timer 1 1/32 quartz
RESET: Reset occurs when RS=1.Here all internal registers are reset by the microcontroller 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 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. 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.
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
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.
Resistors 8.2K, 1k Crystal Oscillator 11.0592 MHz. Capacitor 10f, 33pf, 0.1f. Switch & power supply.
11
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.
12
Basic circuitry using 8051 and its verification by toggling the LED
13
14
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.
15
SEVEN DISPLAY:
SEGMENT
16
17
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 10f, 33pf, 0.1f.
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).
18
19
LCD DISPLAY
20
KEYPAD INTERFACE 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.
21
PROCEDURE: 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.
22
KEYPAD INTERFACE PROGRAM TO INTERFACE A STEPPER MOTOR EXP.NO.8 DATE: AIM: To write a Program to interface a stepper motor with 8051c 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.
23
24
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
25
DIAGRAM
Serial Communication
26
SRAM INTERFACE 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:
27
The hardware connections are done as per the circuit The software program has been written by using Keil Port0 (p0.1 to po.7) is connected to SRAM through the latch Port2 (p2.0 to p2.7) is connected to the remaining 7 Address
diagram shown. microvision-3 software. 74Ls373. pins of SRAM. The corresponding outputs have been observed.
28
SRAM INTERFACING
29
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:
30
ADC 0804 PPI INTERFACE TO MCS51 FOR PARALLEL COMMUNICATION EXP.NO.12 DATE: AIM: To establish parallel connection between two DTEs. EXPERIMENTAL SETUP: Connect the power supply and switch on Connect the parallel cable to both parallel ports on DTEs and lock the connectors PROCEDURE:
31
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: 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.
32
RS 485 EXPERIMENTS 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
33
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: 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
34
RS485 COMMUNICATION
OBSERVATION: 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.
35
CAN AUTOMATION Exp. No:14 DATE AIM: To Design of SJA1000 Standalone interface with micro controller for CAN interface.
36
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. software.
The software program has been written by using Keil microvision-3 Data has been transmitted between the two controller through the CAN bus. The Received data has been observed in the microcontroller
37
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.
38
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 messages 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.
39
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.
40