PIC16F877 general purpose RAM problem

Status
Not open for further replies.

mysteyboyk

New Member
hello!
i am writing a code for 16f877 in assembly language and i need to define 108 bytes data. for example:

data1 equ h'20'
data2 equ h'21'
data3 equ h'22'
..
..


data108 equ h'...'

but PIC16f877 RAM area is between h'20' and h'7f' and is not enough for my 108 byte data?

how can i solve this problem?
 


If you look at the datasheet for the 877 you will see that it has 4 BANKs of registers. Use the RP1 and RP0 to select the other BANKs and use the 'free' registers.

Also looking at your program listing, I would suggest that you look at the CBLOCK assembler directive, it will simplify the coding.

Does this help?
 
Last edited:
yes i must change banks but i have another question.. how can i use CBLOCK directive?
and also when changing banks, do i have to do this?

data1 equ h'20'
..
..
..
BSF RP0
data100 equ h'A0'
..
..

will it be like this?
thanks a lot
 
You can use cblock but according to the datasheet, 0x20 to 0x7f is only 96 registers in bank 0. You need 12 more, so just place the rest in bank 1.
*EDIT: FYI, general purpose register start from 0xa0
 
Last edited:

If you are going to be changing BANKs often, it would be an idea to write BANK Macro's, something like this.

Code:
BANK0 MACRO
     	BCF STATUS,RP0
	BCF STATUS,RP1
 ENDM

BANK1 MACRO
     	BSF STATUS,RP0
	BCF STATUS,RP1
 ENDM

BANK2 MACRO
     	BCF STATUS,RP0
	BSF STATUS,RP1
 ENDM

BANK3 MACRO
      BSF STATUS,RP0
	BSF STATUS,RP1
 ENDM

And in your source code, use

BANKn; to switch BANKs n = 0 thru 3

Which assembler are you using, if you are using MPLAB IDE 7.6 from microchip.com, its free,
then the CBLOCK and other directives are in the HELP section.

Is this clear enough?


EDIT:
Extract from MPLAB Help.
Code:
Simple Example 
cblock 0x20      ; name_1 will be assigned 20
  name_1, name_2 ; name_2, 21 and so on
  name_3, name_4 ; name_4 is assigned 23.
endc
cblock 0x30
  TwoByteVar: 0, TwoByteHigh, TwoByteLow ;TwoByteVar =0x30
                                         ;TwoByteHigh=0x30
                                         ;TwoByteLow =0x31
 
endc
 
Last edited:
mysteyboyk said:
yes it is useful for me..
thanks

As you are using the registers in all 4 BANK's, note that reg adddress's 0x70 thru 0x7F are common to ALL 4 BANK's, so don't use these registers in more than one BANK, to store different data blocks.

Look at the bottom of Page #13, of the datasheet for a full explanation.
 
ericgibbs said:
If you are going to be changing BANKs often, it would be an idea to write BANK Macro's

Mpasm already has built in macro's for bank & page selection

Code:
    BANKSEL  DATA0
    MOVFW    DATAO
    DO_STUFF ......
    BANKSEL  DATA108
    MOVFW    DATA108
    DO_STUFF ......
 
Can I use cblock like this instead of writing line by line?
Code:
cblock	20h
DIGIT1,DIGIT2,DIGIT3,DIGIT4,DIGIT5....
endc
 
Suraj143 said:
Can I use cblock like this instead of writing line by line?
Code:
cblock	20h
DIGIT1,DIGIT2,DIGIT3,DIGIT4,DIGIT5....
endc

Yes, but you need to consider what CBLOCK actually does, it's just a simple text substitution - so the assembler will simply replace every occurance of DIGIT1 by '20h', DIG1T2 by '21h' - it doesn't generate any code, or allocate anything, just does the text substitution.
 
Thanks for the reply why I asked this because if I have 50 registers so I can write them in one line instead of 50 lines.
 
Suraj143 said:
Thanks for the reply why I asked this because if I have 50 registers so I can write them in one line instead of 50 lines.

Yes, it just produces 50 text substitutions.
 
If I need a BIG buffer in ram then I normally use banks 3 and 4 in conjunction with indirect addressing. Set the IRP bit in STATUS and put 10h in FSR, you can now access a ram buffer that is 96 bytes long. If you add a simple check for reaching 70h you can then access a buffer that is 192 bytes long. And, no bank switching required.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…