tienchuan
Joined: 25 Aug 2009 Posts: 175
|
Problem with string copy function (strcpy) |
Posted: Wed Mar 27, 2013 7:05 pm |
|
|
Hi all.
I have a problem when using strcpy to copy one string to another string.
In my project used :
-- CCS C PCH ver 4.140
-- Pic18LF4680
And here is my code:
0. setup fuses, init variables
Code: |
#include <18LF4680.h>
#include <def_18f4680.h>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#device *=16 ADC=10
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#priority rda,timer0,timer1
#use fast_io (B)
#use fast_io (D)
#include <LCD_TM.c>
#include <font.c>
#include <matrix_control.c>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
unsigned int8 str_rs232[16]="";
unsigned int8 str_mod[16]="";
unsigned int8 str_pla[16]="";
unsigned int1 flag_rs232=0;
|
1. Interrupt rda code:
Code: |
#int_rda
void ngat_rs232()
{
char c;
c=getc();
switch(c)
{
case '$':
{
index=0;
}
break;
//------------------------
case '*':
{
if((str_rs232[0]=='M')&&(str_rs232[1]=='O')&&(str_rs232[2]=='D'))
{
index=0;
flag_mod=1;
}
}
break;
//-------------------------
case '#':
{
if((flag_mod==1)&&(index==16))
{
flag_mod=0;
index=0;
flag_rs232_ok=1;
}
}
break;
//-------------------------
default:
{
str_rs232[index]=c;
index++;
}
break;
} // end of switch
} // end of int_rda
|
2. And main program:
Code: |
void main(void)
{
trisb=0;
trisd=0;
trisc=0x80;
trise=0;
trisa=0;
enable_interrupts(int_rda);
//enable_interrupts(int_timer0);
//enable_interrupts(int_timer1);
enable_interrupts(global);
//setup_timer_0 (RTCC_DIV_256| RTCC_INTERNAL);
//set_timer0(200);
//setup_timer_1 (T1_DIV_BY_8| T1_INTERNAL);
//set_timer1(3035);
//buffer_full=0;
printf("*******************************************************\n\r");
printf("* Nhap chuoi ki tu\ so can hien thi *\n\r");
printf("* Bat dau chuoi bang ki tu : * *\n\r");
printf("* Ket thuc chuoi bang ki tu : Enter *\n\r");
printf("*******************************************************\n\r");
while(1)
{
if(flag_rs232)
{
strcpy(str_mod,str_rs232);
printf("%s",str_mod);
flag_rs232=0;
}
} // end of while
} // end of main
|
My problem is in copy "str_rs232" string to "str_mod" string is errors.
If i do follow after , that is right:
Code: |
if(flag_rs232)
{
//strcpy(str_mod,str_rs232);
printf("%s",str_rs232);
flag_rs232=0;
}
|
Pls show me errors in my code and show me a way to fix it.
thanks all.
Regards.
p/s: my code was shorted, only extract some necessary for my problem _________________ Begin Begin Begin !!! |
|