CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how to use bank register

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
adie3112



Joined: 19 Apr 2009
Posts: 3

View user's profile Send private message Yahoo Messenger

how to use bank register
PostPosted: Mon Apr 20, 2009 12:35 am     Reply with quote

I'm the beginner in PIC programming, so wanna ask how can I access the bank register of PIC16F887, since I wanna use that space (bank2 and bank3) for array content . Is there any specific function need to add in the code??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 20, 2009 1:11 am     Reply with quote

Add the line in bold below. The compiler will now also use banks 2 and 3.
Quote:
#include <16F887.h>
#device *=16


This line is only needed for the PCM compiler. PCH and PCD don't need it.
adie3112



Joined: 19 Apr 2009
Posts: 3

View user's profile Send private message Yahoo Messenger

bank function
PostPosted: Mon Apr 20, 2009 2:14 am     Reply with quote

thanks for ur reply,

bank2 unsigned int AVERAGE[NUM_BTTNS];
bank3 unsigned int GUARD [NUM_BTTNS];

this both instruction come from the code that using Hitech as the compiler, but the functions are not defined in the CCS compiler (error during compile) . so what is the suitable function to ensure it will definitey working in CCS compiler,
i already try to change it like this in CCS
#define bank2 unsigned int AVERAGE [NUM_BTTNS]; there is no error, so is this function right or is the meaning same as the Hitech version(bank2 unsigned int AVERAGE[NUM_BTTNS];)

and one more things is there any big differences between the code using Hitech as their compiler and the one using CCS??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 20, 2009 2:33 am     Reply with quote

The CCS compiler automatically decides the location for the arrays.
You don't have to do it. This is one of the useful features of the CCS
compiler.
Ttelmah
Guest







PostPosted: Mon Apr 20, 2009 2:35 am     Reply with quote

CCS is not Hitech...
Basically, you can just enable the bank handling, and leave the compiler to put things where it wants. If you must locate something at a specific location, then just use the #locate directive.
Yes, a huge amount of difference. There would probably not a be line the same, in the resulting assembler, between a program compiled in the two compilers. In some areas, CCS, is very good. It provides extremely efficient re-use of RAM, which is a great feature for the smaller PICs. In some ways 'in use', it is more targetted at behaving a little closer to a compiler on a 'larger' computer, with it being assumed that you should not have to worry at all about memory management, however the sheer limitations of the PIC, mean this can't always be ignored, and then the behaviour can make it harder to completely take control.
There would not be an error for what you posted, but it wouldn't actually 'do' anything....

Best Wishes
adie3112



Joined: 19 Apr 2009
Posts: 3

View user's profile Send private message Yahoo Messenger

PostPosted: Mon Apr 20, 2009 3:47 am     Reply with quote

If you all don't mind can you give me the detail explanation about the bank handling. As Ttelmah reply just now about the enable bank handling. Since I really don't have any knowledge or experience about the bank handling.
Thanks for all supports.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Apr 20, 2009 6:44 am     Reply with quote

Banked memory is an old method for increasing the memory capacity in an existing hardware architecture.

A little background:
A long, long, time ago when silicium was expensive a company called Microchip created a microprocessor revolutionizing the world: At only a few dollars it offered a programmable processor costing as little as a couple of TTL IC's. The processors could be this cheap because of the minimalist architecture, everything not absolutely required was left out. One of the limitations was a data address space of only 256 bytes, including the addresses used for Special Function Registers.
The PIC processor became a huge success.

Time progressed and customers wanted more powerful processors. In order to increase the 256 byte data memory limit in the existing architecture Microchip implemented a technique widely in use in many other systems of that time: Banked Memory.
The 8 bit address bus can only address up to 256 byte, but by adding an extra register it became possible to select between different 'banks'of 256 memory. One way to explain this is to look at each Bank as a seperate memory chip of 256 bytes. Using the select register the desired memory Bank is selected, a picture can be found in the datasheet of your PIC processor.
One major drawback of this technique is that only one memory bank can be active at a time. For example moving data to another memory bank creates overhead for switching the contents of the Select Register. Some registers like the Status Register have to be read very often and to minimize the bank switching overhead these registers are 'mirrored' in all banks; at the same memory location in each bank you can read these special registers at the cost of losing a RAM location.

Final question: you say you are a beginner at PIC programming. Why do you want to use a PIC16 processor? PIC18 processors have fewer hardware limitations making them easier to use at about the same price per chip as the PIC16.
The only reason I can think of to use a PIC16 is that you already own the PCM Compiler and don't want to buy the PIC18 PCH compiler.
PIC18 processors are manufactured using newer production technology often making these chips cheaper than a less capable PIC16. As an example my favourite PIC16F88 against a PIC18F14K50:
PIC16F88: 18 pin DIP, $2.20, 368 bytes RAM, 7 kbyte ROM, 256 EEPROM, 3 timers (2*8bit, 1*16bit), 20MHz max.
PIC18F14K50: 20 pin DIP, $1.53, 768 bytes RAM, 16 kbyte ROM, 256 EEPROM, 4 timers (1*8bit, 3*16bit), 48MHz max.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

about that final question-
PostPosted: Mon Apr 20, 2009 7:46 am     Reply with quote

my company buys lots of 1000 16c622a and 16c715 as SOICs and orders lots of about 500 at a time of both the 16f887 and 886 as DIPS - for ongoing production runs.

BTW: clock never above 8 mhz nor needed higher

what would be the 18F versions of those parts that could save us some $$
and or improve performance ?

Might there still be a reason or two ( or THOUSAND? ) in the $$ department to keep those antique parts alive ?
Ttelmah
Guest







PostPosted: Mon Apr 20, 2009 8:10 am     Reply with quote

To the original poster.

Imagine a library, with shelves addressable by a code.
They run out of space, so add an extra digit, corresponding to a building address.

This is effectively 'bank addressing'.

Now, if you absolutely have to have the book in a particular building, then you can fiddle about, and tell them the full code of the item you want. However unless you need this 'specific' access, then it is simpler to just let the librarian work out the code for you.
CCS is the librarian.

If you add the "#device *=16" entry already mentioned by PCM programmer, then CCS, will _automatically_ handle the bank control for you. You can just declare a variable, and access it, and don't have to care what bank (building in the analogy), it is stored in. CCS will switch banks for you as needed.

The only reasons to go to specific bank switching, with the CCS compiler, are if you absolutely 'must' store a value at a specific location, or you have some specific performance issue, requiring the variable to be in a particular bank.

Basically, forget how HiTech does it, and let the compiler do it's job...

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: about that final question-
PostPosted: Mon Apr 20, 2009 11:04 am     Reply with quote

asmboy wrote:
what would be the 18F versions of those parts that could save us some $$ and or improve performance ?
The PIC16C715 and PIC16C22A are what Microchip calls 'mature' products. I'm not really sure what that means but they are not recommended for new designs. Both are 18-pin chips and there are not a lot of PIC18 chips with that low number of pins, prices start at $1.96. For these chips you better stay with the PIC16 series. Microchip recommended replacement parts:
PIC16C715 $2.27, Microchip recommends PIC16F716 $0.77
PIC16C22A $1.58, Microchip recommends PIC16F628A $1.47
Check the Microchip site for feature differences and pin layout.

For the PIC16F886 and PIC16F887 you will find PIC18 replacements at about your current price level. You are not going to save money on processor hardware but the extra ROM, RAM and improved features will ease the development of new software. It all comes down to quantities: sell 1 million products and every cent counts. Sell a single product and buying the most feature rich processor will save you expensive development time.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group