8051 MC BT-1-LAPTOP-LJ7D0M7S

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

8051 Microcontroller Manual

Hardware Description Of 8051

 Introduction:
The Intel 8051 is a 8-bit microcontroller introduced in 1980, renowned for its
versatility and reliability with 4KB of on-chip program memory and 128 bytes of data
memory, it's suitable for various applications. The 8051 features 32 I/O lines, two 16-
bit timers, and a serial communication port. Power-saving modes reduce energy
consumption. The 8051 has been widely adopted in embedded systems, robotics,
industrial control, and consumer electronics. Its low cost, ease of use, and flexibility
have made it a popular choice. The 8051 remains a fundamental component in many
applications. Its legacy continues, with modern variants offering enhanced features.
The 8051's impact on the microcontroller industry is still significant today. The 8051
is microcontrollerold microcontroller but still the 8051 plays an important role in
market.

 What is microcontroller:
It is a CPU on a single chip. It is execute only single task at a time. It can be used fir
small applications. Processing speed is low and consumes les power(3.3v,5v).It is less
expensive and all are with limited size.

 Why 8051 as the basic in embedded systems:


Starting with the 8051microcontroller as the basic in embedded systems provides a
solid foundation for understanding computer architecture, microcontroller core, and
programming skills. It introduces fundamental concepts such as registers, memory
organization, input/output operations, interrupts, timers, and serial communication,
which are crucial in real-time systems. The 8051 is widely used in various
applications, from simple robots to complex industrial control systems, and its
knowledge remains valuable for embedded systems engineers. Its relatively simple
architecture and instruction set make it an ideal starting point for beginners. Learning
the 8051 provides a timeless understanding of microcontroller fundamentals,
programming skills, and embedded systems concepts, making it easier to transition to
more advanced topics and microcontrollers. By mastering the 8051, one can build a
strong foundation in embedded systems and be well-prepared to tackle complex
projects and newer microcontrollers.

 Features of 8051 microcontroller:


1. 8-bit CPU: 8-bit ALU, 8-bit registers, and 8-bit data bus.

2. 4KB ROM: On-chip program memory for storing program instructions.

3. 128 bytes RAM: On-chip data memory for storing data temporarily.

4. 32 I/O lines: Four 8-bit ports (P0-P3) for input/output operations.

5. Two 16-bit timers: Timer 0 and Timer 1 for timing and counting applications.

6. UART: Universal Asynchronous Receiver-Transmitter for serial communication.

7. On-chip oscillator: Generates clock signal for the microcontroller.

8. Power-saving modes: Idle and power-down modes to reduce power consumption.

9. Interrupts: Supports interrupts for efficient handling of events.

10. Stack: 8-level stack for storing return addresses and data.

11. Arithmetic and logical operations: Supports basic arithmetic and logical
operations.

12. Bit manipulation: Supports bit-level operations.

13. Programmable counter array: PCA (Programmable Counter Array) for custom
counter applications.

14. Analog-to-digital converter: Optional ADC (Analog-to-Digital Converter) for


converting Analog signals to digital.

15. Low power consumption: Suitable for battery-powered devices.

16. High-speed execution: Fast instruction execution for real-time applications.

17. Multitasking: Supports multitasking for multiple tasks execution.

18. Priority interrupts: Supports priority interrupts for critical task handling.

 PIN description of 8051:


 Port 0 (P0) - 8 pins:
P0.0 (Pin 39): Bidirectional I/O pin, also used as AD0 (Address/Data bus)
P0.1 (Pin 38): Bidirectional I/O pin, also used as AD1 (Address/Data bus)
P0.2 (Pin 37): Bidirectional I/O pin, also used as AD2 (Address/Data bus)
P0.3 (Pin 36): Bidirectional I/O pin, also used as AD3 (Address/Data bus)
P0.4 (Pin 35): Bidirectional I/O pin, also used as AD4 (Address/Data bus)
P0.5 (Pin 34): Bidirectional I/O pin, also used as AD5 (Address/Data bus)
P0.6 (Pin 33): Bidirectional I/O pin, also used as AD6 (Address/Data bus)
P0.7 (Pin 32): Bidirectional I/O pin, also used as AD7 (Address/Data bus)

 Port 1 (P1) - 8 pins:


