EIT-M
ELECTRICAL AND COMPUTER ENGINNERING
STREAM OF COMPUTER
EMBEDDED INDIVIDUAL ASSIGNMENT
NAME ID
DAWIT SIRAK EIT-M/UR158093/11
SUBMITTED TO: INS. NEGASI
SUBMISION DATE 05/09/2017 EC
Microso
[Compa
[Date]
PIC16F877 Microcontroller — Full Memory
Organization
The memory system of the PIC16F877 is divided into three main types:
Memory Type Function
Program Memory (FLASH) ----- Stores your code (instructions)
Data Memory (RAM) -------- Stores temporary data (variables, flags)
EEPROM Memory --------- Stores permanent user data (even after power off)
Each one has its own size, access method, and purpose.
Let's explain each one now:
1. 📄 Program Memory (FLASH Memory)
➔ Purpose:
It stores the compiled instructions of your program (like MOVLW, ADDWF, etc).
Microcontroller reads program memory to know what to execute.
➔ Size:
14 KB (8K x 14 bits).
o 8,192 words (each word = 14 bits).
➔ Structure:
RESET Vector at address 0x0000
o When microcontroller resets (power on or reset button), it starts executing from
here.
1
Interrupt Vector at address 0x0004
o If an interrupt happens, it jumps to this address.
➔ Memory Paging:
Divided into 4 Pages (Page 0 to Page 3).
Each page holds part of your program.
If your program is big and crosses into another page, you have to manage the pages.
Page Number Address Range
Page 0 0x0000 to 0x07FF
Page 1 0x0800 to 0x0FFF
Page 2 0x1000 to 0x17FF
Page 3 0x1800 to 0x1FFF
🔵 Program Counter (PC):
A 13-bit register inside PIC that points to the current instruction address in program memory.
2. 🧠 Data Memory (RAM / SRAM)
➔ Purpose:
Used during program execution for:
o Storing variables.
o Temporary storage.
o Working registers.
o Stack for subroutine calls.
o SFRs (Special Function Registers) to control peripherals (like I/O ports, timers,
ADC).
➔ Size:
2
368 bytes of RAM available.
➔ Organized into Banks:
Because RAM is limited, it’s divided into four banks:
Bank Address Range Contents
Bank 0 0x00 - 0x7F GPRs + SFRs
Bank 1 0x80 - 0xFF GPRs + SFRs
Bank 2 0x100 - 0x17F GPRs + SFRs
Bank 3 0x180 - 0x1FF GPRs + SFRs
➔ Inside Each Bank:
1. GPR (General Purpose Registers)
o For your program variables.
o Example: storing a counter, flags, temporary results.
2. SFR (Special Function Registers)
o These control microcontroller hardware.
o Example:
PORTA – Controls Port A pins.
TMR0 – Timer0 Register.
STATUS – Processor status (Zero flag, Carry flag, Bank Select bits).
➔ Bank Switching
Since all SFRs don't fit in one bank, you have to switch banks when needed.
Controlled by two bits in the STATUS register:
o RP1 and RP0.
RP1 RP0 Bank
0 0 Bank 0
0 1 Bank 1
3
RP1 RP0 Bank
1 0 Bank 2
1 1 Bank 3
Example:
If you want to access TRISB (data direction register for Port B), you must first switch to Bank
1.
assembly
BSF STATUS, RP0 ; Set RP0=1 (Bank 1)
BCF STATUS, RP1 ; Set RP1=0 (Bank 1)
➔ Stack Memory
Stack is hardware-managed in PIC16F877.
Used for saving return addresses when you call a function (CALL instruction).
Depth: 8 levels (fixed).
No PUSH or POP instructions; only automatic.
3. 💾 EEPROM Memory
➔ Purpose:
To permanently store data even if the power is switched off.
Used for:
o Passwords.
o Calibration data.
o Configuration settings.
➔ Size:
4
256 bytes EEPROM.
➔ Access:
EEPROM access is special:
o You must write to certain registers (EECON1, EECON2, EEADR, etc).
o There are specific steps to read/write EEPROM to prevent accidental writes.
(You must write two specific instructions sequence before EEPROM write is accepted.)
🧠 Final Overall Diagram (Text Version)
+------------------------------------+
| Program Memory |
| 14 KB FLASH (8K x 14 bits) |
| Pages (0,1,2 ,3), Reset, Interrupts |
+------------------------------------+
+------------------------------------+
| Data Memory |
| 368 bytes RAM (SRAM) |
| Banks (0,1 ,2, 3): GPRs + SFRs |
| Stack (8-level) |
+------------------------------------+
+------------------------------------+
| EEPROM Memory |
| 256 bytes Permanent Data Storage |
| Special read/write steps required |
+------------------------------------+
🎯 Important Points Summary
Concept Notes
Program Memory Holds the program, 14 bits wide instructions.
Data Memory Divided into banks, needs bank switching.
EEPROM Permanent storage, needs special handling.
Stack 8 levels deep, hardware managed.
Bank Switching Done with RP1 and RP0 bits in STATUS register.
🔥 Quick Example
5
Suppose you write a PIC program:
It will be stored in Program Memory.
When you define variables (int x;), they are stored in Data Memory (RAM).
If you save a setting like a device password, you store it into EEPROM.