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

First CCS program and having troubles working with registers

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








First CCS program and having troubles working with registers
PostPosted: Mon May 12, 2008 9:36 pm     Reply with quote

Sorry, but this is my first time using this compiler and I am trying to convert a program from a different compiler and lots of things are different. Primarily, I am having trouble working with the PIC registers. I don't see anyplace where they are assigned names so I don't know how to convert all the instructions that directly modify hardware registers.

For example, I have the following code for setting up the USART:

txsta = 0b00100100;
rcsta = 0b10000000;

And setting some options:

option_reg.NOT_RBPU = 0; // PortB pullups activated
option_reg.INTEDG = 1; // interrupt on rising edge

And waiting for a character from the USART:

while (pir1.RCIF == 0) ;
char c = rcreg;

And testing for receive errors:

if(rcsta.OERR == 1){
rcsta.CREN = 0;
rcsta.CREN = 1;
return OVERFLOW;
}
if(rcsta.FERR == 1){
return FRAMINGERR;
}

How do I do all these things with CCS? Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 12, 2008 9:46 pm     Reply with quote

All of this is done at a higher level with CCS functions.

Quote:
For example, I have the following code for setting up the USART:
txsta = 0b00100100;
rcsta = 0b10000000;

See the #use rs232() statement in the CCS manual.

Quote:
option_reg.NOT_RBPU = 0; // PortB pullups activated
option_reg.INTEDG = 1; // interrupt on rising edge

Look at the port_b_pullups() function.
Look at the ext_int_edge( ) function.

Quote:
while (pir1.RCIF == 0) ;
char c = rcreg;

Look at getc()


And testing for receive errors:

if(rcsta.OERR == 1){
rcsta.CREN = 0;
rcsta.CREN = 1;
return OVERFLOW;
}
if(rcsta.FERR == 1){
return FRAMINGERR;
}
Look at the ERRORS parameter in the #use rs232() statement.


Quote:
How do I do all these things with CCS? Thanks!

You do it a lot faster and more easily than in your other compiler.

Download the CCS manual for more information.
http://www.ccsinfo.com/downloads/CReferenceManual.pdf
Guest








PostPosted: Tue May 13, 2008 12:21 am     Reply with quote

Thanks. It is a bit disconcerting not having direct control over the bits in the registers. I had looked briefly at #use rs232 but didn't see the bits I needed to set and also thought that there would be no way would the compiler designers would use RS232 to mean UART. I mean really, they are NOT the same thing. I do not have any RS232 hardware attached to my PIC, for example.

But that aside, looking at #use rs232, it is hard at first glance to see which settings correspond to the equivalent bits of txsta and rxsta.

I guess you just never have to set transmit enable or receive enable because the getc and putc routines do it for you, is that it?

To specify that the UART is running asynchronously, do you just NOT set SYNC_SLAVE or SYNC_MASTER?

Is just not necessary to do anything other than set the baud rate high enoug to cause the BRGH bit to be set?

Finally, how do you enable continuous receive? The manual mentions that SYNC_MATER_CONT makes the RS232 line a synchronous master mode in continuous receive mode, implying that there is a separate way to enable continuous receive.

What would be great is some examples of using the UART with varying configurations. Or even a discussion of the topic in the manual, explaining what happens to the registers when you make certain choices in the #use RS232 directive.

I miss having control of the registers even if it does save me a byte or two, if that even really is the case.

Anyway, thanks for the help!

Quote:

All of this is done at a higher level with CCS functions.

Quote:
For example, I have the following code for setting up the USART:
txsta = 0b00100100;
rcsta = 0b10000000;

See the #use rs232() statement in the CCS manual.

Quote:
option_reg.NOT_RBPU = 0; // PortB pullups activated
option_reg.INTEDG = 1; // interrupt on rising edge

Look at the port_b_pullups() function.
Look at the ext_int_edge( ) function.

Quote:
while (pir1.RCIF == 0) ;
char c = rcreg;

Look at getc()


And testing for receive errors:

if(rcsta.OERR == 1){
rcsta.CREN = 0;
rcsta.CREN = 1;
return OVERFLOW;
}
if(rcsta.FERR == 1){
return FRAMINGERR;
}
Look at the ERRORS parameter in the #use rs232() statement.


Quote:
How do I do all these things with CCS? Thanks!

You do it a lot faster and more easily than in your other compiler.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 13, 2008 12:56 am     Reply with quote

Here's how to see what the compiler is doing:

If you're using MPLAB, go to the Project Menu, then to Build Options,
and on the Compiler tab, set the List file format to Symbolic.

Also, edit the .H file for your PIC and comment out the #nolist line
near the top.

Then make a test program, compile it, and look at the .LST file.
You can see the values that the compiler puts into the SFR registers.
Ttelmah
Guest







PostPosted: Tue May 13, 2008 2:05 am     Reply with quote

In a sense, this is the key point about using a compiler, rather than assembler. With CCS, if (for instance), you change from using a PIC 16 chip, to a PIC 18, provided you have used their functions, the compiler does the work 'for you'.
You can directly access registers, using the #byte, and #bit functions, _but_ you really should try to think 'high level', and _not_ use these, unless you really have to.

Best Wishes
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Tue May 13, 2008 6:33 am     Reply with quote

Quote:
..It is a bit disconcerting not having direct control over the bits in the registers...

I agree. That is why I never use the CCS library functions for accessing peripherals like I/O ports, serial ports, Timers, etc. I supply the missing port address declarations with my own custom include file. Then I talk to the registers directly. There is no question about what the CCS library is doing with these ports. It is a bit of a bother to create the definitions from the Microchip datasheets, but once you do it for one processor, usually only minimal changes are needed when moving to a similar processor.

Robert Scott
Real-Time Specialties
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue May 13, 2008 8:15 am     Reply with quote

And to access the registers use #bit or #byte to overlay a variable on the register.

below show in hex for a 18F4525
Code:

#bit  RCIF =0XF9E.5
#bit  CREN =0XFAB.4
#bit  OERR =0XFAB.1
#byte RCREG=0XFAE


then read and writes to the variable go directrly to the register.
Code:
  if (OERR)
  {
    CREN = 0;
    CREN = 1;
  }
Guest








PostPosted: Tue May 13, 2008 11:58 am     Reply with quote

Good information, everybody! Thanks.
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