P1.0 (Pin 1): Bidirectional I/O pin
P1.1 (Pin 2): Bidirectional I/O pin
P1.2 (Pin 3): Bidirectional I/O pin
P1.3 (Pin 4): Bidirectional I/O pin
P1.4 (Pin 5): Bidirectional I/O pin
P1.5 (Pin 6): Bidirectional I/O pin
P1.6 (Pin 7): Bidirectional I/O pin
P1.7 (Pin 8): Bidirectional I/O pin

 Port 2 (P2) - 8 pins


P2.0 (Pin 21): Bidirectional I/O pin, also used as A8 (Address bus)
P2.1 (Pin 22): Bidirectional I/O pin, also used as A9 (Address bus)
P2.2 (Pin 23): Bidirectional I/O pin, also used as A10 (Address bus)
P2.3 (Pin 24): Bidirectional I/O pin, also used as A11 (Address bus)
P2.4 (Pin 25): Bidirectional I/O pin, also used as A12 (Address bus)
P2.5 (Pin 26): Bidirectional I/O pin, also used as A13 (Address bus)
P2.6 (Pin 27): Bidirectional I/O pin, also used as A14 (Address bus)
P2.7 (Pin 28): Bidirectional I/O pin, also used as A15 (Address bus)

 Port 3 (P3) - 8 pins


P3.0 (Pin 10): Bidirectional I/O pin, also used as RXD (Serial Input)
P3.1 (Pin 11): Bidirectional I/O pin, also used as TXD (Serial Output)
P3.2 (Pin 12): Bidirectional I/O pin, also used as INT0 (External Interrupt 0)
P3.3 (Pin 13): Bidirectional I/O pin, also used as INT1 (External Interrupt 1)
P3.4 (Pin 14): Bidirectional I/O pin, also used as T0 (Timer 0 Input)
P3.5 (Pin 15): Bidirectional I/O pin, also used as T1 (Timer 1 Input)
P3.6 (Pin 16): Bidirectional I/O pin, also used as WR (Write Signal)
P3.7 (Pin 17): Bidirectional I/O pin, also used as RD (Read Signal)

 Control Signals - 6 pins


RST (Pin 9): Active low reset input
ALE (Pin 30): Output pulse for latching address
PSEN (Pin 29): Output pulse for enabling external program memory
EA (Pin 31): Input pin for enabling/disabling external memory access
XTAL1 (Pin 19): Input pin for crystal oscillator
XTAL2 (Pin 18): Output pin for crystal oscillator

 Power and Ground - 4 pins


VCC (Pin 40): Positive power supply input
GND (Pin 20): Ground connection
VSS (Pin 20): Negative power supply input (not always used)

 Architecture of 8051:

 Input Pins
1. RST (Pin 40): Active low reset input. When this pin is low, the microcontroller is reset.
2. EA (Pin 37): Input pin for enabling/disabling external memory access.
3. INT0 (Pin 3): External interrupt 0 input.
4. INT1 (Pin 5): External interrupt 1 input.
5. T0 (Pin 4): Timer 0 input.
6. T1 (Pin 3): Timer 1 input.
7. RXD (Pin 8): Serial input.

Output Pins:
1. P0.0 - P0.7 (Pins 32-25): 8-bit bidirectional I/O port.
2. P1.0 - P1.7 (Pins 24-17): 8-bit bidirectional I/O port.
3. P2.0 - P2.7 (Pins 16-9): 8-bit bidirectional I/O port.
4. P3.0 - P3.7 (Pins 8-1): 8-bit bidirectional I/O port.
5. ALE (Pin 39): Output pulse for latching address.
6. PSEN (Pin 38): Output pulse for enabling external program memory.
7. TXD (Pin 7): Serial output.
8. WR (Pin 2): Write signal output.
9. RD (Pin 1): Read signal output.

 Bidirectional Pins:
1. P0.0 - P0.7 (Pins 32-25): Can be used as input or output.
2. P1.0 - P1.7 (Pins 24-17): Can be used as input or output.
3. P2.0 - P2.7 (Pins 16-9): Can be used as input or output.
4. P3.0 - P3.7 (Pins 8-1): Can be used as input or output.

