mariuszoll
Member level 5
- Joined
- Aug 28, 2012
- Messages
- 82
- Helped
- 1
- Reputation
- 2
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 2,147
Hi,
I have to read a string from my keyboard and to compare it if other constant strings, and depends on the result my software programe should do something. The prblem is that my program doesn't work correctly.
Below you can see my software parts related to string reading and comparing:
The problem is that whatever the string is the nrbox is always 3.
Could you help me please to fix this problem?
Thank you in advance.
I have to read a string from my keyboard and to compare it if other constant strings, and depends on the result my software programe should do something. The prblem is that my program doesn't work correctly.
Below you can see my software parts related to string reading and comparing:
Code:
// read string from keyboard
void interrupt(void)
{
if(PIR1bits.RCIF)
{
rxchar=RCREG;
TXREG=rxchar;
Delay1KTCYx(10);
rxarray[r]=rxchar;
r++;
if(rxchar=='\r') // if the character is Enter, flag is put on 1
{
flag=1;
}
}
}
// display string read from the keyboard
while(icount==0)
{
interrupt();
if(flag==1)
{
flag=0;
r=0;
icount++;
TXREG=11; //vertical tab
TXREG=13; // carriage return
}
}
// string compare
if(strcmp(rxarray,"a1")==0)
{
nrbox=1;
}
else
{
if(strcmp(rxarray,"a2")==0)
{
nrbox=2;
}
else nrbox=3;
}
The problem is that whatever the string is the nrbox is always 3.
Could you help me please to fix this problem?
Thank you in advance.
Last edited: