Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

read a string from the keyboard and compare it

Status
Not open for further replies.

mariuszoll

Member level 5
Member level 5
Joined
Aug 28, 2012
Messages
82
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Visit site
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:

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:

The code seems to be for the PIC controller. Which controller and compiler are you using and if possible write the entire code in the post. I could help more if you could simply tell me entire code
 

you have set up interrupt for receiving. but you have not told it from when to start receiving. what i am saying is you you have not defined any start character. (or have you set any? tell us.) . what you can try is send enter command once. than try to send string. see what happens. also try to debug on hardware level. if you have any debugger. like icd or pickit.

- - - Updated - - -

and why are you using delay in interrupt.??
 

Now, my program is working. It seems that, strncmppng2ram() function is the best one for this type of comparation.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top