#include <reg51.h>

// Define pins for LED and Button


sbit LED = P1^0; // LED connected to P1.0
sbit Button = P1^1; // Button connected to P1.1

void delay(unsigned int time) {


unsigned int i, j;
for (i = 0; i< time; i++)
for (j = 0; j < 1275; j++);
}

void main(void) {
// Set initial state
LED = 0; // Turn off LED (assuming active high)
Button = 1; // Set button pin as input (high state)

while (1) {
// Check if the button is pressed
if (Button == 0) { // Active low, so 0 means pressed
LED = 1; // Turn on LED
delay(500); // Wait for some time
LED = 0; // Turn off LED
delay(500); // Debounce delay
}
}
}

Explanation:

Header File (reg51.h): This includes the standard definitions for the 8051
microcontroller.

sbit: This keyword defines single-bit access to specific pins. sbit LED = P1^0; defines
LED as the first pin of Port 1, and sbit Button = P1^1; defines Button as the second pin of
Port 1.

delay: A simple delay function to create a delay between operations. The actual time
delay depends on the microcontroller's clock speed.

main function: This function is the entry point of the program.


 Initially, the LED is turned off, and the button is set as an input (high state).
 In the while (1) loop, the code continuously checks if the button is pressed (Button ==
0). If the button is pressed, the LED is turned on, and a delay is added. Then, the LED
is turned off, followed by another delay to debounce the button.

 Timers and counters:

Timer is a specialized type of clock which is used to measure time intervals. A timer that
counts from zero upwards for measuring time elapsed is often called a stopwatch. It is a
device that counts down from a specified time interval and used to generate a time delay,
for example, an hourglass is a timer.

The 8051microcontoller have 2 timers that is


 TIMER 0
 TIMER 1
The 8051 has two timers, Timer 0 and Timer 1. They can be used as timers or as event
counters. Both Timer 0 and Timer 1 are 16-bit wide. Since the 8051 follows an 8-bit
architecture, each 16 bit is accessed as two separate registers of low-byte and high-byte.

 TIMER 0:
The 16-bit register of Timer 0 is accessed as low and high-byte. The low-byte register is
called TL0 (Timer 0 low byte) and the high-byte register is called TH0 (Timer 0 high byte).
These registers can be accessed like any other register. For example, the instruction MOV
TL0, #4H moves the value into the low-byte of Timer #0.

 Timer 0 Overview:
16-bit timer/counter
Can be used as a timer or counter
Can generate interrupts on overflow
Can be used in various modes (see below)

 Timer 0 Modes:
o Mode 0: 13-bit Timer (TH0 = 0)
Timer runs for 13 bits (0-8191)
Then resets to 0
o Mode 1: 16-bit Timer (TH0 = 1)
Timer runs for 16 bits (0-65535)
Then resets to 0
o Mode 2: 8-bit Auto-Reload (TH0 = 2)
Timer runs for 8 bits (0-255)
Then reloads with value in TH0
o Mode 3: Split-Timer (TH0 = 3)
Timer 0 is split into two 8-bit timers (TL0 and TH0)

 Timer 0 Registers
TL0 (Timer 0 Low): Lower 8 bits of Timer 0
TH0 (Timer 0 High): Upper 8 bits of Timer 0

 Timer 0 Control Bits


TF0 (Timer 0 Overflow Flag): Set when Timer 0 overflows
TR0 (Timer 0 Run Control): Starts/stops Timer 0

 Timer 0 Interrupt
TF0 (Timer 0 Overflow Interrupt): Generated when Timer 0 overflows

 Timer 0 Clock
Fosc/12: Timer 0 clock frequency (default)
Fosc/4: Timer 0 clock frequency (when T0M bit is set)

 TIMER 1:

The 16-bit register of Timer 1 is accessed as low- and high-byte. The low-byte register is
called TL1 (Timer 1 low byte) and the high-byte register is called TH1 (Timer 1 high
byte). These registers can be accessed like any other register. For example, the
instruction MOV TL1, #4H moves the value into the low-byte of Timer 1.
 Timer 1 Overview:
