PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 27, 2021 5:42 pm |
|
|
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:
Then it will work.
Get rid of strcpy() every place where you write to out_data[]. |
|