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 CCS Technical Support

Setting variables and config bits

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







Setting variables and config bits
PostPosted: Wed Jun 15, 2005 12:21 am     Reply with quote

Hi,
I have a question about using bitvariables. A few years ago I wrote a PIC-Programm with the Hi-Tec Compiler. Now I found code that I would use for a new project. A part of the code is the following sequence.

static unsigned char ISR_FLAGS @0x00C0; //Reserve one byte for Flags
static bit INTF_START @(unsigned)&ISR_FLAGS*8+0;//Reserve bit0 within the byte
static bit INTF_RB @(unsigned)&ISR_FLAGS*8+1;
static bit INTF_DATOK @(unsigned)&ISR_FLAGS*8+2;
static bit INTF_LIGHT @(unsigned)&ISR_FLAGS*8+3;
static bit INTF_TMREND @(unsigned)&ISR_FLAGS*8+4;

This Code reserved at 0x00C0 8Bit for my flags and on the next lines a bit for the interrupt on specified position within these 8Bit.

How can I do this with the CCS-Compiler. Is there a tutorial in the web where these things are mentioned. I searched in the help but did not find something similar to this.

Another question is about the config bits. When using the Project Wizard it sets the fuses as I want. But if I compile the code in MPLab, the Compiler does not set the Config bits in the programming environment. This seems to be different to the Hi-Tec compiler. Or what do I Have to do that the fuses are used to set the config bits in programming environment?

Thanks for help

Olaf
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 15, 2005 12:48 am     Reply with quote

The following program shows how to do it in CCS. You don't have to set
the memory address of the byte. The compiler will automatically put
it in a suitable RAM location.
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP   
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

int8 ISR_FLAGS; // Reserve one byte for Flags
#bit INTF_START  = ISR_FLAGS.0    // Reserve bit0 within the byte
#bit INTF_RB     = ISR_FLAGS.1
#bit INTF_DATOK  = ISR_FLAGS.2
#bit INTF_LIGHT  = ISR_FLAGS.3
#bit INTF_TMREND = ISR_FLAGS.4

//========================
void main()
{

INTF_START = 1;

INTF_RB = 0;

while(1);
}

If you do want to set a specific RAM address for ISR_FLAGS, you can.
Just substitute the following line for the "int8 ISR_FLAGS;" line:
Code:
#locate ISR_FLAGS = 0xC0   // Reserve one byte for Flags
Olaf
Guest







What's the problem with the configbits?
PostPosted: Wed Jun 15, 2005 2:36 am     Reply with quote

Thank you very much.

And what can I do that MPLab gets the correct config bits?

When I make a #fuse-description then the configs wont be set at the ConfigMenu. I had the problem that the programming of the Config-Bits was different from that I had in the #fuse-description

Olaf
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 15, 2005 8:48 am     Reply with quote

Can you tell us what development environment you are using ?

1. Are you using the CCS IDE, which is part of the PCW or PCWH
compiler ?

or,

2. Are you using the PCM or PCH compiler with the MPLAB IDE ?

I use PCM with MPLAB vs. 7.10. In that environment, if you have a
#fuses statement near the top of your program, the CCS compiler
will put the Config settings into the HEX file. Also, when programming
with PicStart-Plus or ICD2, the config bits will be automatically picked
up and used by MPLAB.

If you are using PCW or PCWH, I don't have that. In that case,
someone else will have to answer your question.
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Wed Jun 15, 2005 9:11 am     Reply with quote

PCM programmer wrote:

If you are using PCW or PCWH, I don't have that. In that case,
someone else will have to answer your question.


The wizard usually creates a file for inclusion that contains your device and fuses. Just edit that file for the appropriate fuses.

Scott
Olaf
Guest







PostPosted: Thu Jun 16, 2005 7:19 am     Reply with quote

Hi,

I'm using the PCW with MPLAB 6.3. Can I be sure that the #fuses will be written in the PIC? The fuses statement is different from the config-menu in MPLab. For the oscillator settings it is not realy a problem. But if the setting of the codeprotection is wrong it will be very annoying.

Olaf
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 16, 2005 12:03 pm     Reply with quote

I'm using MPLAB vs. 7.10. I don't really want to install vs. 6.30
to test your problem, so I'll just test it with 7.10.

If I make a project, and compile the program below with CCS PCM
vs. 3.225, and then go to the Configure menu in MPLAB and select
Configuration Bits, I see this window:
Code:
Configuration Bits

Address    Value      Category              Setting
2007       3F71       Oscillator            XT
                      Watchdog Timer        Off
                      Power Up Timer        On
                      Brown Out Detect      On
                      Low Voltage Program   Disabled
                      Flash Program Write   Enabled
                      Data EE Read Protect  Off
                      Code Protect          Off


If I look at the end of the .LST file, it shows this:
Code:
Configuration Fuses:
   Word  1: 3F71   XT NOWDT PUT NOPROTECT BROWNOUT NOLVP NOCPD NOWRT NODEBUG


Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//===================
void main()
{
printf("Hello World");

while(1);
}


Everything is correct.

I suggest that you get rid of the little ".h" include file that PCW makes,
and move the code that's in it to the top of your main C source file.
This should include the #fuses line. In other words, make it look
like the program above. Then there won't be a mystery about what
the #fuses line is. It's right there, in front of you, when you look at
your main C source file. Then compile your program. If you don't
get the same results that I did, then maybe upgrade MPLAB to 7.10.
Guest








PostPosted: Thu Jun 16, 2005 2:47 pm     Reply with quote

Quote:
If I look at the end of the .LST file, it shows this:

Code:
Configuration Fuses:
   Word  1: 3F71   XT NOWDT PUT NOPROTECT BROWNOUT NOLVP NOCPD NOWRT NODEBUG


Are you sure? I dont see this at the bottom of my .LST file anymore on my version of MPLab 7.10. I also don't see the stack level usage either - where do they hide that now?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 16, 2005 3:18 pm     Reply with quote

Quote:
I dont see this at the bottom of my .LST file anymore on my
version of MPLab 7.10. I also don't see the stack level usage either -
where do they hide that now?

Are you sure that MPLAB is set to use the CCS compiler,
or are you still compiling with Hi-Tech C ?

If you're using the CCS compiler, what is the version ?
The version is given at the top of the .LST file.
Olaf
Guest







PostPosted: Fri Jun 17, 2005 12:32 am     Reply with quote

Hi,

there is no line in the list-file which includes the fuses. Yes I'm sure that I compile wirh CCS. In the company I'm now working we don't have the Hi-Tec. The compiler version is 3.057. A really old version. But I think this should not be a problem. An there is not a problem with the .h file. There are the fuses listed which I set in the project wizard. But they won't be taken for programming the pic. The only solution is that I have to make the settings with the config menu in MPLAB. But this could be a problem when I'm in a hurry.

Olaf
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 17, 2005 12:58 am     Reply with quote

You're right. I don't have your exact version, but I tried versions
3.045 and 3.068, and they don't put the fuse settings at the end of
the .LST file. CCS must have added that feature later.

If I try to use vs. 3.068 with MPLAB 7.10, it tells me "Your compiler
version is too old for this version of MPLAB". I wonder if you are
getting a message like that ?

When I was using those versions, I used MPLAB vs. 5.xx with
the PicStart-Plus programmer. It always picked up the fuse
settings properly.

I don't know what programmer you're using. If you're using
PicStart-Plus, then I would suggest MPLAB vs. 5.70.40.
It doesn't have colored syntax for C, but at least it will work.
You can download it from the Microchip archives page:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023073
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