Not able to transfer a character from an array to an another array

Status
Not open for further replies.

ahmad2005

Member level 1
Joined
Mar 30, 2011
Messages
40
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Mirpur,Dhaka,Bangladesh
Activity points
1,618
Not able to transfer character from a array to an another array

Look at my code. at this line "UART1_Write_Text(UP_STATUS);" I was supposed to get all 6 characters of variable UP_STATUS but it only gives three. probably, codes r not appropriately written for array variables UP_STATUS[3] to UP_STATUS[5]. Can anyone suggest me how can I fix this?

Code:
char UP_STATUS[5];
int DimTime = 123;
char DimTimeTXT[2];

  if((uart_string[0] == 'U')&&(uart_string[1] == 'P')) {
      if(PORTA.RA2==1){UP_STATUS[0]='1';} else {UP_STATUS[0]='0';}
      if(PORTA.RA3==1){UP_STATUS[1]='1';} else {UP_STATUS[1]='0';}
      if(PORTA.RA4==1){UP_STATUS[2]='1';} else {UP_STATUS[2]='0';}
      
      IntToStr(Dimtime,DimTimeTXT);
      UP_STATUS[3] = DimTimeTXT[0];
      UP_STATUS[4] = DimTimeTXT[1];
     UP_STATUS[5] = DimTimeTXT[2]; 
      UART1_Write_Text(UP_STATUS); // here I was supposed to get: 000123 [considering PORTA ALL 0] but it only gives: 000 [only first three character.  
      uart_string[0] = "";                                                                                                                          ////Question is where is other three
      uart_string[1] = "";
    }
 

Re: not able to transfer character from a array to an another array

Hi,

I'm not familiar with "C"... but I try to analyze it anyway

char UP_STATUS[5];
I'm not sure, but I thought this is for 5 bytes, but you use 6 bytes...0, 1, 2, 3, 4, 5
The same is for DimTimeTXT.

int DimTime = 123;
How is "int" defined?
I thought it is a 16 bit integer. Then the IntToStr function should expect 5 (for uint16) or 6 (for int16) bytes wide result string.

*******
Are your variable names case sensitive?
DimTime <--> Dimtime

*******

I think it should be impossible to send only 3 bytes, I rather think it is sending the three ASCII style bytes "000" while the other bytes are non ASCII style and thus are ignored at the receiver (PC?).

A true string has a variable length. Either it is delimited by 0x00, or there is a "length" given with the variable.
How is your byte array treated in this concern? (UART1_write)

Klaus
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…