16-bit timer/counter
Can be used as a timer or counter
Can generate interrupts on overflow
Can be used in various modes (see below)

 TMOD Registers:
Both Timer 0 and Timer 1 use the same register to set the various timer operation modes.
It is an 8-bit register in which the lower 4 bits are set aside for Timer 0 and the upper four
bits for Timers. In each case, the lower 2 bits are used to set the timer mode in advance
and the upper 2 bits are used to specify the location.

Gate − When set, the timer only runs while INT(0,1) is high.
C/T − Counter/Timer select bit.
M1 − Mode bit 1.
M0 − Mode bit 0.

 GATE
Every timer has a means of starting and stopping. Some timers do this by software, some by
hardware, and some have both software and hardware controls. 8051 timers have both
software and hardware controls. The start and stop of a timer is controlled by software using
the instruction SETB TR1 and CLR TR1 for timer 1, and SETB TR0 and CLR TR0 for
timer 0.
The SETB instruction is used to start it and it is stopped by the CLR instruction. These
instructions start and stop the timers as long as GATE = 0 in the TMOD register. Timers can
be started and stopped by an external source by making GATE = 1 in the TMOD register.
 C/T (CLOCK / TIMER)
This bit in the TMOD register is used to decide whether a timer is used as a delay
generator or an event manager. If C/T = 0, it is used as a timer for timer delay generation.
The clock source to create the time delay is the crystal frequency of the 8051. If C/T = 0, the
crystal frequency attached to the 8051 also decides the speed at which the 8051 timer ticks at
a regular interval.
Timer frequency is always 1/12th of the frequency of the crystal attached to the 8051.
Although various 8051 based systems have an XTAL frequency of 10 MHz to 40 MHz, we
normally work with the XTAL frequency of 11.0592 MHz. It is because the baud rate for
serial communication of the 8051.XTAL = 11.0592 allows the 8051 system to communicate
with the PC with no errors.

 Modes of operation:

 Different Modes of Timers:

 Mode 0 (13-Bit Timer Mode):


Both Timer 1 and Timer 0 in Mode 0 operate as 8-bit counters (with a divide-by-32
prescaler). Timer register is configured as a 13-bit register consisting of all the 8 bits of TH1
and the lower 5 bits of TL1. The upper 3 bits of TL1 are indeterminate and should be ignored.
Setting the run flag (TR1) does not clear the register. The timer interrupt flag TF1 is set when
the count rolls over from all 1s to all 0s. Mode 0 operation is the same for Timer 0 as it is for
Timer 1.
 Mode 1 (16-Bit Timer Mode):
Timer mode "1" is a 16-bit timer and is a commonly used mode. It functions in the same way
as 13-bit mode except that all 16 bits are used. TLx is incremented starting from 0 to a
maximum 255. Once the value 255 is reached, TLx resets to 0 and then THx is incremented
by 1. As being a full 16-bit timer, the timer may contain up to 65536 distinct values and it
will overflow back to 0 after 65,536 machine cycles.
 Mode 2 (8 Bit Auto Reload):
Both the timer registers are configured as 8-bit counters (TL1 and TL0) with automatic
reload. Overflow from TL1 (TL0) sets TF1 (TF0) and also reloads TL1 (TL0) with the
contents of Th1 (TH0), which is preset by software. The reload leaves TH1 (TH0)
unchanged.
The benefit of auto-reload mode is that you can have the timer to always contain a value from
200 to 255. If you use mode 0 or 1, you would have to check in the code to see the overflow
and, in that case, reset the timer to 200. In this case, precious instructions check the value
and/or get reloaded. In mode 2, the microcontroller takes care of this. Once you have
configured a timer in mode 2, you don't have to worry about checking to see if the timer has
overflowed, nor do you have to worry about resetting the value because the microcontroller
hardware will do it all for you. The auto-reload mode is used for establishing a common baud
rate.
 Mode 3 (Split Timer Mode):
