- ๐ Project Overview
- ๐๏ธ System Architecture
- ๐ System Operation Flow
- ๐ป Software Architecture
- ๐ ๏ธ Development Environment
- ๐ฎ Usage Instructions
- ๐ฌ Demonstration
- ๐ Project Structure
- ๐ฌ Technical Specifications
- ๐ฅ Contributors
- ๐ License
This project implements a complex floating-point division calculator using two PIC16F877A microcontrollers working in a master-slave architecture. The system can perform division operations on float numbers up to 1 million (10โถ) with decimal precision up to 6 digits (e.g., 999999.999999).
- Dual MCU Architecture: Master-Slave communication using USART
- Floating-Point Precision: 6.6 fixed-point arithmetic (6 integer + 6 decimal digits)
- Interactive Input: Push-button digit entry with timeout and double-click detection
- LCD Display: 16ร2 character display with cursor control
- Hardware Simulation: Complete Proteus simulation environment
| Component | Quantity | Description | Connection |
|---|---|---|---|
| PIC16F877A | 2 | Master CPU & Co-processor | USART Communication |
| 16ร2 LCD | 1 | Character Display | 4-bit mode to Master PORTD |
| Push Button | 1 | Input Interface | Master PORTB.0 |
| 4MHz Crystal | 2 | System Clock | Each MCU |
| Resistors | Various | Pull-up resistors | 4.7Kฮฉ, 10Kฮฉ |
| Capacitors | 4 | Crystal oscillators | 15pF each |
- PORTB.0: Push Button Input
- PORTD: LCD Interface (4-bit mode)
- PORTC: USART Communication
- MCLR: 10Kฮฉ Pull-up
| PIC16F877A Microcontroller | 16ร2 LCD Display | Push Button | 4MHz Crystal |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| Main processing unit | User interface display | Input interface | System clock source |
| Pull-up Resistors | Capacitors (15pF) |
|---|---|
![]() |
![]() |
| 4.7Kฮฉ & 10Kฮฉ values | Crystal oscillator caps |
graph TD
A[System Power Up] --> B[Welcome Screen<br/>Blinks 3 times]
B --> C[Number 1 Entry]
C --> D[Integer Part Entry<br/>6 digits]
D --> E[Decimal Part Entry<br/>6 digits]
E --> F[Number 2 Entry]
F --> G[Integer Part Entry<br/>6 digits]
G --> H[Decimal Part Entry<br/>6 digits]
H --> I[Division Calculation]
I --> J[Display Result]
J --> K{Button Press?}
K -->|Single| L[Cycle Display<br/>Result/Num1/Num2]
K -->|Double| C
L --> K
sequenceDiagram
participant M as Master CPU
participant S as Slave CPU
Note over M,S: Phase 1: Send First Number (12 digits)
M->>S: Digit 0 (MSB)
M->>S: Digit 1
M->>S: Digit 2
Note over M,S: ... (continue for all 12 digits)
M->>S: Digit 11 (LSB)
Note over M,S: Phase 2: Send Second Number (12 digits)
M->>S: Digit 0 (MSB)
M->>S: Digit 1
M->>S: Digit 2
Note over M,S: ... (continue for all 12 digits)
M->>S: Digit 11 (LSB)
Note over M,S: Phase 3: Receive Result (12 digits)
S->>M: Result Digit 0
S->>M: Result Digit 1
S->>M: Result Digit 2
Note over M,S: ... (continue for all 12 digits)
S->>M: Result Digit 11
Communication Details:
- Protocol: Simple USART transmission without acknowledgment
- Baud Rate: 9600 bps
- Data Format: 8-bit, no parity, 1 stop bit
- Timing: 5ms delay between each byte transmission
- Flow: Sequential transmission of 12-digit numbers as individual bytes
- LCD Initialization: 4-bit mode setup
- Welcome Screen: Blinking animation
- Number Entry: Cursor positioning
- Result Display: Formatted output
; Master sends data without acknowledgment
usart_send_byte:
BANKSEL TXSTA
BTFSS TXSTA, TRMT ; Wait for transmit buffer empty
GOTO $-1
BANKSEL TXREG
MOVWF TXREG ; Send byte
RETURN
; Transmission with 5ms delay between bytes
transmit_first_number_to_slave:
CLRF transmit_index
transmit_loop:
MOVF transmit_index, 0
ADDLW digit_array1_0
MOVWF FSR
MOVF INDF, 0
CALL usart_send_byte
CALL delay_5ms ; 5ms delay between transmissions
INCF transmit_index, 1
MOVF transmit_index, 0
SUBLW .12
BTFSS STATUS, Z
GOTO transmit_loop
RETURNThe slave implements a 18ร12 decimal division algorithm:
- Input Scaling: 12-digit dividend โ 18-digit (shifted 6 places)
- Precision: 6.6 fixed-point arithmetic
- Algorithm: Long division with decimal precision
perform_18x12_division:
; Initialize 13-digit working remainder
; Process 18 dividend digits
; Generate 12 quotient digits (6.6 format)- Multi-digit Comparison: 13ร12 number comparison
- Multi-digit Subtraction: With borrow propagation
- Fixed-Point Conversion: Integer to 6.6 format
The division algorithm implements a sophisticated decimal long division process designed for high-precision floating-point arithmetic:
; Input: 12-digit numbers (NNNNNN.DDDDDD format)
; Dividend scaling: 12 โ 18 digits (shift left by 6 decimal places)
; Working remainder: 13 digits for overflow handling
; Final quotient: 12 digits (6.6 fixed-point format)-
Input Preparation:
- Copy 12-digit dividend to upper 12 positions of 18-digit array
- Clear lower 6 positions (equivalent to multiplying by 10^6)
- Initialize 13-digit working remainder to zero
- Set up quotient storage for 12 digits
-
Iterative Division Process:
FOR each of 18 dividend digits: 1. Shift working remainder left by 1 decimal place 2. Bring down next dividend digit 3. Count how many times divisor fits into current remainder 4. Store count as quotient digit (if in quotient range) 5. Subtract (count ร divisor) from remainder
-
Precision Control:
- First 6 iterations: Build integer part of quotient
- Last 12 iterations: Generate quotient digits
- Skip first 5 quotient positions to maintain 6.6 format
Multi-Digit Comparison (compare_13x12_numbers):
; Compares 13-digit working remainder with 12-digit divisor
; Returns: div_compare_result = 1 if remainder โฅ divisor
; Handles digit-by-digit comparison from MSB to LSBMulti-Digit Subtraction (subtract_13x12_numbers):
; Performs remainder = remainder - divisor
; Implements decimal borrow propagation
; Uses ripple-borrow routines (b_f_h_d_x) for carry handlingBorrow Propagation System:
; Example: b_f_h_d_0 through b_f_h_d_11
; Each routine handles borrow from current digit to next higher digit
; Implements fall-through logic for cascading borrows
; Converts negative digits to positive with borrow from next positionInput: 123456.789012 รท 2.000000
1. Scale dividend: 123456.789012 โ 123456789012.000000 (18 digits)
2. Divisor remains: 2.000000 (12 digits as: 2000000000000)
3. Division produces: 61728.394506 (6.6 format)
4. Result transmitted as 12 bytes: [0,6,1,7,2,8,3,9,4,5,0,6]
- MPLAB IDE: PIC development environment
- Proteus: Circuit simulation software
- PIC16F877A: Target microcontroller knowledge
-
Clone Repository
git clone https://github.com/osaidnur/PIC-Float-Division-Calculator.git cd PIC-Float-Division-Calculator -
MPLAB Setup
- Open
master/master.mcpfor Master CPU project - Open
slave/slave.mcpfor Slave CPU project - Build both projects to generate
.hexfiles
- Open
-
Proteus Simulation
- Open
Circuit.pdsprj - Load
master.hexinto Master PIC16F877A - Load
slave.hexinto Slave PIC16F877A - Run simulation
- Open
- Power Up: System displays welcome message
- Number Entry: Use push button to increment digits
- Navigation:
- Single Click: Increment current digit
- Wait 1 second: Advance to next digit
- Double Click: Skip to decimal part or next number
- Calculation: Automatic after second number entry
- Result Viewing: Button cycles through result/numbers
- Range: 0.000001 to 999999.999999
- Precision: 6 decimal places
- Format: NNNNNN.DDDDDD (6 integer + 6 decimal)
sample_run.mp4
PIC-Float-Division-Calculator/
โโโ ๐ README.md # This documentation
โโโ ๐ project4_description.pdf # Original requirements
โโโ ๐ Circuit.pdsprj # Proteus simulation file
โโโ ๐ master/ # Master CPU code
โ โโโ ๐ master.asm # Main assembly source
โ โโโ ๐ master.hex # Compiled hex file
โ โโโ ๐ master.mcp # MPLAB project
โ โโโ ๐ 16f877a_g.lkr # Linker script
โ โโโ ๐ LCDIS.INC # LCD library
โ โโโ ๐ P16F877A.INC # MCU definitions
โโโ ๐ slave/ # Slave CPU code
โ โโโ ๐ slave.asm # Main assembly source
โ โโโ ๐ slave.hex # Compiled hex file
โ โโโ ๐ slave.mcp # MPLAB project
โโโ ๐ Project Backups/ # Automatic backups
โโโ ๐ images/ # Documentation images
- Clock Speed: 4 MHz per MCU
- Communication: 9600 baud USART
- Precision: 6 decimal places
- Response Time: < 2 seconds for division
- Memory Usage: ~80% of available RAM
- Time Complexity: O(nรm) = O(18 ร 12) = = O(216) elementary operations
- Space Complexity: 43 bytes for division variables
- Precision: Maintains 6 decimal places throughout calculation
- Range: Handles dividends up to 999999.999999
- Decimal Operations: BCD-like digit manipulation
- Communication: Interrupt-driven for efficiency
This project is licensed under the Apache License - see the LICENSE file for details.









