TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL 4.1 Experiment No. 1 Aim: Simple programs on Memory transfer. Problem Statement: To develop and implement a simple program for transferring data from a source memory location to a destination memory location using the 8051 Microcontrollers. Objective: a. To understand the basic concept of data transfer between registers and memory. b. To study different addressing modes used for memory transfer operations. c. To develop simple programs for transferring, copying, and exchanging data between memory locations. d. To familiarize with the instruction set related to memory transfer operations. Outcome: a. Students will be able to understand the concept of data movement between registers and memory. b. Students will demonstrate the use of basic memory transfer instructions c. Students will be able to apply different addressing modes for memory-to-memory and register-to-memory data transfer. Apparatus / Software Required: PC with Windows OS Keil μVision IDE Simulator/debugger Theory: Microcontroller consists of all features that are found in microprocessors with additional built- in ROM, RAM, I/O ports, Serial ports, Timers, Interrupts, and Clock circuits. It is an entire computer on a single chip that is embedded within applications. Microcontrollers are widely used in many domestic (washing machines, VCD players, microwave oven, robotics, etc.) as well as industrial and automobile areas. The 8051 is the first microcontroller of the MCS-51 family developed by Intel Corporation in 1980. It was developed using N-type Metal-Oxide-Semiconductor (NMOS) technology and later it came to be identified by a letter C in their names e.g. 80C51 which was developed with TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL Complementary Metal-Oxide-Semiconductor (CMOS) technology which consumes less power than NMOS and made it better compatible for battery-powered applications. Microcontrollers can be classified on the basis of their bit processing capability e.g. 8-bit microcontroller means it can read, write, and process 8-bit data. Basically, it specifies the size of the data bus. Today microcontrollers are designed with much more compact, cheap, and powerful specifications like AVR and PIC. Memory transfer in microcontrollers involves moving data between different memory locations or between memory and the processor's registers. This process is crucial for executing instructions, storing variables, and handling input/output operations. Microcontrollers typically use various addressing modes and instructions to efficiently manage data movement within their memory architecture. Memory Types: RAM (Random Access Memory): Volatile memory used for storing data that changes during program execution. It's used for variables, intermediate results, and temporary data storage. ROM (Read-Only Memory)/Flash Memory: Non-volatile memory that stores the program instructions and constants that don't change. It retains data even when the power is off. EEPROM (Electrically Erasable Programmable Read-Only Memory): Non-volatile memory that can be erased and reprogrammed, often used for storing settings or configuration data that needs to be persistent but can be updated. Data Transfer Instructions: Load Instructions: Move data from a memory location to a register within the microcontroller. Store Instructions: Move data from a register to a memory location. Immediate Instructions: Load constant values directly into registers. Addressing Modes: Direct Addressing: Accesses data using a fixed memory address. Indirect Addressing: Accesses data using the address stored in a register. Indexed Addressing: Accesses data using a base address plus an offset. Relative Addressing: Accesses data relative to the current instruction pointer. TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL Memory Access Mechanisms: Buses: Microcontrollers use address, data, and control buses to facilitate memory transfers. DMA (Direct Memory Access): A hardware mechanism that allows data transfer between memory locations without CPU intervention, improving efficiency for large data transfers. Program Counter (PC): A register that points to the memory address of the next instruction to be executed. Stack Pointer (SP): A register used to manage the stack, a region of memory used for temporary data storage during function calls and interrupts. Example (8051 Microcontroller): MOV A, @R0: This instruction moves the byte of data stored at the memory location pointed to by register R0 into the accumulator (A). MOVX A, @DPTR: This instruction moves the byte of data stored at the external memory location pointed to by the DPTR (Data Pointer) register into the accumulator. MOVC A, @A+DPTR: This instruction adds the contents of the accumulator to the DPTR, and then moves the byte of data stored at the calculated address in program memory into the accumulator, according to Scribd. In essence, memory transfer in microcontrollers is a fundamental process that enables the execution of instructions and the manipulation of data, allowing them to perform a wide range of tasks. Procedure: 1. Open Keil μVision IDE. 2. Create a new project and select the target device (e.g., 8051). 3. Add a new .c file depending on the program. 4. Write the code and save the file. 5. Simulate using Debug → Start/Stop Debug Session. 6. Use watch window/memory window to observe the data transfer. 7. Verify correct execution of memory operations. 8. Attach screenshot of result window. TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL Sample Program: #include <reg51.h> // Header file for 8051 microcontroller void main(void) { // Declare and initialize source array with 10 values unsigned char source[10] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20}; // Declare destination array (empty) to copy data into unsigned char destination[10]; // Variable for loop counter unsigned char i; // Copy each element from source[] to destination[] for(i = 0; i < 10; i++) { destination[i] = source[i]; // Memory-to-memory transfer } while(1); // Infinite loop to keep program running } TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL Conclusion: ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- Questions: 1. List out some of the features of the 8051? 2. Write down the Steps to create project using Keil software. 3.Draw and Explain RAM Memory organisation of 8051. TE (2019 Pattern)/SEM - II I / Microcontroller Lab - 304188 ADYPSOE/ E&TC /LAB MANUAL Program: TE (2019 Pattern)/SEM - II I / Microcontroller Lab - 304188 ADYPSOE/ E&TC /LAB MANUAL Result : TE (2019 Pattern)/SEM - II I / Microcontroller Lab - 304188 ADYPSOE/ E&TC /LAB MANUAL TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL 4.2 Experiment No. 2 Aim: Parallel port interacting of LEDS—Different programs (flashing, Counter, BCD, HEX, Display of Characteristic) Problem Statement: To study and implement LED interfacing with the 8051 microcontrollers by connecting LEDs to a parallel port and developing programs in Keil for flashing, binary counting, BCD, HEX, and ASCII character display, and verify the output using Proteus simulation. Objective: 1. To understand parallel port programming of 8051. 2.To study hardware interfacing of LEDs with 8051. 3. To implement software routines for LED pattern generation. 4. To learn simulation of embedded systems using Keil and Proteus. 5. To interpret LED outputs as binary, BCD, HEX, and ASCII values. Outcomes: Students will able to 1.Demonstrate parallel port programming of the 8051 microcontroller for digital output applications. 2.Interface LEDs with 8051 and verify their operation through hardware connections and simulations. 3.Develop and execute software routines to generate various LED patterns. Apparatus / Software Required: PC with Windows OS Keil μVision IDE Proteus 8051 DEVELOPMENT BOARD (DVK) Theory: All 8051 microcontrollers have 4 I/O (P0, P1, P2, and P3) ports each comprising 8 bits which can be configured as inputs or outputs. Accordingly, in total of 32 input/output pins enabling the microcontroller to be connected to peripheral devices are available for use. Pin configuration, i.e. whether it is to be configured as an input (1) or an output (0), depends on its logic state. In order to configure a microcontroller pin as an output, it is necessary to TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL apply logic zero (0) to appropriate I/O port bit. In this case, voltage level on appropriate pin will be 0. Similarly, in order to configure a microcontroller pin as an input, it is necessary to apply a logic one (1) to appropriate port. In this case, voltage level on appropriate pin will be 5V (as is the case with any TTL input). 1. LED (Light emitting diode) A light-emitting diode (LED) is a two-lead semiconductor light source. It is a p-n junction diode, which emits light when activated. If LEDs are connected with common cathode (connect cathode of all LEDs to ground), then logic_1'has to be written to make LED ON. And If LEDs are connected with common anode (connect anode of all LEDs to VCC), then logic O'has to be written to make LED ON. Following diagram shows 8 LED connections to PIC Microcontroller. IO PORTS: 8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as input or output. Hence, total 32 input/output pins allow the microcontroller to be connected with the peripheral devices. Pin configuration, i.e. the pin can be configured as 1 for input and 0 for output as per the logic state. Procedure: Software Setup 1.Open Keil μVision and create new project for 8051. 2.Write C code for each program (Flashing, Counter, BCD, HEX, ASCII). 3.Compile and generate .hex file. 4.Open Proteus, place components 8051 and LEDs. 5.Load the generated hex file into the 8051. 6.Run the simulation and observe LED patterns. Hardware Setup- SETTING FOR 8051 DEVELOPMENT BOARD (DVK) 1. Connect +12V supply to board. 2. Connect the USB Cable to the micro controller Kit and select COM port of the PC. 3. Switch ON the power supply. 4. Open Prog ISP Flashing Software on PC. Select the IC (AT89S52). 5. Select given LED sw hex File -> click on Load Flash. Select the HEX file. Click on Auto Button. This uploads HEX file into microcontroller shown by green bar. 6. Connect 10 pin FRC Cables. Press RESET and observe output. 7.Attach screenshot of result window. TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL Sample Program: 1) Flashing LED #include <reg51.h> // Header file for 8051 microcontroller #include <stdio.h> // Standard I/O library (not mandatory here) // Variable to hold LED status (initially all OFF) unsigned char led_status = 0x00; // Delay function (software delay using nested loops) void delay() { int i, j; for(i = 0; i < 1000; i++) { for(j = 0; j < 1000; j++) { // Do nothing, just waste time } } } void main() { P1 = led_status; // Send initial LED status (all OFF) to Port 1 while(1) // Infinite loop (program runs continuously) { P1 = led_status; // Output led_status on Port 1 (LED pattern) // If all LEDs are ON (0xFF), reset to 0x00 (all OFF) if(led_status == 0xFF) led_status = 0x00; else led_status = led_status + 1; // Increment LED pattern step by step delay(); // Call delay to make LED change visible } } 2) BCD #include<reg51.h> #include<stdio.h> unsigned char led_status=0x00; void delay() { int i,j; for(i=0;i<1000;i++) {for(j=0;j<1000;j++) { } } } void main() { P1=led_status; TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL while(1) { P1=led_status; if(led_status==0xFF) led_status=0x00; else led_status=led_status+1; delay(); } } 3) Hex #include<reg51.h> void delay(void); void main(void) { Unsigned char bnum[16]={0x00,0x01,0x04,0x65,0x10,0x11,0x14,0x15,0x40,0x41,0x44,0x45,0x50,0x51,0x 54,0x55}; while(1) { int i; for(i=0;i<16;i++) { P1=bnum[i]; delay(); } } } void delay(void) { int i; for(i=0;i<10000;i++); } TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL Conclusion: ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- Questions: 1.Why do we need resistors while connecting LEDs to 8051? 2.What is the difference between BCD and HEX representations? 3. How many LEDs can be directly connected to one 8051 ports? TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL 4.3 Experiment No. 3 Aim: Interfacing of Stepper motor to 8051- software delay using Timer Problem Statement: Design and implement a system to rotate a stepper motor clockwise and anti-clockwise by generating proper excitation sequences from the 8051’s parallel port, using timer delay routines in Keil μVision, and verify through Proteus simulation. Objective: 1.To study interfacing of stepper motor with 8051 microcontroller. 2.To generate control signals for stepper motor coils using port pins. 3.To implement full-step sequence with timer-based software delay. 4.To observe clockwise and anti-clockwise rotations. 5.To simulate and verify the program in Keil and Proteus. Outcome: Students will able to 1.Demonstrate interfacing of a stepper motor with the 8051 microcontroller using port pins. 2.Generate appropriate control signals for energizing the stepper motor coils. 3.Implement a full-step sequence for motor rotation using timer-based software delay. 4.Control the direction of rotation (clockwise and anti-clockwise) through programming. 5.Simulate and verify stepper motor operation using Keil μVision for coding and Proteus for circuit simulation. Apparatus / Software Required: PC with Windows OS Keil μVision IDE Proteus 8051 DEVELOPMENT BOARD (DVK) Stepper motor card Theory: Stepper Motor: TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL A stepper motor is an electric motor whose main feature is that its shaft rotates by performing steps, that is, by moving by a fixed amount of degrees. This feature is obtained by the internal structure of the motor, and allows to know the exact angular position of the shaft by simply counting how may steps have been performed, with no need for a sensor. This feature also makes it fit for a wide range of applications. It is a brushless, synchronous electric motor that can divide a complete rotation into a number of steps. Stepper motors generally have a permanent magnet shaft (rotor), and it is surrounded by a stator. A stepper motor rotates at small angles to complete 360 degrees rotation, these small angles are called steps, hence the name Stepper Motor. A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements or steps. This motor divides a full rotation of 360 degrees into a number of equal steps. A stepper motor is an electromechanical device that moves in discrete steps depending on the excitation of its windings. The 8051 alone cannot drive the motor directly because of current limitations, so a driver IC (ULN2003) is used. Stepper Motor Working: The motor has multiple stator windings energized in a sequence. Each pulse moves the motor by a step angle (e.g., 1.8° or 7.5°). By controlling the sequence of excitation, direction and speed can be controlled. Excitation Sequence (Full Step, 4-phase motor): Step Coil Sequence (P2.0–P2.3) Hex Value Rotation 1 1000 0x08 CW 2 0100 0x04 CW 3 0010 0x02 CW 4 0001 0x01 CW For Anti-clockwise, reverse the sequence. Timer Delay: 8051 has Timer0 and Timer1 (16-bit). By loading appropriate values in TH0 and TL0, fixed delays can be generated. Procedure: Software Setup Using Keil for writing the C program and Proteus for simulating the setup: TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL 1. Keil C Program: o Configure the 8051 timer for generating delays. o Write a function to rotate the stepper motor using the half-step sequence. 2. Proteus Simulation: o Place the 8051 microcontroller on the schematic. o Add the ULN2003A driver IC. o Add the stepper motor. o Connect the 8051 ports to the ULN2003A inputs. o Connect the ULN2003A outputs to the stepper motor coils. o Configure the power supply for the stepper motor. Steps in Proteus: 1. Add Components: o 8051 microcontroller. o ULN2003A IC. o Stepper motor. o Power supply. o Oscillator (for 8051). Hardware Setup- SETTING FOR 8051 DEVELOPMENT BOARD (DVK) 1.Connect +12V supply to board. 2. Connect the USB Cable to the micro controller Kit and select COM port of the PC. 3. Switch ON the power supply. 4. Open Prog ISP Flashing Software on PC. Select the IC (AT89S52). 5. Select given.hex File -> click on Load Flash. Select the HEX file. Click on Auto Button. This uploads HEX file into microcontroller shown by green bar. 6. Connect 10 pin FRC Cables to the stepper motor section of the DVK kit. 7. Press start switch then increment. You can change the direction of motor by pressing REV switch for keyboard. You can start or stop the motor by pressing the START or STOP keys. 8.Connect Motor card at RL4 on DVK BOARD. 9.Connect Jumpers Settings For stepper motor JP6, JP7 – 2 & 3 short. FRC CONNECTION: J2 - J14 J3 – J15 TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL Sample Program: #include<reg51.h> void delay(unsigned int); sbit sw =P3^1; void main(void) { P2=0X00; while(1) { if(sw==0) { P2=0X03; delay(100); P2=0X06; delay(100); P2=0X0C; delay(100); P2=0X09; delay(100); } else { P2=0X09; delay(100); P2=0X0C; delay(100); P2=0X06; delay(100); P2=0X03; delay(100); } } } void delay(unsigned int m) { unsigned int i,j; for(i=0;i<m;i++) { for(j=0;j<1275;j++); } } TE (2019 Pattern)/SEM-III/ Microcontroller Lab - 304188 ADYPSOE/E&TC/LAB MANUAL Conclusion: ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- Questions: 1.What is the difference between full-step and half-step excitation? 2.How is clockwise and anti-clockwise rotation achieved?