On this page
Half Adder Implementation
This program implements a half adder using the 8051 microcontroller, demonstrating basic digital logic operations.
Description
A half adder adds two single bits and produces a sum and carry output:
- Inputs: Port 1 (A) and Port 0 (B)
- Outputs:
- Sum on P2.0
- Carry on P3.0
Code
| |
Explanation
Sum Calculation (A XOR B)
- MOV A, P1: Load input A
- MOV R1, P0: Load input B into R1
- XRL A, R1: XOR operation (A ⊕ B) gives the sum
- RRC A: Rotate right through carry to get LSB
- MOV P2.0, C: Output sum bit to P2.0
Carry Calculation (A AND B)
- MOV A, P1: Load input A again
- MOV R1, P0: Load input B into R1
- ANL A, R1: AND operation (A • B) gives the carry
- RRC A: Rotate right through carry to get LSB
- MOV P3.0, C: Output carry bit to P3.0
The program continuously reads inputs and updates outputs in an infinite loop.