[SOLVED] how to store received stream of serial data? (PIC16F877A)

Status
Not open for further replies.

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
751
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,054
Hi, now i just started learning USART in PIC. I can now read serial data from RCREG register of PIC16F877A. But now i want to store successive keyboard pressings (in hyperterminal) in 30 variables.
If i press keyboard then corresponding ascii is loaded in RCREG and i can save it in a variable. Upto that its working...
NOW, PLS give me a small idea how to store a 10 successive keypress in 10 variables...
 

As Embedded Partner said, use an array of characters with size equal to the number of characters you want to receive and, a pointer to that array.
Here's a code for a function that receive a stream of characters from the hyper terminal.
Code:
char *Receive_MSG(char *String, unsigned short int MSG_Length)
{						
	unsigned short int Index = 0;	// Message Index
	
	while(Index < MSG_Length)
	{	
		String[Index] = Receive_Byte();
		if(String[Index] != 13 && String[Index] != 10)
		{
			String[Index + 1] = '\0';		// Set the next character to NULL
			Index++;
		}
		else
		{
			String[Index + 1] = '\0';		// Set the next character to NULL
			break;
		}
	}
	return String;
}
 
Hi vinodstanur,

If you use C, above mentioned arrays and pointers can be used easily for the purpose.
If you use assembly, use Indirect-addressing with INDF and FSR registers (see datasheet for details).

Thanks
 

for serial communications the best approach is to use circular FIFO - search in the forum, there was already some discussion about this. Using simply an array is not very good approach - you'll find out that during reading if write event occurs you'll get conflicts. Make it professional - use FIFO
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…