Skip to content

DanielArndt0/pic-eeprom-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 

Repository files navigation

EEPROM for PIC

EEPROM read/write example for the PIC12F629 and PIC12F675 using MikroC PRO.

Overview

This repository contains a simple and didactic example of how to access the internal data EEPROM of the PIC12F629 and PIC12F675.

The project provides reusable routines for:

  • writing one byte to EEPROM
  • reading one byte from EEPROM
  • validating the EEPROM address range

It is intended as a basic embedded systems example for students, hobbyists, and developers working with PIC microcontrollers.

Platform and Development Environment

  • Microcontrollers: PIC12F629, PIC12F675
  • Language: C
  • IDE: MikroC PRO v7.2.0
  • Clock: 4 MHz

EEPROM Information

The PIC12F629 and PIC12F675 provide:

  • 128 bytes of internal data EEPROM
  • valid address range from 0x00 to 0x7F

Project Structure

src/

  • main.c — example application using the EEPROM routines
  • eeprom.c — EEPROM implementation
  • eeprom.h — EEPROM public interface

docs/

  • PIC12F629.pdf — microcontroller documentation

Features

  • EEPROM byte write routine
  • EEPROM byte read routine
  • address limiting to valid EEPROM range
  • write status return for error handling
  • reusable module split into .h and .c

How It Works

write(unsigned char data, unsigned char address)

Writes one byte to the selected EEPROM address:

  • validates the address range
  • selects data EEPROM access
  • enables write mode
  • temporarily disables global interrupts
  • performs the required unlock sequence
  • starts the write cycle
  • waits until the write operation finishes
  • returns a status code

read(unsigned char address)

Reads one byte from the selected EEPROM address:

  • validates the address range
  • selects data EEPROM access
  • loads the EEPROM address
  • starts the read cycle
  • returns the byte stored in EEDAT

Example Usage

#include "eeprom.h"

void main()
{
    unsigned char value;
    unsigned char status;

    status = write(0x2A, 0x10);

    if (status == EEPROM_WRITE_OK)
    {
        value = read(0x10);
    }

    while (1)
    {
    }
}

Return Values

write(...)

  • EEPROM_WRITE_OK → write completed successfully
  • EEPROM_WRITE_ERROR → write operation failed

Address Range

This implementation supports EEPROM addresses in the following range:

  • 0x00 to 0x7F

If an address above the valid range is passed, it is limited to the maximum valid EEPROM address.

Author

Daniel Gier Arndt

This project is a small embedded systems study/example repository focused on EEPROM access with the PIC12F629 and PIC12F675.

About

EEPROM read/write example for PIC12F629 and PIC12F675 using MikroC PRO.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages