Serial comm between uC and PC...

Status
Not open for further replies.

You aren't using this code on PC to PC transfers are you??? That code was for Hitech on a pic16... PC to PC needs different coding...
 
You aren't using this code on PC to PC transfers are you??? That code was for Hitech on a pic16... PC to PC needs different coding...

OK, this code was for comparing two string not for PC to PC....the problem in this code is that while scanning/reading the string it depend on size i mean on loop/array indexing i want to make it as per user size like pressing enter will terminate string like this..
 

Our biggest problem here is... You are struggling to program one device!!! Programming two.... To talk together... You really need to get one half working as you need it first....
Going off you "Window" thread, you can't get windows to send a string to the outside world... With VB6 you just chuck the MScomm control on a form and write

Code:
MSComm1.output " Hello outside world " & CRLF

It extremely simple...

You can chuck a button on the form and put the line in the button handler and keep repeating...
 

I would like to stop you for talking about PC to PC transfer...
I am thinking that i should first clear few doubt then move to data transfer.
I am trying to compare two string one is stored in uC memory and 2nd string is readied from PC to UART ten uC here i am not talking about PC to PC only one PC to uC...
for example as we do for making password, the problem i am repeating again is how to store string of variable size if enter is press then it should end after that comparing of that two string is to be done...
i hope now you got my point.
 
Comparing strings and all the other stuff should be learned, from a C language book, instantly. Do you have a semester in programming?
 
Please have a look on previous post i have done that asking for something else..
i want to make read char independent of array size i.e. real time or on pressing enter it should end reading/storing string from terminal window.
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);
}
 
Hi,

i have corrected the code working cool, this code will match the password in terminal window....after pressing ESC the string will terminate!

Code:
#define ESC 27
unsigned char *a=" Hello! Ask me a question!\n ";
unsigned char *w=" WRONG PASSWORD ";
unsigned char *m=" MATCHED PASSWORD ";
unsigned char b[10];
unsigned char *c="Hello";
unsigned char  HSerin(void);
 void HSerout(unsigned char ch),
 HSerinit(void); 

 void main(void)                        // program entry  
   {  
int compareLimit = 100;   
   TRISB=0x00;
   unsigned char ch ;         // <- LOOK HERE.
   ADCON1 = 0x6;                    // Analogue off    
   HSerinit();      
  __delay_ms(1); 

while(*a!=0)
{ 
    ch=*a++;   
    HSerout(ch);  
     __delay_ms(150);       
  }
while(1)                        // endless Loop       
  {  

for(char x=0;x<9;x++){
b[x]=HSerin(); 
if(b[x]== ESC){
b[x]=0;
break;
}

}

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

if(result > 0 || result < 0){
while(*w!=0)
{ 
    ch=*w++;   
    HSerout(ch);  
     __delay_ms(150);       
  }
}

else if(result==0)
		{
while(*m!=0)
{ 
    ch=*m++;   
    HSerout(ch);  
     __delay_ms(150);       
  }
		}



}
	}
 
Ritesh!!! A string compare is as simple as a number compare

Take "Password"

P = 80
a = 97
s = 115
s = 115
w = 119
o = 111
r = 114
d = 100

You can either check each number one by one
Or for a simple ( but not always correct ), solution. Add them all up.

The problem with the last solution is they can be out of order and still work..

The best way is to use strcmp(); in the string library

 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…