Timer mode "3" is known as split-timer mode. When Timer 0 is placed in mode 3, it
becomes two separate 8-bit timers. Timer 0 is TL0 and Timer 1 is TH0. Both the timers count
from 0 to 255 and in case of overflow, reset back to 0. All the bits that are of Timer 1 will
now be tied to TH0.
When Timer 0 is in split mode, the real Timer 1 (i.e. TH1 and TL1) can be set in modes 0, 1
or 2, but it cannot be started/stopped as the bits that do that are now linked to TH0. The real
timer 1 will be incremented with every machine cycle.

 PROGRAM FOR TIMERS:


Toggle LED over flow program using timer 0 and timer 1:

#include <reg51.h>

void main() {
// Initialize Timer 0
TMOD = 0x01; // Mode 1 (16-bit timer) for Timer 0
TH0 = 0x3C; // Load high byte for Timer 0
TL0 = 0xFF; // Load low byte for Timer 0
TR0 = 1; // Start Timer 0

// Initialize Timer 1
TMOD |= 0x10; // Mode 1 (16-bit timer) for Timer 1
TH1 = 0x3C; // Load high byte for Timer 1
TL1 = 0xFF; // Load low byte for Timer 1
TR1 = 1; // Start Timer 1

while(1) {
// Wait for Timer 0 overflow
while(!TF0);
TF0 = 0; // Clear overflow flag
P1 ^= 0x01; // Toggle LED connected to P1.0

// Wait for Timer 1 overflow


while(!TF1);
TF1 = 0; // Clear overflow flag
P2 ^= 0x01; // Toggle LED connected to P2.0
}
}

 Explanation about above programs:


This program initializes and uses both Timer 0 and Timer 1 in the 8051 microcontroller
to toggle LEDs connected to Port 1 and Port 2.

Timer 0 Initialization:

1. TMOD = 0x01; - Sets Timer 0 to Mode 1 (16-bit timer)


2. TH0 = 0x3C; - Loads the high byte (0x3C) into Timer 0
3. TL0 = 0xFF; - Loads the low byte (0xFF) into Timer 0
4. TR0 = 1; - Starts Timer 0

Timer 1 Initialization:

1. TMOD |= 0x10; - Sets Timer 1 to Mode 1 (16-bit timer)


2. TH1 = 0x3C; - Loads the high byte (0x3C) into Timer 1
3. TL1 = 0xFF; - Loads the low byte (0xFF) into Timer 1
4. TR1 = 1; - Starts Timer 1

Main Loop:

The program enters an infinite loop, where it:

1. Waits for Timer 0 overflow (while(!TF0);)


2. Clears the Timer 0 overflow flag (TF0 = 0;)
3. Toggles the LED connected to Port 1 (P1 ^= 0x01;)
4. Waits for Timer 1 overflow (while(!TF1);)
5. Clears the Timer 1 overflow flag (TF1 = 0;)
6. Toggles the LED connected to Port 2 (P2 ^= 0x01;)

Explanation:

The program uses both Timer 0 and Timer 1 to generate periodic interrupts, which
toggle LEDs connected to Port 1 and Port 2. The timers are set to Mode 1 (16-bit timer)
and loaded with the same values (0x3C and 0xFF). The program waits for each timer to
overflow, clears the overflow flag, and toggles the corresponding LED.

 Counters:
A counter is a device that stores (and sometimes displays) the number of times aparticular
event or process occurred, with respect to a clock signal. It is used to count the
eventhappening outside the microcontroller. In electronics, counters can be implemented
quite easily using register-type circuits such as a flip-flop.

PROGRAM:

#include <reg51.h> // Header file for 8051 microcontroller

void main(void) {
// Initialize Timer 0 in 16-bit counter mode
TMOD = 0x06; // Set Timer 0 as a 16-bit counter (mode 2)
TR0 = 1; // Start Timer 0

while (1) {
unsigned char lowByte = TL0; // Read lower byte of the counter
unsigned char highByte = TH0; // Read higher byte of the counter

// You can add code here to process the counter value


// For example, you could send the counter value to a display

// This example will just store the value for further processing
unsigned int counterValue = (highByte << 8) | lowByte;

// Process the counter value as needed


// For example, you could check if a certain number of pulses have been counted
}
}

 Serial port:

A serial port is a communication interface through which information is transferred in or


