Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Serial comm between uC and PC...

Status
Not open for further replies.
In your code this is wrong:

unsigned char *c;

That is just a pointer.. there is no memory reserved for characters. you need to define it as an array:

unsigned char c[20];

You can change the number to whatever size array you need.
 
To change the function to a unblocking type.. Use the receive flag.

C:
unsigned char HSerin()    
 {     
   if (RCIF)                     // Is there a character    
      return RCREG;                    // return character 
   else
       return   255;      // Or return -1
  }
 
what does this mean??

Nothing.. I think that was bad code from Ian. You can't return error codes in the same path you return data.. they need to be separated.
 
Nothing.. I think that was bad code from Ian. You can't return error codes in the same path you return data.. they need to be separated.

Yes you can if he uses ascii like I suggested a good while back.... This way he can learn software control..

Ritesh... If you use ascii like I showed you, you only need 0 to 127 ascii characters... So if the function returns 255 ( -1) then you know that a character isn't here yet!!!
 
Yes you can if he uses ascii like I suggested a good while back.... This way he can learn software control..

Ritesh... If you use ascii like I showed you, you only need 0 to 127 ascii characters... So if the function returns 255 ( -1) then you know that a character isn't here yet!!!

True.. You just have to know what kind of data is coming in. I was thinking "in general".. which actually makes things very complicated..
 
I'm trying to simplify the serial transfer for Ritesh... Using binary data transfers wil be a tiny bit over his head... Be my guest if you can show him packet transfers.....

Ritesh just got the thing working when you came up with that unblocking code.. that made his head spin.
 
I have one question, can we transfer data from uC to PC via UART and then this data to another using team viewer sharing to PC...?
I mean to say how to copy/move data to teamviwer from hyperterminal ?
 
It should be simple if you want to send the same piece of data to two PCs. Do you have another UART to USB converter for the other PC?
 
I am trying to compare two string one stored in memory other is scanned..
the problem is that while reading string from terminal i am using array the length will depend on it.
so, comparing of string will be wrong can't we read string in such a way without using a fixed size and compare it???

Code:
unsigned char b[10];
unsigned char *c="Hello";

for(char x=0;x<6;x++){
b[x]=HSerin(); 

}

int result = strncmp(c,b, compareLimit);

if(result > 0){
ch='a';
HSerout(ch);
}

else if(result < 0)
		{
ch='b';
HSerout(ch);
		}
else{
ch='c';
HSerout(ch);
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top