|
|
View previous topic :: View next topic |
Author |
Message |
qwertyqqqq
Joined: 27 Jan 2009 Posts: 1
|
use rs232 ;i need help |
Posted: Thu Jan 29, 2009 5:35 am |
|
|
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
|
|
Posted: Thu Jan 29, 2009 6:01 am |
|
|
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
|
|
Posted: Thu Jan 29, 2009 4:30 pm |
|
|
In the C language you have to use '==' for comparing.
This same error is also in two other locations in your code. |
|
|
Guest
|
|
Posted: Thu Jan 29, 2009 4:57 pm |
|
|
ckielstra wrote: | 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 |
|
|
|
|
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
|