out one bit at a time (in contrast to parallel ports, where multiple bits are transferred
simultaneously). Serial ports are used for serial communication, where data is sent
sequentially over a communication channel or computer bus.

Connecting a modem to a computer for dial-up internet access


Connecting a printer or plotter to a computer
Connecting sensors or other devices to a computer for data acquisition
Debugging and programming microcontrollers
Types of Serial Ports:

1. UART (Universal Asynchronous Receiver/Transmitter):


Function: UART handles asynchronous communication without a clock signal. Data
integrity is maintained through start, stop, and parity bits.
Application: Used in RS-232, RS-485, and TTL serial communication.
Baud Rate: Configurable, typically ranges from 9600 to 115200 bps.

2. USART (Universal Synchronous/Asynchronous Receiver/Transmitter):


Function: USART supports both synchronous (with a clock) and asynchronous
communication.
Application: Versatile for various communication protocols.
Synchronization: Can use a clock line for synchronized data transfer.

3. SPI (Serial Peripheral Interface):


Function: A synchronous protocol using separate lines for data in, data out, clock,
and chip select.
Application: High-speed communication with sensors, SD cards, and other peripherals.
Full-Duplex: Allows simultaneous data transmission and reception.

4. I2C (Inter-Integrated Circuit):


Function: A multi-master, multi-slave, synchronous protocol using two lines (SDA
and SCL).
Application: Communicating with sensors, memory chips, and I/O devices.
Addressing: Devices are identified by unique addresses.

5. RS-232:
Function: A standard for serial communication transmission of data.
Application: Common in computer serial ports and older communication equipment.
Voltage Levels: ±12V signaling levels.

6. RS-485:
Function: An enhanced version of RS-232 for multi-point systems.
Application: Industrial automation and networking.
Differential Signaling: Provides better noise immunity and longer distance.

Serial Port Communication Parameters

1. Baud Rate:
Definition: Number of signal changes per second.
Impact: Higher baud rates increase data transfer speed but may reduce reliability over
long distances.

2. Data Bits:
Common Values: 7 or 8 bits.
Usage: Determines the size of the data payload in each frame.
3. Parity Bit:
Types: None, Even, Odd.
Purpose: Used for error detection.

4. Stop Bits:
Common Values: 1 or 2 bits.
Function: Indicates the end of a data packet, ensuring correct synchronization.

5. Flow Control:
Types: Hardware (RTS/CTS), Software (XON/XOFF).
Usage: Prevents data overflow by managing data transmission speed.

Serial Port Operation

1. Initialization:
Configuration: Set baud rate, data bits, parity, and stop bits.
Enabling: Turn on UART/USART modules in the microcontroller.

2. Transmission:
Data Register: Load data into the transmit data register.
Transmission Complete Flag: Check for completion before sending the next byte.

3. Reception:
Data Register: Read data from the receive data register.
Buffer Overrun: Ensure the receive buffer is read before new data arrives to avoid
overflow.

PROGRAM:

#include <reg51.h> // Include the register definitions for the 8051

void UART_Init(void) {
// Set up the serial port for 8-bit UART mode
SCON = 0x50; // 0101 0000b: 8-bit UART, mode 1, REN enabled

// Set baud rate (assuming 11.0592 MHz crystal frequency)


TMOD = 0x20; // Timer 1 in Mode 2 (8-bit auto-reload)
TH1 = 0xFD; // Baud rate 9600: 256 - (11.0592 MHz / (32 * 12 * 9600)) = 253
TL1 = 0xFD; // Same value for TL1

// Start Timer 1
TR1 = 1;

// Enable serial port


ES = 1; // Enable serial interrupt
EA = 1; // Enable global interrupt
}

void UART_SendChar(char c) {
SBUF = c; // Load character into the buffer
while (TI == 0); // Wait until transmission is complete
TI = 0; // Clear the transmit interrupt flag
}

char UART_ReceiveChar(void) {
while (RI == 0); // Wait until data is received
RI = 0; // Clear the receive interrupt flag
return SBUF; // Return received character
}

