Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/26/09 07:28
Read: times


 
#171181 - String of characters serially
Hi members,

I am trying to receive a string of 4 characters into my 80C51 from my PC and then sum it u in the controller and send back the result. But i have no luck. i get a random character every time. My hardware is working as if i send a single character then it is sent back successfully.
#include<reg51.h>
#include<serial.h>//sets the baud rate and initilizes the controller serial port.
#include<generic.h>//this has the delays, although this has no use in this program

char recieved_0= 0x00;
char recieved_1= 0x00;
char recieved_2= 0x00;
char recieved_3= 0x00;
char recieved_4= 0x00;
char rr = 0x00;


int in = 0 ;
void serial_interrupt() interrupt 4
{
	if(TI)
		{
		rr = 0x00;//resetting the summing variable
		TI = 0;
		}	
	if(RI)
		{
		RI = 0;
		if(recieved_0 == 0)
		   recieved_0 = SBUF;//first character
		else if(recieved_1 == 0)
		   recieved_1 = SBUF;//second character
		else if(recieved_2 == 0)
		   recieved_2 = SBUF;//third character
		else if(recieved_3 == 0)
		   recieved_3 = SBUF;//fourth character
		else if(recieved_4 == 0)
		   recieved_4 = SBUF;//fifth character
		}
}

void main()
{
initialize_serial();
SBUF = 0xAA;
usec_wait(20);
while(1)
{
if(recieved_4 != 0)//this conditio will be true if the fourth character has some vlue in it
  {
  rr = recieved_0+recieved_1+recieved_2+recieved_3+recieved_4;
  recieved_0= 0x00;//reseting this varable bac to zero
  recieved_1= 0x00;//reseting this varable bac to zero
  recieved_2= 0x00;//reseting this varable bac to zero
  recieved_3= 0x00;//reseting this varable bac to zero
  recieved_4= 0x00;//reseting this varable bac to zero
  SBUF = rr;//sending out the result
  }
}
}
 



Please help me out...

List of 4 messages in thread
TopicAuthorDate
String of characters serially            01/01/70 00:00      
   Some more info needed and some tips            01/01/70 00:00      
      Thanks Kiran            01/01/70 00:00      
         Framing + counting            01/01/70 00:00      

Back to Subject List