PIC18F
PIC18F
PIC18F
Memory capacity
The number of bits that a
semiconductor memory chip can
store is called chip capacity
Unit = Kbits (kilobits), Mbits (megabits)
Different from storage capacity of
computer systems
Memory capacity of a memory IC chip
= bits
Storage capacity of computer system
= bytes
Memory organization
Memory chips organized into a number of locations
within the IC
Each location can hold 1 bit, 4 bits, 8 bits or even 16 bits.
The number of bits that each location within memory
chip can hold = number of data pins on the chip.
How many location exist inside a memory chip? Depends
on the number of address pins.
The number of locations within a memory IC always
equal 2 ^number of address pins.
The total number of bits that a memory chip can store =
number of locations X number of data bits per location.
Speed
Most important characteristic of memory chip =
speed at which its data can be accessed.
To access the data, the address is presented to the
address pins, the READ pin is activated, and,
after a certain amount of time has elapsed, the
data shows up at the data pins.
The shorter this elapsed time, the better. the
more expensive the memory chip.
The speed of the memory chip is commonly
referred to as its access time. It varies from a
few nanosecond to hundreds of nanosecond.
Example
1) Memory chip has 12 address pins
and 4 data pins. Find:
(a)The organization (b) the capacity
2) A 512K memory chip has 8 pins for
data. Find
(a) The organization (b) number of
address pins for this memory chip.
Types of memory
1) ROM (read Only Memory)
2) PROM (Programmable ROM) and OTP
3) EPROM (Erasable programmable
ROM) and UV-EPROM
4) EEPROM (Electrically Erasable
Programmable ROM)
5) Flash Memory EPROM
6) Mask ROM
1) RAM
2) SRAM
3) NVRAM (Nonvolatile RAM)
4) DRAM(Dynamic RAM)
TBLRD
How to access fixed data residing in
the program ROM spaceof PIC18.
First learn how to store fixed data in
the program ROM space using DB
(define byte) directive.
Program example : Assume the word USA is burned into ROM location
starting at 500H, and that the program is burned into ROM location
starting at 0. Analyze how the program works and state where USA is
stored after this program is run
HERE
ORG 0000H
CLRF TRISB
MOVLW 0X00
MOVWF TBLPTRL
MOVLW 0X05
MOVWF TBLPTRH
TBLRD*
; TABLAT = U char pointed to by TBLPTR.
MOVFF TABLAT,PORTB
INCF TBLPTRL,F ; TBLPTRL =01 pointing to next (501)
TBLRD*
; TABLAT =S char pointed to by TBLPTR
MOVFF TABLAT, PORTB
INCF TBLPTRL, F ; TBLPTRL =02 pointing to next (502)
TBLRD*
;TABLAT =A char pointed to by TBLPTR
MOVFF TABLAT, PORTB
GOTO HERE
Function
Description
TBLWT*
Table Write
TBLWT*+
TBLWT*-
TBLWT+*
Increment TBLPTR
and then write
TBLWR
Writing to
flash
Example Program
Write the message GOOD BYE to Flash
memory starting at location 400H.
And
Reads the data from flash and places
in PORTB one byte at a time.
MOVLW AD
MOVWF TABLAT
TBLWT*+
; Perform short write increment address
MOVLW A ; Load the space into working register
MOVWF TABLAT
TBLWT*+
; Perform short write increment address
MOVLW A B
MOVWF TABLAT
TBLWT*+
; Perform short write increment address
MOVLW A Y
MOVWF TABLAT
TBLWT*+
; Perform short write increment address
MOVLW A E
MOVWF TABLAT
TBLWT*+
; Perform short write increment address
;Read the back one byte at a time and examine the bytes on
PORTB
MOVLW 0X00
MOVWF TBLPTRL
MOVLW 0X04
MOVWF TBLPTRH
CLRF TRISB
MOVLW 0X8
MOVWF COUNT
OVER TBLRD*+ ;Read the byte to TABLAT and increment
MOVFF TABLAT, PORTB
CALL DELAY
DECF COUNT,F
DECFSZ COUNT,F
BRA OVER
C version
#include <p18Cxxx.h>
void Delay(unsigned int itime);
void main()
{
unsigned char x;
//write to program memory
TBLPTR = (short long)0x0400;
TABLAT = G
_asm TBLWTPOSTINC _endasm
TABLAT = O
_asm TBLWTPOSTINC _endasm
TABLAT = O
_asm TBLWTPOSTINC _endasm
TABLAT = D
_asm TBLWTPOSTINC _endasm
//short write
//short write
//short write
//short write
TABLAT =
_asm TBLWTPOSTINC _endasm
TABLAT = B
_asm TBLWTPOSTINC _endasm
TABLAT = Y
_asm TBLWTPOSTINC _endasm
TABLAT = E
_asm TBLWTPOSTINC _endasm
//LONG WRITE
TBLPTR = (short long)0x0400;
EECON1bits.EEPGD =1;
EECON1bits.CFGS =0;
EECON1bits.WREN =1;
EECON1bits.GIE =0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR=1;
_asm NOP _endasm
INTCONbits.GIE = 1;
EECON1bits. WREN = 0;
//short write
//short write
//short write
//short write