void main(void) {
UART_Init(); // Initialize UART

while (1) {
char received_char = UART_ReceiveChar(); // Receive a character
UART_SendChar(received_char); // Echo the received character
}
}

 Branch Instruction In 8051 :


 This instruction is used to control the flow of execution of the program.
 This instruction is also called “Jump Instruction”.
 The branching instruction in the 8051 microcontroller are responsible for performing
this operation. Task like looping, calling delay and conditional execution of code can
be performed using these branching instruction.
 Branch instruction are divided into two types
1. Unconditional Jump Instruction.
2. Conditional Jump Instruction.

 Unconditional Jump Instruction:


 A jump to a new location from where the program continues execution is executed.
 There are three types.
1. Short Jump(SJMP)
2. Long Jump(LJMP)
3. Absolute Jump(AJMP)

 Short Jump:
 Syntax of short jump is SJMP Addr8.
1.
2. One byte is apcode SJMP.
3. Another one is operand addr8.
 The range of address in short jump is -128 to +127.

 Long Jump:-
 Syntax of long jump is LJMP addr16.
 The size of long jump is 3byte.
1. One byte is apcode LJMP.
2. Another two bytes are operand addr16.
 The range of address in long jump is 0000 to FFFF.

 Absolute Jump:-
 Syntax of Absolute jump is AJMP addr11.
 The size of Absolute jump is 2byte.
1. One byte is apcode AJMP.
2. Another byte is operand addr11.

 Conditional Jump Instruction:


 A jump to a new program location is executed only if a specified condition is met.
 Here the all conditional jumps are short jumps, meaning that the address of the target
must be within -128 to 127 bytes of the contest of the program.
 There are 8 jump instructions.
1. JZ Instruction.
2. JNZ Instruction.
3. JC Instruction.
4. JNC Instruction.
5. JB Instruction.
6. JNB Instruction.
7. DJNZ Instruction.
8. CJNE Instruction.

 JZ Instruction Target:
 JZ means jump if zero.
 The content in the accumulator is the zero then it jumps to the target address is known
as JZ instruction. If A = 0.

 JNZ Instruction Target:


 JNZ means jump if not zero.
 The content in the accumulator is not a zero then it jumps to the target address is
known as JNZ instruction. If A != 0.

 JC Instruction Target:
 JC means jump if carry.
 If carry flag is high then it jumps to target address is known as JC instruction. If CY =
1.

 JNC Instruction Target:


 JNC means jump if no carry.
 If carry flag is not high then it jumps to target address is known as JNC instruction. If
CY = 0.

 JB Instruction:
 JB means jump if bit.
 If bit is high then jump to target address is known as JB instruction. If B = 1.

 JNB Instruction:
 JNB means jump if not bit.
 If bit is not high then it jump to target address is known as JNB instruction. If B = 0.

 DJNZ Instruction:
 Decrement jump if not zero.
 After doing decrement the result will be zero then it jumps to target is known as
DJNZ instruction.

 CJNE Instruction:
 CJNE means compare jump if not equal.
 After both source byte and destination byte are comparing if there are not equal then
it jumps to target is known as CJNE instruction.

 I/O Ports Programming:


I/O Ports Programming refers to the process of controlling and accessing input/output
devices connected to a microcontroller or computer using programming languages and
techniques. Here's a brief overview:

 I/O Ports:

Input Ports: Receive data from external devices (e.g., sensors, switches).
- Output Ports: Send data to external devices (e.g., LED 's, displays).

Programming Techniques:

1. Bit Manipulation: Directly access and manipulate individual bits or groups of bits within a
port.
2. Port Addressing: Use specific addresses to access and control I/O ports.
3. Register-Level Programming: Use registers to control and monitor I/O ports.

Programming Languages:
1. Assembly Language: Low-level, symbolic representation of machine code.
2. C/C++: High-level languages with libraries and functions for I/O port access.
3. Microcontroller-Specific Languages: Languages like Arduino's IDE, PIC BASIC, or AVR
Studio.

Example (8051 Microcontroller):

- P1 = 0xFF; // Set all pins of Port 1 as output and high


- P2 |= 0x01; // Set pin 0 of Port 2 as output and high (bitwise OR)
- if (P3 & 0x02) { ... } // Check if pin 1 of Port 3 is high (bitwise AND)

You might also like