|
PROGRAM MEMORY
Page 34
INDEX
Program Memory is the space available for your PROGRAM.
You really don't need to know very much about the amount of memory in a
microcontroller as it is generally larger than you require.
But for the technically minded, here are the details:
Memory consists of pages. A page has 256 locations and these are identified in
hexadecimal as 00 to FF.
The first page of memory is called Page 0. The next page is Page 1 etc.
A PIC12C508A has 2 pages of memory 00 to 1FF. This is 512 locations (actually
511 usable locations as the top location is reserved for oscillator
calibration).
The PIC12C509, PIC16C84, PIC16F84 and PIC16F627 have 4 pages of memory, 00 to
3FF.
This is 1024 locations or 1k of memory.
The PIC16F628 has 2k of memory.
CALL, GOTO and RETURN instructions operate across the full memory for each chip
except CALL for PIC12C508 and PIC12C509. CALL for PIC12C508 and PIC12C509
only allows a CALL to a location that is in the first 0FF (256 locations). This
is the only limiting feature of the PIC12C508A and PIC12C509.
1024 memory locations may seem very small but when you start writing a program,
you will be surprised how many routines can be fitted in.
Each line of code takes up one memory location. The PIC16F628 has 2k locations. This
represents nearly 30 pages if the program is printed on A4 sheets of paper.
Memory is also called MEMORY SPACE, PROGRAM SPACE, PROGRAM AREA,
CODE,
or INSTRUCTIONS.
The following diagram compares the memory of the PIC chips we are covering in
our course:
ADDITIONAL NOTES :
When the frequency of the oscillator of a PIC microcontroller is 4MHz, it takes 1uS to
carry out each instruction. If the instruction causes the micro to go to
another part of the program, the instruction takes 2uS.
A program can be placed anywhere is memory and to do this there is a pseudo
instruction called ORG.
ORG is called a pseudo instruction as it is not burnt into the chip but
tells the assembler where to burn the first instruction in a program.
ORG must have a value associated with it. For instance, ORG 000 will tell the assembler
to place the first real instruction in your program at address 000, when the
chip is burnt.
If you specify ORG 0CC, the following instruction will be placed at memory
location 0CC, when the chip is "burnt".
You can use ORG again in a program to force a particular sub-routine to reside
at a particular location. For example ORG 1AF will force the instruction
MOVLW 01 to be at location 1AF in memory:
ORG 1AF
MOVLW 01
INTERRUPT VECTOR
When a microcontroller is operating in a circuit, an event on a input line can
trigger the micro to perform a particular operation.
This event is called an interrupt and causes the micro to go to location 004 in
memory. An instruction is placed at this location to make the micro go to a
sub-routine to handle the event.
Location 004 is called the Peripheral Interrupt Vector location and
since memory starts at 000, we need to start our program below 004 so that
location 004 can be used at a later time.
The first location in memory is called the RESET Vector. The microcontroller
goes to this location during turn-on and whenever a reset is created.
At memory location 000, an instruction is needed to take the micro to location
005, for the start of the program.
The following instructions show the code:
SetUp
|
ORG 000
GOTO SetUp
ORG 005
MOVLW 08
TRIS 06
OPTION 0DFh
GOTO Main |
;Start of program in memory
;
;Next instruction will be placed at location 005 |
|
The program will be burnt into a chip as follows: (actually the binary code
will be burnt into the chip).
this
NEXT
|