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

if (x == c) problem

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



Joined: 20 Mar 2010
Posts: 193
Location: Auckland NZ

View user's profile Send private message

if (x == c) problem
PostPosted: Sat Jul 10, 2010 10:16 pm     Reply with quote

Hi,
I have noticed few times that ccs is doing a funny thing:
I use PCH, when I do this
Code:
if ((a == 1) && (c ==1)) {

then it does not work, but if I do this
Code:
if ((a != 0) && (c !=0)) {

then it works!

Any similar experience and solution?

This is my code:
Code:

for (ac=0;ac<16;ac++) { // find it in the buffer and if there then do not buffer again

if ((tx_c_h == sent_buffered_cmd_h[ac]) && (tx_c_l == sent_buffered_cmd_l[ac]) && (tx_d1_h == sent_buffered_data1H[ac]) && (tx_d1_l == sent_buffered_data1L[ac]) && (tx_d2_h == sent_buffered_data2H[ac]) && (tx_d2_l == sent_buffered_data2L[ac]) && (tx_d3_h == sent_buffered_data3H[ac]) && (tx_d3_L == sent_buffered_data3L[ac]) && (tx_d4_h == sent_buffered_data4H[ac]) && (tx_d4_l == sent_buffered_data4L[ac])) {

   inbuffer = 1;
   } //if
   else {
      inbuffer = 0;
   } //else

and it does not work...

But this works
Code:

for (a=0;a<16;a++) {

if ((strn_decrypted[6] == sent_buffered_cmd_h[a]) && (strn_decrypted[7] == sent_buffered_cmd_l[a]) && (strn_decrypted[8] == sent_buffered_data1H[a]) && (strn_decrypted[9] == sent_buffered_data1L[a]) && (strn_decrypted[10] == sent_buffered_data2H[a]) && (strn_decrypted[11] == sent_buffered_data2L[a]) && (strn_decrypted[12] == sent_buffered_data3H[a]) && (strn_decrypted[13] == sent_buffered_data3L[a]) && (strn_decrypted[14] == sent_buffered_data4H[a]) && (strn_decrypted[15] == sent_buffered_data4L[a])) {

//message receiving confirmed
flag_expect_response[a] = 0 ;
   }
}

thnx
_________________
Help "d" others and then you shell receive some help from "d" others.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 12:52 am     Reply with quote

It's impossible to see, if your complains are justified without knowing the exact type definition of all involved variables - and the PCH version.

I guess, that you actually never verified the claimed issue with the first example? I know, that it's generally working correctly (e.g. with int8 type).
Code:
if ((a == 1) && (c ==1)) {

There may be possibly issues with decoding of complex expressions, although I'm not aware of it with PCH (they are still quite common with recent PCH versions). If so, everything is changed when replacing a single subexpression. Thus it's necessary to know the exact conditions to reproduce the problem.

A usual explanation would be a common user programming error as e.g. comparing signed and unsigned data types.
Linuxbuilders



Joined: 20 Mar 2010
Posts: 193
Location: Auckland NZ

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 1:09 am     Reply with quote

Variables:
Code:

BYTE tx_msg,tx_c_h,tx_c_l,tx_d1_h,tx_d1_l,tx_d2_h,tx_d2_l,tx_d3_h,tx_d3_l,tx_d4_h,tx_d4_l;

BYTE sent_buffered_msg_type[16];
BYTE sent_buffered_cmd_h[16];
BYTE sent_buffered_cmd_l[16];
BYTE sent_buffered_data1H[16];
BYTE sent_buffered_data1L[16];
BYTE sent_buffered_data2H[16];
BYTE sent_buffered_data2L[16];
BYTE sent_buffered_data3H[16];
BYTE sent_buffered_data3L[16];
BYTE sent_buffered_data4H[16];
BYTE sent_buffered_data4L[16];


Code:

void buffer_in_TX(short sent,short confirmation, int txbuffer) {
int a;
short inbuffer;
   inbuffer = 0;

for (a=0;a<16;a++) { // find it in the buffer and if there then do not buffer again

    if ((sent_buffered_cmd_h[a] == tx_c_h) && (sent_buffered_cmd_l[a] == tx_c_l) && (sent_buffered_data1H[a] == tx_d1_h) && (sent_buffered_data1L[a] == tx_d1_l) && (sent_buffered_data2H[a] == tx_d2_h) && (sent_buffered_data2L[a] == tx_d2_l) && (sent_buffered_data3H[a] == tx_d3_h) && (sent_buffered_data3L[a] == tx_d3_L) && (sent_buffered_data4H[a] == tx_d4_h) && (sent_buffered_data4L[a] == tx_d4_l)) {
      inbuffer = 1;
   } //if
   else {
      inbuffer = 0;
   } //else
   
   if ((sent == 1) && (confirmation == 0)) {
      flag_sent[a] = 1; // send when bus is free and remove from the buffer
      //beep_short();
      } //if
   } //for

   if ( ((inbuffer == 0) && (sent == 0)) || ((inbuffer == 0) && (confirmation == 1)) )   {
      //beep_long();
      if (confirmation == 1) {
         flag_expect_response[txbuffer] = 1;   
      } //if
      if (confirmation == 0) {
         flag_expect_response[txbuffer] = 0;   
      } //if

      sent_confirmation[txbuffer] = confirmation;
      sent_buffered_msg_type[txbuffer] = tx_msg;
      sent_buffered_cmd_h[txbuffer] = tx_c_h;
      sent_buffered_cmd_l[txbuffer] = tx_c_l;
      sent_buffered_data1H[txbuffer] = tx_d1_h;
      sent_buffered_data1L[txbuffer] = tx_d1_l;
      sent_buffered_data2H[txbuffer] = tx_d2_h;
      sent_buffered_data2L[txbuffer] = tx_d2_l;
      sent_buffered_data3H[txbuffer] = tx_d3_h;
      sent_buffered_data3L[txbuffer] = tx_d3_l;
      sent_buffered_data4H[txbuffer] = tx_d4_h;
      sent_buffered_data4L[txbuffer] = tx_d4_l;
   } //if

}

void printout(int confirmation,int msg_type_to_send,int cmd_h_to_send,int cmd_l_to_send,int data1H_to_send,int data1L_to_send,int data2H_to_send,int data2L_to_send,int data3H_to_send,int data3L_to_send,int data4H_to_send,int data4L_to_send) {
short sent;
crcRX();

   disable_interrupts(int_rda);
   sent = 0;

   tx_msg = msg_type_to_send;
   tx_c_h = cmd_h_to_send;
   tx_c_l = cmd_l_to_send;
   tx_d1_h = data1H_to_send;
   tx_d1_l = data1L_to_send;
   tx_d2_h = data2H_to_send;
   tx_d2_l = data2L_to_send;
   tx_d3_h = data3H_to_send;
   tx_d3_l = data3L_to_send;
   tx_d4_h = data4H_to_send;
   tx_d4_l = data4L_to_send;   

   txbuffer++;
   if (txbuffer > 15) {
      txbuffer = 0;
   } //if

if ( (!kbhit()) && (stop_TX != 1) ) {
comms_TX_high();
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",0xFF,dest_h,dest_l,address_h,address_l,msg_type_to_send,cmd_h_to_send,cmd_l_to_send,data1H_to_send,data1L_to_send,data2H_to_send,data2L_to_send,data3H_to_send,data3L_to_send,data4H_to_send,data4L_to_send,crc_h_calculated,crc_l_calculated,0xD);
comms_TX_low();
   
   sent = 1;
   reprint_delay = 0;

} //if
else {
   sent =   0;
   } //else

buffer_in_TX(sent,confirmation,txbuffer); //buffer it if not in buffer

   enable_interrupts(int_rda);

} //void

When I send a message I expect it to be loaded into my buffer if not there, however it does not execute this part:
if ((sent_buffered_cmd_h[a] == tx_c_h) && (sent_buffered_cmd_l[a] == tx_c_l) && (sent_buffered_data1H[a] == tx_d1_h) && (sent_buffered_data1L[a] == tx_d1_l) && (sent_buffered_data2H[a] == tx_d2_h) && (sent_buffered_data2L[a] == tx_d2_l) && (sent_buffered_data3H[a] == tx_d3_h) && (sent_buffered_data3L[a] == tx_d3_L) && (sent_buffered_data4H[a] == tx_d4_h) && (sent_buffered_data4L[a] == tx_d4_l)) {

and always marks inbuffer as 0
_________________
Help "d" others and then you shell receive some help from "d" others.
Linuxbuilders



Joined: 20 Mar 2010
Posts: 193
Location: Auckland NZ

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 1:11 am     Reply with quote

PCH 4.107
_________________
Help "d" others and then you shell receive some help from "d" others.
Linuxbuilders



Joined: 20 Mar 2010
Posts: 193
Location: Auckland NZ

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 1:14 am     Reply with quote

Code:

34:                    if ((sent_buffered_cmd_h[a] == tx_c_h) && (sent_buffered_cmd_l[a] == tx_c_l) && (sent_buffered_data1H[a] == tx_d1_h) && (sent_buffered_data1L[a] == tx_d1_l) && (sent_buffered_data2H[a] == tx_d2_h) && (sent_buffered_data2L[a] == tx_d2_l) && (sent_buffered_data3H[a] == tx_d3_h) && (sent_buffered_data3L[a] == tx_d3_L) && (sent_buffered_data4H[a] == tx_d4_h) && (sent_buffered_data4L[a] == tx_d4_l)) {
  0512    6A03     CLRF 0x3, ACCESS
  0514    51A6     MOVF 0xa6, W, BANKED
  0516    0FCB     ADDLW 0xcb
  0518    6EE9     MOVWF 0xfe9, ACCESS
  051A    0E00     MOVLW 0
  051C    2003     ADDWFC 0x3, W, ACCESS
  051E    6EEA     MOVWF 0xfea, ACCESS
  0520    5062     MOVF 0x62, W, ACCESS
  0522    5CEF     SUBWF 0xfef, W, ACCESS
  0524    E15C     BNZ 0x5de
  0526    6A03     CLRF 0x3, ACCESS
  0528    51A6     MOVF 0xa6, W, BANKED
  052A    0FDB     ADDLW 0xdb
  052C    6EE9     MOVWF 0xfe9, ACCESS
  052E    0E00     MOVLW 0
  0530    2003     ADDWFC 0x3, W, ACCESS
  0532    6EEA     MOVWF 0xfea, ACCESS
  0534    5063     MOVF 0x63, W, ACCESS
  0536    5CEF     SUBWF 0xfef, W, ACCESS
  0538    E152     BNZ 0x5de
  053A    6A03     CLRF 0x3, ACCESS
  053C    51A6     MOVF 0xa6, W, BANKED
  053E    0FEB     ADDLW 0xeb
  0540    6EE9     MOVWF 0xfe9, ACCESS
  0542    0E00     MOVLW 0
  0544    2003     ADDWFC 0x3, W, ACCESS
  0546    6EEA     MOVWF 0xfea, ACCESS
  0548    5064     MOVF 0x64, W, ACCESS
  054A    5CEF     SUBWF 0xfef, W, ACCESS
  054C    E148     BNZ 0x5de
  054E    6A03     CLRF 0x3, ACCESS
  0550    51A6     MOVF 0xa6, W, BANKED
  0552    0FFB     ADDLW 0xfb
  0554    6EE9     MOVWF 0xfe9, ACCESS
  0556    0E00     MOVLW 0
  0558    2003     ADDWFC 0x3, W, ACCESS
  055A    6EEA     MOVWF 0xfea, ACCESS
  055C    5065     MOVF 0x65, W, ACCESS
  055E    5CEF     SUBWF 0xfef, W, ACCESS
  0560    E13E     BNZ 0x5de
  0562    6A03     CLRF 0x3, ACCESS
  0564    51A6     MOVF 0xa6, W, BANKED
  0566    0F0B     ADDLW 0xb
  0568    6EE9     MOVWF 0xfe9, ACCESS
  056A    0E01     MOVLW 0x1
  056C    2003     ADDWFC 0x3, W, ACCESS
  056E    6EEA     MOVWF 0xfea, ACCESS
  0570    5066     MOVF 0x66, W, ACCESS
  0572    5CEF     SUBWF 0xfef, W, ACCESS
  0574    E134     BNZ 0x5de
  0576    6A03     CLRF 0x3, ACCESS
  0578    51A6     MOVF 0xa6, W, BANKED
  057A    0F1B     ADDLW 0x1b
  057C    6EE9     MOVWF 0xfe9, ACCESS
  057E    0E01     MOVLW 0x1
  0580    2003     ADDWFC 0x3, W, ACCESS
  0582    6EEA     MOVWF 0xfea, ACCESS
  0584    5067     MOVF 0x67, W, ACCESS
  0586    5CEF     SUBWF 0xfef, W, ACCESS
  0588    E12A     BNZ 0x5de
  058A    6A03     CLRF 0x3, ACCESS
  058C    51A6     MOVF 0xa6, W, BANKED
  058E    0F2B     ADDLW 0x2b
  0590    6EE9     MOVWF 0xfe9, ACCESS
  0592    0E01     MOVLW 0x1
  0594    2003     ADDWFC 0x3, W, ACCESS
  0596    6EEA     MOVWF 0xfea, ACCESS
  0598    5068     MOVF 0x68, W, ACCESS
  059A    5CEF     SUBWF 0xfef, W, ACCESS
  059C    E120     BNZ 0x5de
  059E    6A03     CLRF 0x3, ACCESS
  05A0    51A6     MOVF 0xa6, W, BANKED
  05A2    0F3B     ADDLW 0x3b
  05A4    6EE9     MOVWF 0xfe9, ACCESS
  05A6    0E01     MOVLW 0x1
  05A8    2003     ADDWFC 0x3, W, ACCESS
  05AA    6EEA     MOVWF 0xfea, ACCESS
  05AC    5069     MOVF 0x69, W, ACCESS
  05AE    5CEF     SUBWF 0xfef, W, ACCESS
  05B0    E116     BNZ 0x5de
  05B2    6A03     CLRF 0x3, ACCESS
  05B4    51A6     MOVF 0xa6, W, BANKED
  05B6    0F4B     ADDLW 0x4b
  05B8    6EE9     MOVWF 0xfe9, ACCESS
  05BA    0E01     MOVLW 0x1
  05BC    2003     ADDWFC 0x3, W, ACCESS
  05BE    6EEA     MOVWF 0xfea, ACCESS
  05C0    506A     MOVF 0x6a, W, ACCESS
  05C2    5CEF     SUBWF 0xfef, W, ACCESS
  05C4    E10C     BNZ 0x5de
  05C6    6A03     CLRF 0x3, ACCESS
  05C8    51A6     MOVF 0xa6, W, BANKED
  05CA    0F5B     ADDLW 0x5b
  05CC    6EE9     MOVWF 0xfe9, ACCESS
  05CE    0E01     MOVLW 0x1
  05D0    2003     ADDWFC 0x3, W, ACCESS
  05D2    6EEA     MOVWF 0xfea, ACCESS
  05D4    506B     MOVF 0x6b, W, ACCESS
  05D6    5CEF     SUBWF 0xfef, W, ACCESS
  05D8    E102     BNZ 0x5de
35:                      inbuffer = 1;
  05DA    81A7     BSF 0xa7, 0, BANKED
36:                   } //if
37:                   else {
  05DC    D001     BRA 0x5e0
38:                      inbuffer = 0;
  05DE    91A7     BCF 0xa7, 0, BANKED
39:                   } //else
40:

_________________
Help "d" others and then you shell receive some help from "d" others.
Linuxbuilders



Joined: 20 Mar 2010
Posts: 193
Location: Auckland NZ

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 2:01 am     Reply with quote

It was my mistake,

this is wrong:
Code:

void buffer_in_TX(short sent,short confirmation, int txbuffer) {
int a;
short inbuffer;
   inbuffer = 0;

for (a=0;a<16;a++) { // find it in the buffer and if there then do not buffer again

    if ((sent_buffered_cmd_h[a] == tx_c_h) && (sent_buffered_cmd_l[a] == tx_c_l) && (sent_buffered_data1H[a] == tx_d1_h) && (sent_buffered_data1L[a] == tx_d1_l) && (sent_buffered_data2H[a] == tx_d2_h) && (sent_buffered_data2L[a] == tx_d2_l) && (sent_buffered_data3H[a] == tx_d3_h) && (sent_buffered_data3L[a] == tx_d3_L) && (sent_buffered_data4H[a] == tx_d4_h) && (sent_buffered_data4L[a] == tx_d4_l)) {
      inbuffer = 1;
   } //if
   else {
      inbuffer = 0;
   } //else

I am overriding my flag with this:
Code:

   else {
      inbuffer = 0;
   } //else

So correct is:
Code:

void buffer_in_TX(short sent,short confirmation, int txbuffer) {
int a;
short inbuffer;
   inbuffer = 0;

for (a=0;a<16;a++) { // find it in the buffer and if there then do not buffer again

    if ((sent_buffered_cmd_h[a] == tx_c_h) && (sent_buffered_cmd_l[a] == tx_c_l) && (sent_buffered_data1H[a] == tx_d1_h) && (sent_buffered_data1L[a] == tx_d1_l) && (sent_buffered_data2H[a] == tx_d2_h) && (sent_buffered_data2L[a] == tx_d2_l) && (sent_buffered_data3H[a] == tx_d3_h) && (sent_buffered_data3L[a] == tx_d3_L) && (sent_buffered_data4H[a] == tx_d4_h) && (sent_buffered_data4L[a] == tx_d4_l)) {
      inbuffer = 1;
   } //if

and then if msg is in the buffer then inbuffer will kick on and be 1, if not there will stay 0 as in initial:
Code:

short inbuffer;
inbuffer = 0;


Thnx.

PS. the if (x == c) problem is there I am sure but this one was false alarm. I have notice this strange behavior few times in the past. If I get it again I will post it.
_________________
Help "d" others and then you shell receive some help from "d" others.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 2:22 am     Reply with quote

I can't see from your code, if the compare will ever match. I could verify with MPLAB SIM however, that it achieves a match
exactly for one position, if the buffer arrays have been set before respectively. So it seems to me, that the claimed problem
doesn't exist.

In any case, you should post a complete code example, that reproduces the problem.
Linuxbuilders



Joined: 20 Mar 2010
Posts: 193
Location: Auckland NZ

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 2:25 am     Reply with quote

13K is too much, many thnx anyway, since my "else" is removed all works like a beauty.

Razz
_________________
Help "d" others and then you shell receive some help from "d" others.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 3:45 am     Reply with quote

Quote:
13K is too much
I didn't mean posting your complete application code but a complete example, that can be compiled as is.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 2:39 pm     Reply with quote

If you do post an example program, do it in the style you used below,
with simple, short little variables, and a very short (but complete)
program. Make it easy for us to read. You will get a lot more help that way.
Quote:

if ((a == 1) && (c ==1)) {
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