Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
The 8051 microcontroller has an 8-bit Here are five addressing modes of the i) MOV A, @R0: This instruction
: This instruction moves
data bus and a 16-bit address bus. 8051 microcontrollers: the content of the memory location The step angle of a stepper motor Immediate Addressing Mode: pointed to by the value in register R0 into refers to the angular distance the rotor In immediate addressing, the operand the accumulator A. It is an example of (output shaft) of the motor moves with (data) is directly specified in the indirect addressing. each step of the motor. instruction. For example, MOV A, #25H ii) CPL bit: CPL stands for complement, the special function register (SFR) moves the immediate value 25H into the and this instruction complements (flips) used to keep track of the priority of accumulator. the state of a specified bit. For example, interrupts is often referred to as the Register Addressing Mode: CPL P1.2 complements the state of bit 2 "Interrupt Priority Register" (IPR) Register addressing involves specifying a in port 1. In LCDs (Liquid Crystal Displays), the register as the operand. For instance, iii) DJNZ R2, Next: DJNZ stands for contrast is often controlled using a MOV A, B moves the content of register B "Decrement and Jump if Not Zero." It variable resistor (potentiometer) into the accumulator. decrements the value in register R2 and connected to a specific pin called the Direct Addressing Mode: jumps to the specified label (Next) if the "contrast" or "V0" pin. Direct addressing mode involves result is not zero. Two commonly used assembler specifying the memory address directly. iv) RR A: RR stands for "Rotate Right directives for the 8051 For example, MOV A, 30H moves the through Carry." This instruction rotates microcontrollers are: 1) ORG (Origin): content of the memory location 30H into the bits in the accumulator A one position This directive is used to specify the origin the accumulator. to the right through the carry flag. or starting address for the code or data in Indirect Addressing Mode: v) SUBB A, B: SUBB stands for "Subtract memory. 2) DB (Define Byte): This In indirect addressing, the address of the with Borrow." This instruction subtracts directive is used to define one or more operand is held in a register or memory the value in register B from the bytes of data and store them in memory. location. For instance, MOV A, @R0 accumulator A, taking into account the "C/T" (Counter/Timer) bit in the TMOD moves the content of the memory location borrow from the previous subtraction if (Timer Mode) register is used to select pointed to by the value in register R0 into the carry flag is set. between Timer or Counter mode for the the accumulator. Here are five features of the 8051 associated timer (Timer 0 or Timer 1). Indexed Addressing Mode: microcontroller: pins on the 8051 microcontrollers Indexed addressing involves specifying a Harvard Architecture: explanation of the functions of the base address and an offset. For example, The 8051 microcontroller employs a mentioned: MOV A, 20H+R1 moves the content of Harvard architecture, which means it has i) ALE (Address Latch Enable): the memory location calculated by adding separate memory spaces for program ALE is used to enable the external latch 20H and the value in register R1 into the and data. This architecture enhances the for the address bus, allowing the accumulator. Understanding these performance and efficiency of the microcontroller to latch the most addressing modes is crucial for effective microcontroller. significant address byte during the 1st programming and utilization of the 8051 On-Chip RAM and ROM: machine cycle. microcontroller's capabilities. The 8051 comes with on-chip RAM ii) PSEN (Program Store Enable): Write 8051 C - program to generate 4 (Random Access Memory) for data PSEN is an active-low signal that kHz square wave on port pin P1.2 storage and on-chip ROM (Read-Only indicates the microcontroller is accessing using timer 0 in auto reload mode? Memory) for program storage. This external program memory. When PSEN [Assume XTAL = 12 MHz] integrated memory simplifies the design is low, it signifies a fetch operation for an #include <reg51.h> of microcontroller-based systems. instruction from external program // Define crystal frequency Multiple I/O Ports: memory. #define XTAL_FREQ 12000000UL The 8051 has multiple I/O ports, including iii) EA (External Access): // Function to provide a delay P0, P1, P2, and P3. These ports can be EA, when grounded (0), enables the void delay(unsigned int count) { configured for various input and output microcontroller to fetch code from unsigned int i, j; operations, providing versatility in external memory. If EA is left for (i = 0; i < count; i++) interfacing with external devices. unconnected or tied high (Vcc), the for (j = 0; j < 1275; j++); Four Parallel I/O Ports: microcontroller fetches code from its } The microcontroller features four parallel internal ROM. void main() { I/O ports (P0, P1, P2, and P3), each with iv) RESET: // Configure Timer 0 in mode 2 (auto- 8 bits. These ports can be used for The RESET pin is used to reset the reload) interfacing with external devices, sensors, microcontroller. When a high-to-low TMOD = 0x02; and other peripherals. transition is detected on this pin, the // Calculate Timer 0 reload value for a Integrated Serial Communication: microcontroller is reset, and program 4 kHz square wave The 8051 microcontroller includes a execution starts from the beginning. // Reload Value = (65536 - UART (Universal Asynchronous A stepper motor is a type of (XTAL_FREQ / (2 * desired_frequency))) Receiver/Transmitter) for serial electromechanical device that converts // In this case, desired_frequency = communication. This feature facilitates electrical pulses into precise mechanical 4000 Hz communication with other devices, such motion. It moves in discrete steps, and TH0 = 0xFC; as sensors, displays, or communication each step corresponds to a specific TL0 = 0x66; modules. angular rotation. Stepper motors are // Set P1.2 as output These features make the 8051 widely used in various applications, P1 = P1 & 0xFB; microcontroller widely used in embedded including robotics, CNC machines, 3D // Start Timer 0 systems due to its versatility, ease of use, printers, and automation systems, due to TR0 = 1; and integrated peripherals. their accuracy and ability to control while (1) { position and speed effectively. They are // Toggle P1.2 to generate a square driven by providing a sequence of wave electrical pulses to their coils, causing P1_2 = ~P1_2; them to step incrementally and rotate. // Provide a small delay for the square wave frequency delay(1); } } The 8051 microcontroller has four register The TCON (Timer Control) register in banks (Bank 0 to Bank 3), each the 8051 microcontroller plays a crucial containing registers like ACC role in controlling the behaviour of Timer (Accumulator), B, DPTR (Data Pointer), 0 and Timer 1. Here are three key and other general-purpose registers. aspects of the TCON register: These banks allow efficient context Timer 0 and Timer 1 Control: TCON is switching during subroutine calls, divided into two parts, one for Timer 0 enabling the microcontroller to quickly (TF0, TR0, IE0, and IT0) and the other for switch between different sets of registers Timer 1 (TF1, TR1, IE1, and IT1). These to support multitasking and optimize control bits determine the operation, register utilization in program execution. interrupt enable, and interrupt type for In 8051 C programming, the common each timer. data types include: Timer Overflow Flag (TF): The TF bit is int: The 'int' data type is used to represent set when either Timer 0 or Timer 1 integer values. It typically occupies 16 overflows, indicating that the specified bits in 8051 programming. time period has elapsed. Programmers Char: 'char' stands for character and is can check this flag to determine when a used to represent a single byte or timer has completed its counting cycle. character in 8051 C programming. External Interrupt Control (IE0 and IE1): unsigned char: Similar to 'char,' but it is TCON includes bits IE0 and IE1, which used for representing only positive are used for controlling external interrupts values, allowing a range of 0 to 255. associated with Timer 0 and Timer 1, float: 'float' is used for representing respectively. When enabled, these bits floating-point numbers, which include allow external signals to trigger interrupts. decimal points. However, 8051 C compilers may have limited support for floating-point operations. Logical instructions in microcontroller programming involve operations on binary data, manipulating bits based on logical conditions. Here are three key logical instructions: AND (Logical AND): The AND instruction performs a bitwise AND operation between each pair of corresponding bits in two operands. The result is stored in the destination operand, setting bits to 1 only if both corresponding bits in the source operands are 1. OR (Logical OR): The OR instruction performs a bitwise OR operation between each pair of corresponding bits in two operands. The result is stored in the destination operand, setting bits to 1 if at least one corresponding bit in the source operands is 1. XOR (Logical Exclusive OR): The XOR instruction performs a bitwise exclusive OR operation between each pair of corresponding bits in two operands. The result is stored in the destination operand, setting bits to 1 if the corresponding bits in the source operands are different.