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

Converting Micro Chip J1939 to CCS J1939 Help!

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







Converting Micro Chip J1939 to CCS J1939 Help!
PostPosted: Mon May 09, 2005 8:45 pm     Reply with quote

The following won't compile because of the "static rom struct"


static rom struct TX_BUFFER_INFO_STRUCT BUFFER_TABLE[ECAN_MAX_TX_BUFFERS] = {
{ 0x06 }, // TXB1
{ 0x08 }}; // TXB0


I was wondering if anyone has converted the Micro Chip J1939 library to a CCS library.

Thanks

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 10, 2005 12:28 pm     Reply with quote

Quote:
The following won't compile because of the "static rom struct"

In CCS, to place a variable in ROM, you use "const".

I think you'll need to make a lot of test programs, to prove
to yourself that your modifications will work.

This means not only compiling the modified declarations, but it
also means putting in sample code to access the structures.
Preferably, use code that was taken right out of the J1939.c program.
That's what I've done below. I've also added code to access all
elements in the structure and display them. That way, I know I can
read all of them. I get the following result displayed on my terminal
window:

06
08

In the code below, you'll notice that I've commented out certain lines
of the J1939 code, and substituted lines that are compatible with CCS.

1. They've declared an instance of the structure, and they want to place
it in ROM. In CCS, this done by using the type specifier 'const'.
So I've removed 'static rom' and replaced it with 'const'.

2. They've declared LastTXBufferUsed to be static. But in CCS, 'static'
doesn't do much for you. In a normal compiler, you have linkable
object modules and if want variables to local to a module, then you
declare them to be 'static'. But CCS has no linker. All "modules"
must be #included into the main source file. In CCS, using 'static'
only really makes sense if you use it within a function so as to preserve
the variable between calls to that function. I suppose you could leave
it in there on that particular line and it really wouldn't hurt. CCS does
initialize static variables to zero unless you initialize them to some
other value. So keep that in mind. This is in the manual.

3. I've used a #byte statement to declare the CANCON register address.
That's how it's done in CCS.

4. They're using "unsigned char", and in CCS, a "char" is unsigned by
default. It doesn't really hurt to leave it as "unsigned char", so that's
what I did.

You're going to need to become familiar with the differences between
data types for CCS and other compilers. In CCS, a "long" is an
unsigned 16-bit value. An "int" is an unsigned 8-bit value.
It's best to use the alternate names for CCS data types, which are
int8, int16, and int32. These are unsigned. It's much easier to see
what the size is when you do it that way.

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

#define ECAN_MAX_TX_BUFFERS   2

struct TX_BUFFER_INFO_STRUCT {
       unsigned char WindowBits; };

//static rom struct TX_BUFFER_INFO_STRUCT BUFFER_TABLE[ECAN_MAX_TX_BUFFERS] = {
const struct TX_BUFFER_INFO_STRUCT BUFFER_TABLE[ECAN_MAX_TX_BUFFERS] = {
{ 0x06 }, // TXB1
{ 0x08 }}; // TXB0

//static unsigned char LastTXBufferUsed = 0;
unsigned char LastTXBufferUsed = 0;

#byte CANCON = 0xF6F

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

CANCON  = BUFFER_TABLE[LastTXBufferUsed].WindowBits;

LastTXBufferUsed = 0;
printf("%x \n\r", BUFFER_TABLE[LastTXBufferUsed].WindowBits);

LastTXBufferUsed = 1;
printf("%x \n\r", BUFFER_TABLE[LastTXBufferUsed].WindowBits);

while(1);
}
mike holeton
Guest







PostPosted: Tue May 10, 2005 8:19 pm     Reply with quote

Thank You very much for the help. I am begining to think this is not going to be a easy(maybe not even fun conversion) to do. I will take your advice and see how far I can go with it. I may be back for additonal help, so bare with me.

Thank You

Mike (licensed and maintenced CCS member)
rwskinner
Guest







PostPosted: Tue Dec 05, 2006 8:39 pm     Reply with quote

Mike,
Did you ever make it very far on the Microchip J1939 to CCS conversion.
I'm faced with the same thing right now, my problem is I'm just now learning C (Came over from PBP)
ScottSD



Joined: 15 Sep 2016
Posts: 1

View user's profile Send private message

PostPosted: Thu Sep 15, 2016 3:34 pm     Reply with quote

I would be very interested in this as well.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Sep 16, 2016 5:05 am     Reply with quote

gee an 11 year old post, does this make the 'record book' ?
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