# rotronica/pic_16f877a_buffer_mux_ms architecture

> Architecture diagram of the GitHub repository rotronica/pic_16f877a_buffer_mux_ms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rotronica/pic_16f877a_buffer_mux_ms
- Repository: https://github.com/rotronica/pic_16f877a_buffer_mux_ms

## Overview

##### Project type and purpose
- This is an embedded-firmware project written in C for a Microchip PIC16F877A microcontroller.
- Its sole purpose is to multiplex four seven-segment displays so they can show a scrolling/static message (“HOLA LIAM”) by updating one display at a time every 5 ms.

##### File structure
- README.md – high-level description of how the multiplexing works, timing, masks, etc.
- Source_Code.c – the main C source implementing millis(), visualizar_display(), data buffers, and port operations
- fusibles.h – PIC configuration-bits definitions (oscillator, watchdog, etc.)

There are no “frontend/backend” folders—everything lives in one flat directory because it’s a single MCU application. No build scripts, no OS, no external services.

##### README for additional insights
- It explains how visualizar_display() is called repeatedly (probably from main() in a loop or a timer interrupt).
- It shows how PORTA (PINES_MUX) and PORTD (PUERTO_VISUALIZADOR) are manipulated with bit masks and shifts.
- It defines constants: MUX_TIME = 5 ms, DISPLAY_MASK = 0x0F, NUM_DISPLAYS = 4, plus the DATOS[] lookup table for segment patterns.

##### Detail
- Port names (PORTA, PORTD), mask values (0x0F), constants (MUX_TIME = 5 ms, NUM_DISPLAYS = 4).
- Fusible settings (oscillator speed) near the Timer block to show how the timebase is derived.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Hardware Boundary"
        direction TB
        CPU["PIC16F877A CPU Core"]:::hardware
        subgraph "Peripherals"
            direction TB
            Timer["Timer0 → millis()"]:::software
            ConfigBits["Configuration Bits (oscillator, watchdog)"]:::data
        end
        subgraph "I/O Ports"
            direction TB
            PortsSegment["PORTD (segment-data lines)"]:::hardware
            PortsMux["PORTA bits 0–3 (digit-select)"]:::hardware
        end
    end

    subgraph "Software Logic"
        direction TB
        Decision{"(now – last_mux) ≥ MUX_TIME?"}:::logic
        StateMachine["State Machine: visualizar_display()"]:::software
        DisplayBuffer["Display Buffer & DATOS[] lookup table"]:::data
    end

    subgraph "Physical Displays"
        direction TB
        Displays["4 × Seven-Segment Displays"]:::hardware
    end

    %% Flow
    Timer -->|"increments counter"| Decision
    Decision -->|yes| StateMachine
    Decision -->|no| Timer
    StateMachine -->|"reads index"| DisplayBuffer
    StateMachine -->|"writes pattern"| PortsSegment
    StateMachine -->|"toggles digit-select"| PortsMux
    PortsMux -->|"controls"| Displays
    StateMachine -->|"display_state = (display_state+1) mod 4"| Decision

    %% Documentation
    README["High-level Documentation"]:::data
    README -.->|describes| Timer

    %% Click Events
    click Timer "https://github.com/rotronica/pic_16f877a_buffer_mux_ms/blob/master/Source_Code.c"
    click StateMachine "https://github.com/rotronica/pic_16f877a_buffer_mux_ms/blob/master/Source_Code.c"
    click DisplayBuffer "https://github.com/rotronica/pic_16f877a_buffer_mux_ms/blob/master/Source_Code.c"
    click ConfigBits "https://github.com/rotronica/pic_16f877a_buffer_mux_ms/blob/master/fusibles.h"
    click README "https://github.com/rotronica/pic_16f877a_buffer_mux_ms/blob/master/README.md"

    %% Styles
    classDef software fill:#AED6F1,stroke:#2471A3,stroke-width:1px
    classDef hardware fill:#ABEBC6,stroke:#1D8348,stroke-width:1px
    classDef data fill:#F4F6F6,stroke:#7B7D7D,stroke-width:1px
    classDef logic fill:#F9E79F,stroke:#B7950B,stroke-width:1px
```
