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

Code Translation from cc5x to ccs

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



Joined: 20 Apr 2004
Posts: 0
Location: Mexico

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

Code Translation from cc5x to ccs
PostPosted: Mon Jul 18, 2005 7:28 am     Reply with quote

Hi everyone I want to translate the following code from cc5x compiler to ccs compiler. My first problem are the port declaration for a specific bit of the port like PORTA.x.Then I want to translate how to access one bit of specific variable like temp.x and I hope someone can help me to convert this code. Thanks very much.


#define Clock_8MHz
#define Baud_9600

#include "d:\Pics\c\16F88.h"

//There is no config word because this program tested on a 16F88 using Bloader the boot load program

#pragma origin 4

#include "d:\Pics\code\Delay.c" // Delays
#include "d:\Pics\code\Stdio.c" // Basic Serial IO

#define TX_CE PORTB.0
#define TX_CS PORTB.1
#define TX_CLK1 PORTB.3
#define TX_DATA PORTB.4

#define RX_CE PORTA.2
#define RX_CS PORTA.3
#define RX_CLK1 PORTA.4
#define RX_DATA PORTA.1
#define RX_DR PORTA.0

uns8 data_array[29];
uns8 counter;
uns8 packet_number;

void boot_up(void);
void configure_receiver(void);
void configure_transmitter(void);
void transmit_data(void);
void receive_data(void);

void main()
{
uns8 i;
uns16 elapsed_time;

packet_number = 0;
counter = 0;

boot_up();

while(1)
{
packet_number++;

//Put some data in the ougoing array
data_array[0] = packet_number;
for(i = 1 ; i < 29 ; i++)
data_array[i] = ++counter;

transmit_data();

//Here we monitor how many clock cycles it takes for the receiver to register good data
//elasped_time is in cycles - each cycles is 500ns at 8MHz so 541 cycles = 270.5us
//==============================================
TMR1IF = 0;
TMR1L = 0 ; TMR1H = 0 ; TMR1ON = 1;
while(RX_DR == 0)
if (TMR1IF == 1) break; //If timer1 rolls over waiting for data, then break
TMR1ON = 0;
elapsed_time.high8 = TMR1H;
elapsed_time.low8 = TMR1L;
//==============================================

if(RX_DR == 1) //We have data!
receive_data();

delay_ms(10); //Have a second between transmissions just for evaluation

}

}

void boot_up(void)
{
OSCCON = 0b.0111.0000; //Setup internal oscillator for 8MHz
while(OSCCON.2 == 0); //Wait for frequency to stabilize

ANSEL = 0b.0000.0000; //Turn pins to Digital instead of Analog
CMCON = 0b.0000.0111; //Turn off comparator on RA port

PORTA = 0b.0000.0000;
TRISA = 0b.0000.0001; //0 = Output, 1 = Input (RX_DR is on RA0)

PORTB = 0b.0000.0000;
TRISB = 0b.0000.0100; //0 = Output, 1 = Input (RX is an input)

enable_uart_TX(0); //Setup the hardware UART for 20MHz at 9600bps
enable_uart_RX(0); //Take a look at header files - it's not that hard to setup the UART

printf("\n\rRF-24G Testing:\n\r", 0);

delay_ms(100);

configure_transmitter();
configure_receiver();
}

//This will clock out the current payload into the data_array
void receive_data(void)
{
uns8 i, j, temp;

RX_CE = 0;//Power down RF Front end

//Erase the current data array so that we know we are looking at actual received data
for(i = 0 ; i < 29 ; i++)
data_array[i] = 0x00;

//Clock out the data
for(i = 0 ; i < 29 ; i++) //29 bytes
{
for(j = 0 ; j < 8 ; j++) //8 bits each
{
temp <<= 1;
temp.0 = RX_DATA;

RX_CLK1 = 1;
RX_CLK1 = 0;

}

data_array[i] = temp; //Store this byte
}

//if(RX_DR == 0) //Once the data is clocked completely, the receiver should make DR go low
// printf("DR went low\n\r", 0);

printf("Received packet %d\n\r", data_array[0]);
//This prints out the entire array - very large!
/*
printf("\n\rData Received:\n\r", 0);
for(i = 0 ; i < 29 ; i++)
{
printf("[%d]", i);
printf(" : %h - ", data_array[i]);
}
*/


RX_CE = 1; //Power up RF Front end
}

//This sends out the data stored in the data_array
//data_array must be setup before calling this function
void transmit_data(void)
{
uns8 i, j, temp, rf_address;

TX_CE = 1;

//Clock in address
rf_address = 17;
for(i = 0 ; i < 8 ; i++)
{
TX_DATA = rf_address.7;
TX_CLK1 = 1;
TX_CLK1 = 0;

rf_address <<= 1;
}

//Clock in the data_array
for(i = 0 ; i < 29 ; i++) //29 bytes
{
temp = data_array[i];

for(j = 0 ; j < 8 ; j++) //One bit at a time
{
TX_DATA = temp.7;
TX_CLK1 = 1;
TX_CLK1 = 0;

temp <<= 1;
}
}

TX_CE = 0; //Start transmission
}

