Interfacing Explained
1) LED Interfacing with 8051 Microcontroller
LED interfacing is a fundamental concept to understand how microcontrollers control
output devices. The 8051 microcontroller has parallel I/O ports used to connect LEDs.
Working Principle: Each pin of the 8051 can act as an output pin. When a logic low (0) is
sent to an LED connected through a current-limiting resistor to Vcc, the LED turns ON.
Sending logic high (1) turns it OFF.
Connection:
- Anode (+) of LED to Vcc via 330Ω resistor.
- Cathode (-) to a port pin (e.g., P1.0).
- To glow LED, set port bit to 0.
Program Flow:
1. Set port direction as output.
2. Send 0 to turn ON the LED.
3. Send 1 to turn OFF the LED.
4. Use delay for blinking.
Example Code:
#include<reg51.h>
sbit LED = P1^0;
void delay() {
int i, j;
for(i=0; i<1000; i++)
for(j=0; j<1275; j++);
}
void main() {
while(1) {
LED = 0;
delay();
LED = 1;
delay();
}
}
2) Keyboard Interfacing with 8051 Microcontroller
A 4x4 matrix keyboard is often used for input. Rows are connected to output pins and
columns to input pins.
Working:
1. Microcontroller sends 0 to one row.
2. It reads columns to detect keypress.
3. If a column reads 0, key is pressed.
Flow:
1. Initialize port.
2. Send 0 to each row and scan columns.
3. Detect pressed key.
4. Use delay for debounce.
Example Code:
#include <reg51.h>
void main() {
while(1) {
P1 = 0xFE; // Row 1 LOW
if(P1 != 0xFE) {
// Key Pressed
}
}
}
3) Traffic Light Interfacing with 8086 Microprocessor
Used to control RED, YELLOW, and GREEN LEDs. Implemented using timers and delays.
Control Logic:
1. GREEN ON (10s)
2. YELLOW ON (2s)
3. RED ON (10s)
4. Repeat
Interface: LEDs via decoder or output port (e.g., 8255 PPI).
Pseudocode:
MOV AL, 01H ; Green ON
OUT PORT, AL
CALL DELAY
MOV AL, 02H ; Yellow ON
OUT PORT, AL
CALL DELAY
MOV AL, 04H ; Red ON
OUT PORT, AL
CALL DELAY
4) Finding Largest Number in an Array (8086 Assembly)
Steps:
1. Load count in CX
2. Load first element in AL
3. Compare with other elements
4. Update AL if greater
Code:
MOV CX, 05H
LEA SI, ARRAY
MOV AL, [SI]
INC SI
LOOP1:
CMP AL, [SI]
JAE NEXT
MOV AL, [SI]
NEXT:
INC SI
LOOP LOOP1
AL contains the largest number.
5) Arithmetic in Microprocessor (8086)
Addition:
MOV AL, 05H
ADD AL, 03H ; AL = 08H
Subtraction:
MOV AL, 09H
SUB AL, 04H ; AL = 05H
Multiplication:
MOV AL, 02H
MOV BL, 03H
MUL BL ; AX = 06H
Division:
MOV AX, 0006H
MOV BL, 02H
DIV BL ; AL = 03H, AH = 0
Use AX for results in MUL and dividend in DIV.