Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Help me to Filter string in UART + Codevision

Status
Not open for further replies.

firefoxvn

Newbie level 1
Joined
Jan 21, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,289
Hi, I want to filter string that reply from SIMCOM. I have the string: xxxxxxxx +12345678 xxxxxx. The string "+12345678" is that I want. I do following steps:
- Check rx_counter!=0
- Create array has 10 char, array[0] starts from "+"
- If (array = UDR)==CR, program break;
- Check if rx_counter==0, copy string to another array has 10 char
- Send it to LCD or TX line.
Here is my code:
Code:
#define MAXCHAR 40
#define CR 13
char int_buff[MAXCHAR];

void check_SMS()//Check SMS sends case
{

unsigned int i;//Create int var
char content[10];//create array has 10 character
i=0;//set i=0
int_buff[0]='+';//create array int_buff[0] starts from "+"

while((i<MAXCHAR) && (rx_counter>0))//
{
if((int_buff[i++]=UDR)==CR) break;//The program stops when UDR=int_buff=CR, CR is enter key and equal 13 in ASCII.
delay_ms(500);
}
if(rx_counter==0)//if rx_counter=0, transmit is finished
{
strcpy(content,&int_buff[i]);//Copy data from int_buff to content
puts(content);
lcd_gotoxy(0,0);
lcd_puts(content);//Print it to LCD
delay_ms(500);
}
But its did not work, I don't understand my code was wrong or the way I think was wrong. Help me fix the code, please. Thanks for reading and sorry for my English. I'm foreigner.
 

sherazi

Banned
Joined
Feb 15, 2010
Messages
388
Helped
61
Reputation
124
Reaction score
61
Trophy points
1,318
Location
Muscat, Oman, Oman
Activity points
0
well y not try this method!

here is how i check a call or sms, and if its call then extaract the number... its just a part of a test program its for u to have an idea and its working
Code:
i=0;
	for (;;)
	{	abcce:
		usart_buff[i]=USART0_Receive();
		if(usart_buff[i]=='+')
		{
			
			usart_buff[i]=USART0_Receive();
			if(usart_buff[i]=='C')
			{
				usart_buff[i]=USART0_Receive();
				if(usart_buff[i]=='L')
				{
					do{
					
					usart_buff[i]=USART0_Receive();
					}
					while (usart_buff[i]!=':');
					USART0_Receive();
					//USART0_Receive(); 
					USART0_Receive();
					//do{
					i=7;
					for (int d=0;d<8;d++)
					numb[i--]=USART0_Receive();
					//}
					//while(numb[i]!=',');
										USART0_TransmitString("\r ATH\r");
										_delay_ms(250);
										
					numb[8]='\0';
					

					//USART0_TransmitString(numb);
					
					if(strncmp(numb,sm,8)==0)
					USART0_TransmitString("switch on");
					
				 	else if(match_mstr()==1)
					USART0_TransmitString("switch on");

					else if(match_user()==1)
					USART0_TransmitString("switch on");
				
					
					goto abcce;	
				}
				else if (usart_buff[i]=='M')
				{
					usart_buff[i]=USART0_Receive();
					if(usart_buff[i]=='T')	
					{
						for(int d=0;d<8;d++)
						{
							USART0_Receive();
						}
						i=0;
						index[0]=USART0_Receive();
						index[1]=USART0_Receive();
						
						//USART0_TransmitString("\r index :  \r");
						//USART0_TransmitString(index);
						//	USART0_Transmit('\r');
					//	index[]="02";
						USART0_TransmitString("AT+CMGR=");
						USART0_TransmitString(index);	
						USART0_Transmit('\r');

						
						while(USART0_Receive()!=',');
						
						USART0_Receive();
						USART0_Receive();
						USART0_Receive();
						USART0_Receive();
						USART0_Receive();
						
						i=7;
						//while(numb[i]!=0x0d)
						for (int d=0;d<8;d++)
						{
							numb[i--]=USART0_Receive();
						}
						//
						USART0_TransmitString(numb);
						USART0_TransmitString("\r");	
	

						int w=0;
						while(USART0_Receive()!=0x0d);
						
						w=-1;
						msg[-1]=USART0_Receive();
						while(msg[w]!=0x0d)
						{
							msg[++w]=USART0_Receive();
							//w++;
						}
						msg[w]='\0';
							
						USART0_TransmitString("\r at+cmgd=1,4\r");
	
						USART0_TransmitString(msg);
						//char chr[5];
 
Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top