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

Same problem continues with CAN bus [Solved]
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 27, 2021 5:42 pm     Reply with quote

Here is the first part of program #2:
Quote:
void main() {
delay_ms(200);
output_a(0x01);
output_b(0x00);
output_c(0b00000100);

set_tris_a(0x01);
set_tris_B(0b00001000);
set_tris_C(0b00000100);

setup_timer_0 (T0_INTERNAL|T0_DIV_256|T0_8_BIT);
set_timer0(178);
enable_interrupts(int_TIMER0);
enable_interrupts(GLOBAL);

can_init();
i=0;
clr_Buf();

//fill_buf();
can_putd(ID1,&out_data,tx_len,tx_pri,tx_ext,tx_rtr);
while(TRUE){

if (!input(BTN)){
strcpy(out_data[0], 1);
strcpy(out_data[1], 0);
output_high(LED4);
printf("LED4 ON \r\n");
printf("LED3 OFF \r\n");

It calls clr_Buf() which zeros the data in the out_data[] array.
You then try to copy a 0x01 byte into the byte 0 position by
using the strcpy() function. That's wrong. strcpy() is for strings.
Your array is not a string. It's a collection of 8 arbitrary bytes.

Here is a test program that I made to show the problem:
Code:
//    can25K80_2.c
#include <18f25k80.h>
#device ADC=8  *=16 //ICD=TRUE
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOPLLEN,SOSC_DIG,NOIESO,NOFCMEN,CANB
#use delay(iNTERNAL=16mhz)
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7,ERRORS)

int out_data[8];

void clr_Buf() {
      out_data[0]=0;
      out_data[1]=0;
      out_data[2]=0;
      out_data[3]=0;
      out_data[4]=0;
      out_data[5]=0;
      out_data[6]=0;
      out_data[7]=0;
}

//-----------------------------------
void display_out_data(void)
{
int8 i;

for(i=0; i<8; i++)
   printf("%x ", out_data[i]);
printf("\r");
}

//==============================
void main()
{
clr_Buf();

display_out_data();
 
strcpy(out_data[0], 1);
display_out_data();

while(TRUE);
}

The result of running this program in MPLAB vs. 8.92 simulator is:
Quote:

00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00

The 2nd line should have 01 at the start if your strcpy() method
worked, but it doesn't work.

Remove this line:
Quote:
strcpy(out_data[0], 1);

Change it to this:
Code:
out_data[0] = 1;

Then it will work.

Get rid of strcpy() every place where you write to out_data[].
amcasi



Joined: 19 Jun 2015
Posts: 21
Location: Banned - Spammer

View user's profile Send private message

PostPosted: Mon Jun 28, 2021 12:48 am     Reply with quote

Thank you so much Pcm Programmer.

I changed strcpy to out_data everything are working now.
Yea. Third expert eye looked and solved problem.

A lot of thanks to you.
Have nice and nice days.

Amcasi
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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