Extend PIC Microcontroller‘s RAM by without using EMI

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

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