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

Mapping of Internal Registers in ANSI-C

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







Mapping of Internal Registers in ANSI-C
PostPosted: Wed Apr 13, 2005 9:34 pm     Reply with quote

I would like to know if this implementation works with CCS for PIC. The reason why i dont want to use #byte is because of the porting issues.

Please suggest me the best method to map io's and yet portable to all platforms


/*** PORT_B ***/
typedef union {
char BB;
struct {
char BIT_7 :1;
char BIT_6 :1;
char BIT_5 :1;
char BIT_4 :1;
char BIT_3 :1;
char BIT_2 :1;
char BIT_1 :1;
char BIT_0 :1;
} Bits;
}PORTB;

extern volatile PORTB PORT_B @ 0x0001;


or can somebody explain me what "#byte" implemented.


Thank You.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 13, 2005 9:51 pm     Reply with quote

The following code would be more portable than #byte statements,
but I have to ask, how often do you plan to change compilers ?
Even if you're making a product that is intended for use with
different compilers, I think it would be better to port it to each
compiler than to try to debug some "universal" source code.
Look at Peter Anderson's website.
http://www.phanderson.com/PIC/PICC/index.html
He tries to make his code be semi-universal, by avoiding the
use of the CCS delay_ms(), etc., functions. But by doing so
he gives up the flexibility to change the crystal frequency
and have the delay functions automatically be adjusted for
the new frequency. Even he uses the #byte statements.
See his register definitions file.
http://www.phanderson.com/PIC/PICC/CCS_PCM/defs_f84.html
So my main question to you would be, why bother ?

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)

#define TrisB  0x86
#define PortB  0x06

main()
{

*TrisB = 0x00;
*PortB = 0x55;

while(1);
}
jose
Guest







Re.Mapping of Internal Registers in ANSI-C
PostPosted: Wed Apr 13, 2005 10:19 pm     Reply with quote

Thank you for the advice,

But how can i access bits in the registers using the similar method.

Thank you
Jose
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 14, 2005 7:10 am     Reply with quote

For portability you shouldn't be using PORTB. Instead, you should be using something more descriptive like "data_port". All of these declarations should be in a header file and you would use a different header file for each compiler.
jose
Guest







PostPosted: Mon Apr 18, 2005 7:01 pm     Reply with quote

Thank you for your advice Mark,

I hope this implementation would work on all the platforms and it doesnt take up the ram area.

Please comment on this implementation.

Thank you

regards
Jose



typedef volatile char SP;

typedef union {
SP BB;
struct {
SP BIT_7 :1;
SP BIT_6 :1;
SP BIT_5 :1;
SP BIT_4 :1;
SP BIT_3 :1;
SP BIT_2 :1;
SP BIT_1 :1;
SP BIT_0 :1;
} Bits;
}PORTB;



#define REG_PORTB ((PORTB *)0x00)



void main() {
.......
.....

REG_PORTB->Bits.BIT_1 = 0;
REG_PORTB->BB = 0;

}
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Apr 18, 2005 8:17 pm     Reply with quote

This is how I would do it

http://www.ccsinfo.com/forum/viewtopic.php?t=20186
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