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

use rs232 ;i need help

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



Joined: 27 Jan 2009
Posts: 1

View user's profile Send private message

use rs232 ;i need help
PostPosted: Thu Jan 29, 2009 5:35 am     Reply with quote

I want to compare two char array and if they re the pin b0 is high#include

<16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000)

#use rs232 (baud=9600, xmit=pin_C6, rcv=pin_C7, parity=N, stop=1)
int d;
int flag=0;
int flag1=0;
int i=0;
char c;
char yan[20];
char ert[7]={'*','c','e','t','i','n','$'};
#int_rda
void serihaberlesme_kesmesi()
{
output_low(pin_b0);
c=getch();
putc(c);
if ((flag==0)&& (c=='*'))
{
flag=1;
}
else
{
if ((c=='$') && (flag==1))
{
flag=0;
for(d=0;i;d--)
{
if(yan[i]!=ert[i])
{
i=0;
flag1=1;
continue;

}
else
{
if ((flag1=1) && (yan[0]='c'))
{output_high(pin_b0);}
}

}
}
}

if(flag=1)
{
yan[i]=c;
i++;
}
}
void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
output_low(pin_c5);
enable_interrupts(int_rda);
enable_interrupts(GLOBAL);
while(1)
{

}
}
this is my program can u help me?
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jan 29, 2009 6:01 am     Reply with quote

1st of all use the code tags. This makes your code more readable.

Secondly, a char array is basically a string but NOT null terminated, you can still use some of the string functions if you know for sure certain things. If your char arrays have fixed sizes :-

strncmp(str1, str2, 10) will compare the first 10 characters of the 2 strings.

look at the CCS help for more info or search google for strncmp.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jan 29, 2009 4:30 pm     Reply with quote

Code:
if(flag=1)
In the C language you have to use '==' for comparing.
This same error is also in two other locations in your code.
Guest








PostPosted: Thu Jan 29, 2009 4:57 pm     Reply with quote

ckielstra wrote:
Code:
if(flag=1)
In the C language you have to use '==' for comparing.
This same error is also in two other locations in your code.


Which is why I always put the constant first.

Code:

if(flag=1) // will always evaluate to true and leave you with hard to diagnose logic errors.

if(1=flag) // will cause a compiler error as you cannot assign a value to the constant.


Simple thing but ends up making the compiler do a bit of the "proofing" work for you.

Greg
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