//2.4G Configuration - Receiver
//This setups up a RF-24G for receiving at 1mbps
void configure_receiver(void)
{
uns8 i, j, temp;
uns8 config_setup[14];

//During configuration of the receiver, we need RX_DATA as an output
PORTA = 0b.0000.0000;
TRISA = 0b.0000.0001; //0 = Output, 1 = Input (RX_DR is on RA0) (RX_DATA is on RA1)

//Config Mode
RX_CE = 0; RX_CS = 1;

//Setup configuration array
//===================================================================
//Data bits 111-104 Max data width on channel 1 (excluding CRC and adrs) is 232
config_setup[0] = 232;

//Data bits 103-64 Channel 2 address - we don't care, set it to 200
config_setup[1] = 0;
config_setup[2] = 0;
config_setup[3] = 0;
config_setup[4] = 0;
config_setup[5] = 200;

//Data bits 63-24 Channel 1 address - set it to 17
config_setup[6] = 0;
config_setup[7] = 0;
config_setup[8] = 0;
config_setup[9] = 0;
config_setup[10] = 17;

//Data bits 23-16 Address width and CRC
config_setup[11] = 0b.0010.0011;

//Data bits 15-8
config_setup[12] = 0b.0100.1101;

//Data bits 7-0
config_setup[13] = 0b.0000.1101;
//===================================================================

//Clock in configuration data
for(i = 0 ; i < 14 ; i++)
{
temp = config_setup[i];

for(j = 0 ; j < 8 ; j++)
{
RX_DATA = temp.7;
RX_CLK1 = 1;
RX_CLK1 = 0;

temp <<= 1;
}
}

//Configuration is actived on falling edge of CS (page 10)
RX_CE = 0; RX_CS = 0;

//After configuration of the receiver, we need RX_DATA as an input
PORTA = 0b.0000.0000;
TRISA = 0b.0000.0011; //0 = Output, 1 = Input (RX_DR is on RA0) (RX_DATA is on RA1)

//Start monitoring the air
RX_CE = 1; RX_CS = 0;

printf("RX Configuration finished...\n\r", 0);

}

//2.4G Configuration - Transmitter
//This sets up one RF-24G for shockburst transmission
void configure_transmitter(void)
{
uns8 i, j, temp;
uns8 config_setup[14];

//Config Mode
TX_CE = 0; TX_CS = 1;

//Setup configuration array
//===================================================================
//Data bits 111-104 Max data width on channel 1 (excluding CRC and adrs) is 232
config_setup[0] = 232;

//Data bits 103-64 Channel 2 address - we don't care, set it to 200
config_setup[1] = 0;
config_setup[2] = 0;
config_setup[3] = 0;
config_setup[4] = 0;
config_setup[5] = 200;

//Data bits 63-24 Channel 1 address - set it to 17
config_setup[6] = 0;
config_setup[7] = 0;
config_setup[8] = 0;
config_setup[9] = 0;
config_setup[10] = 17;

//Data bits 23-16 Address width and CRC
config_setup[11] = 0b.0010.0011;

//Data bits 15-8
config_setup[12] = 0b.0100.1101;

//Data bits 7-0
config_setup[13] = 0b.0000.1100;
//===================================================================

//Clock in configuration data
for(i = 0 ; i < 14 ; i++)
{
temp = config_setup[i];

for(j = 0 ; j < 8 ; j++)
{
TX_DATA = temp.7;
TX_CLK1 = 1;
TX_CLK1 = 0;

temp <<= 1;
}
}

//Configuration is actived on falling edge of CS (page 10)
TX_CE = 0; TX_CS = 0;

printf("TX Configuration finished...\n\r", 0);
}
_________________
Jean Paul Talledo Vilela
PACE Laboratory
Tec de Monterrey
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Jul 18, 2005 9:37 am     Reply with quote

if you edit your post and include [.code] (leave out the .) before the start of the code and [./code] (leave out the .) after the end of the code it will make it a lot easier for people to read.

change the format from: #define TX_CE PORTB.0

to: #define TX_CE PIN_B0


add #define uns8 int


change the format from: 0b.0000.1100 to 0b00001100
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 18, 2005 10:53 am     Reply with quote

Quote:
TX_CE = 1;

TX_CE is used in the code as a memory location, which means he
should use a #bit statement to define it. This is how it should be done:

Code:
#byte PORTB = 6

#bit TX_CE = PORTB.0
#bit TX_CS = PORTB.1
#bit TX_CLK1 = PORTB.3
#bit TX_DATA = PORTB.4
// etc.
Jean_Paul_Talledo



Joined: 20 Apr 2004
Posts: 0
Location: Mexico

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

please help me with his code too!!!
PostPosted: Mon Jul 18, 2005 11:05 am     Reply with quote

my problem translating is how to convert the temp.0 to ccs function or variable.


code:



for(j = 0 ; j < 8 ; j++) //8 bits each
{
temp <<= 1;
temp.0 = RX_DATA;

RX_CLK1 = 1;
RX_CLK1 = 0;

}
_________________
Jean Paul Talledo Vilela
PACE Laboratory
Tec de Monterrey
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

Re: please help me with his code too!!!
PostPosted: Mon Jul 18, 2005 11:12 am     Reply with quote

Jean_Paul_Talledo wrote:
my problem translating is how to convert the temp.0 to ccs function or variable.


code:



for(j = 0 ; j < 8 ; j++) //8 bits each
{
temp <<= 1;
temp.0 = RX_DATA;

RX_CLK1 = 1;
RX_CLK1 = 0;

}


Easy. Just before the for loop, initialize temp = 0, then replace "temp.0 = RX_DATA" with:

Code:
if (RX_DATA) {
   bit_set(temp,0);
}
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