Skip to content

Latest commit

ย 

History

50 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฎ PIC Float Division Calculator

Project Logo Microcontroller Simulation


๐Ÿ“‘ Table of Contents


๐Ÿ“– Project Overview

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).

๐ŸŽฏ Key Features

  • 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

๐Ÿ—๏ธ System Architecture

๐Ÿ”ง Hardware Components

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

๐Ÿ–ฅ๏ธ Component Layout

Master CPU (16F877A)

  • PORTB.0: Push Button Input
  • PORTD: LCD Interface (4-bit mode)
  • PORTC: USART Communication
  • MCLR: 10Kฮฉ Pull-up

Slave CPU (16F877A)

  • PORTC: USART Communication
  • PORTD: Status LEDs (Optional)
  • MCLR: 10Kฮฉ Pull-up

LCD Display (16ร—2)

  • 4-bit Data Mode: D4-D7 โ†’ PORTD.4-7
  • Control Pins: RS, EN โ†’ PORTD.2-3
  • RS Pull-up: 4.7Kฮฉ resistor

๐Ÿ“ท Hardware Components Gallery

๐Ÿ”ง Individual Components

PIC16F877A Microcontroller 16ร—2 LCD Display Push Button 4MHz Crystal
PIC16F877A LCD 16x2 Push Button Crystal 4MHz
Main processing unit User interface display Input interface System clock source
Pull-up Resistors Capacitors (15pF)
Resistors Capacitors
4.7Kฮฉ & 10Kฮฉ values Crystal oscillator caps

๐Ÿ”Œ Complete Circuit Design

Complete Circuit Design

Complete Proteus simulation schematic showing the dual PIC16F877A architecture with Master-Slave communication, LCD interface, push button input, and all supporting components including crystals, resistors, and capacitors.


๐Ÿ”„ System Operation Flow

๐Ÿ“ฑ User Interface Flow

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
Loading

๐Ÿค Master-Slave Communication Protocol

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
Loading

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

๐Ÿ’ป Software Architecture

๐ŸŽ›๏ธ Master CPU Functions

๐Ÿ–ฅ๏ธ Display Management

  • LCD Initialization: 4-bit mode setup
  • Welcome Screen: Blinking animation
  • Number Entry: Cursor positioning
  • Result Display: Formatted output

๐ŸŽฎ Input Handling

  • Button Debouncing: Clean signal processing
  • Timeout Detection: Auto-advance after 1 second
  • Double-Click: Fast navigation
  • Digit Increment: 0-9 cycling

๐Ÿ“ก Communication Protocol

; 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
    RETURN

โš™๏ธ Slave CPU Functions

๐Ÿ”ข Division Algorithm

The 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)

๐Ÿงฎ Key Mathematical Operations

  • Multi-digit Comparison: 13ร—12 number comparison
  • Multi-digit Subtraction: With borrow propagation
  • Fixed-Point Conversion: Integer to 6.6 format

๐Ÿ”ฌ Detailed Division Mechanism

The division algorithm implements a sophisticated decimal long division process designed for high-precision floating-point arithmetic:

๐Ÿ“Š Data Structure & Scaling

; 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)

๐Ÿ”„ Algorithm Flow

  1. 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
  2. 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
  3. 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

๐Ÿงฎ Core Operations

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 LSB

Multi-Digit Subtraction (subtract_13x12_numbers):

; Performs remainder = remainder - divisor
; Implements decimal borrow propagation
; Uses ripple-borrow routines (b_f_h_d_x) for carry handling

Borrow 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 position

๐Ÿ“ˆ Example Calculation

Input: 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]

๐Ÿ› ๏ธ Development Environment

๐Ÿ“‹ Prerequisites

  • MPLAB IDE: PIC development environment
  • Proteus: Circuit simulation software
  • PIC16F877A: Target microcontroller knowledge

๐Ÿ”ง Build Instructions

  1. Clone Repository

    git clone https://github.com/osaidnur/PIC-Float-Division-Calculator.git
    cd PIC-Float-Division-Calculator
  2. MPLAB Setup

    • Open master/master.mcp for Master CPU project
    • Open slave/slave.mcp for Slave CPU project
    • Build both projects to generate .hex files
  3. Proteus Simulation

    • Open Circuit.pdsprj
    • Load master.hex into Master PIC16F877A
    • Load slave.hex into Slave PIC16F877A
    • Run simulation

๐ŸŽฎ Usage Instructions

๐Ÿš€ Getting Started

  1. Power Up: System displays welcome message
  2. Number Entry: Use push button to increment digits
  3. Navigation:
    • Single Click: Increment current digit
    • Wait 1 second: Advance to next digit
    • Double Click: Skip to decimal part or next number
  4. Calculation: Automatic after second number entry
  5. Result Viewing: Button cycles through result/numbers

๐Ÿ“Š Input Format

  • Range: 0.000001 to 999999.999999
  • Precision: 6 decimal places
  • Format: NNNNNN.DDDDDD (6 integer + 6 decimal)

๐ŸŽฌ Demonstration

๐Ÿ“น Simulation Video

sample_run.mp4

๐Ÿ“ธ Screenshots

Welcome Screen

Welcome Screen System startup with blinking welcome message

Number Entry

Number Entry Interactive digit entry with cursor

Result Display

Result Display Final result with formatting


๐Ÿ“ Project Structure

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

๐Ÿ”ฌ Technical Specifications

โšก Performance Metrics

  • 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

๐ŸŽฏ Algorithm Complexity

  • 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

๐Ÿ‘ฅ Contributors

๐ŸŒŸ Meet Our Amazing Team


Ahmad Hussin

Moath Wajeeh

Moaid Karakra

Osaid Nur

๐Ÿค Team Collaboration Stats

Contributors Code Lines


๐Ÿ“œ License

This project is licensed under the Apache License - see the LICENSE file for details.


About

Assembly project implementing a floating-point division calculator using PIC16F877A microcontroller.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages