Extend PIC Microcontroller‘s RAM by without using EMI

Summary of Extend PIC Microcontroller‘s RAM by without using EMI


This article describes a simple external SRAM interface for PIC microcontrollers to extend RAM (tested on PIC16F877/887 and PIC18F4550/4620). It uses 64K x 8 24512 SRAM chips, a 74HC373 latch to extend 8-bit to 16-bit addressing, and a 74HC138 demultiplexer for bank selection. The post provides C functions with inline assembly to write to and read from selected memory banks, allowing up to 192KB (expandable to 448KB) of external RAM using banked addressing.

Parts used in the Extend PIC Microcontroller‘s RAM by without using EMI:

  • PIC microcontrollers (examples: PIC16F877, PIC16F887, PIC18F4550, PIC18F4620)
  • 24512 64K x 8 CMOS SRAM modules
  • 74HC373 8-bit latch
  • 74HC138 demultiplexer (memory bank selector)
  • Microcontroller I/O ports (PORTB, PORTC, PORTD referenced in code)

Introduction

Virtually all PIC microcontrollers have some banking mechanism to extend addressing to additional memory space. But this external data memory is not directly addressable (except in some high versions of PIC18 devices, which include PIC18F8520, PIC18F6620, etc.). In this post we describe easy to implement external memory interface for PIC microcontrollers. Theoretically most of the PIC microcontrollers can use this setup to extend its RAM space. At the prototyping stage we test this system with PIC16F877, PIC16F887, PIC18F4550 and PIC18F4620 microcontrollers.Extend PIC Microcontroller‘s RAM by without using EMI

Schematic

With this given schematic user may be able to address RAM space up to 192KB. But this can be extended up to 448KB by adding more SRAM modules to the system.
In this given setup we use 24512 – 64K x 8 CMOS SRAMs as a memory modules. 74HC373 latch is used as 8bit to 16bit address extender and 74HC138 demultiplexer is used as memory bank selector.

Function to write data to the external memory bank

//=========================================
=====================================
// Function to write data to the external memory bank
// Input parameters:
//   bank: Memory band number. Valid range is between 1 to 7. 0 for no bank.
//   address: Memory address to write.
//   value: Value to write
// Return:
//   none
//======================================
========================================
void WriteExMem(char bank, unsigned int address, char value) {
asm {
clrf TRISD
clrf TRISB
movlw 0xe0
andwf TRISC, 1
movlw 0xc3
andwf PORTC, 1
nop
nop
movf FARG_WriteExMem_address+1, 0
movwf PORTD
movlw 0xfd
andwf PORTC, 1
nop
nop
bsf PORTC, 1
movf FARG_WriteExMem_address, 0
movwf PORTD
movf FARG_WriteExMem_value, 0
movwf PORTB
nop
nop
movlw 0xfe
andwf PORTC, 1
movf FARG_WriteExMem_bank, 0
movwf R0
rlcf R0, 1
bcf R0, 0
rlcf R0, 1
bcf R0, 0
movf R0, 0
iorwf PORTC, 1
nop
nop
bsf PORTC, 0
movlw 0xe3
andwf PORTC, 1
}
}

Function to read data from external memory bank

//=========================================
=====================================
// Function to read data from external memory bank
// Input parameters:
//   bank: Memory band number. Valid range is between 1 to 7. 0 for no bank.
//   address: Memory address to read.
// Return:
//   Data value
//========================================
======================================

Extend PIC Microcontroller‘s RAM by without using EMI schematic
char ReadExMem(char bank, unsigned int address) {
asm {
clrf TRISD
movlw 0xff
movwf TRISB
movlw 0xe0
andwf TRISC, 1
movlw 0xc3
andwf PORTC, 1
nop
nop
movf FARG_ReadExMem_address+1, 0
movwf PORTD
movlw 0xfd
andwf PORTC, 1
nop
nop
bsf PORTC, 1
movf FARG_ReadExMem_address, 0
movwf PORTD
movf FARG_ReadExMem_bank, 0
movwf R0
rlcf R0, 1
bcf R0, 0
rlcf R0, 1
bcf R0, 0
movf R0, 0
iorwf PORTC, 1
nop
nop
movf PORTB, 0
movwf R1
movlw 0xe3
andwf PORTC, 1
movf R1, 0
movwf R0
}
}

 

For more detail: Extend PIC Microcontroller‘s RAM by without using EMI

Quick Solutions to Questions related to Extend PIC Microcontroller‘s RAM by without using EMI:

  • What is the purpose of the 74HC373 in this project?
    The 74HC373 latch is used as an 8bit to 16bit address extender.
  • What role does the 74HC138 play?
    The 74HC138 demultiplexer is used as the memory bank selector.
  • Which SRAM module is used in the setup?
    The setup uses 24512 64K x 8 CMOS SRAM modules.
  • How much external RAM can this schematic address by default?
    The given schematic can address up to 192KB of RAM.
  • Can the system be expanded beyond 192KB?
    Yes, it can be extended up to 448KB by adding more SRAM modules.
  • Which PIC microcontrollers were tested with this system?
    The system was tested with PIC16F877, PIC16F887, PIC18F4550 and PIC18F4620.
  • How does the WriteExMem function select the bank and address?
    The WriteExMem function uses PORTD for address lines, PORTB for data, and manipulates PORTC bits to control latches and bank selection per the inline assembly.
  • How does the ReadExMem function obtain data from external memory?
    The ReadExMem function configures PORTB as input, sets PORTD with the address, selects the bank via PORTC, then reads data from PORTB into a register and returns it.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter