# Serial comm using pic16f877a....

#### RRITESH KAKKAR

Joined Jun 29, 2010
2,829
so, what changes to do ?/
void should be removed?

#### DerStrom8

Joined Feb 20, 2011
2,390
The function prototype should not be omitted. Compilers are known to do pretty sketchy things when there is no prototype, best case, it assumes an int return type. Omitting it will probably cause a warning for the PIC compiler...

This should be left in.
For some reason I was thinking that "void xxx(void);" and "void xxx(void){.....}" were both prototypes.

But Edeca over at ETO already found your problem. It has to do with this statement. See if you can find it yourself--you'll kick yourself when you do

Rich (BB code):
if(RCREG=='b');
{
f =  'a' ;
HSerout(f);
__delay_ms(250);
}

#### RRITESH KAKKAR

Joined Jun 29, 2010
2,829
ch= HSerin();
if(ch =='b')
{

while(*a!=0)
{
ch=*a++;
HSerout(ch);
__delay_ms(250);
}
}
if(ch =='a')
{

while(*b!=0)
{
ch=*b++;
HSerout(ch);
__delay_ms(250);
}
}

}
}

#### DerStrom8

Joined Feb 20, 2011
2,390
Why did you just post that code?

EDIT: I see you changed RCREG to ch. I don't know if you have to do that or not, but the problem was that you had a semicolon after the "if(RCREG == 'b')"

#### RRITESH KAKKAR

Joined Jun 29, 2010
2,829
ut the problem was that you had a semicolon after the "if(RCREG == 'b')"
yes semicolon was problem...

#### DerStrom8

Joined Feb 20, 2011
2,390
So after removing the semicolon, does it work?

#### RRITESH KAKKAR

Joined Jun 29, 2010
2,829
yes.......................

#### RRITESH KAKKAR

Joined Jun 29, 2010
2,829
I am little bit confused..
while(1) mean loop forever,
but while(!TXIF); // Wait for module to finish
not clear to me ! 'NOT' so, if TXIF is 0 it will 1, like that?

#### DerStrom8

Joined Feb 20, 2011
2,390
I am little bit confused..
while(1) mean loop forever,
but while(!TXIF); // Wait for module to finish
not clear to me ! 'NOT' so, if TXIF is 0 it will 1, like that?
Yes, that is correct. That while statement essentially says that the program must wait until !TXIF is 0, so when TXIF becomes 1, the statement becomes 0, and it will break out of that loop and continue with the code.

#### t06afre

Joined May 11, 2009
5,934
In this case it would be perfectly OK to code like this
Rich (BB code):
while(TXIF==0);
The !(NOT) operator is a boolean operator. It works great on bit values. But be aware of that the NOT operator returns zero if its operand is nonzero, and 1 if its operand is zero. So in your case case as long TXIF=0. Your while loop will be equal to a while(1) loop.

#### RRITESH KAKKAR

Joined Jun 29, 2010
2,829
For storing string array is working correct.

Rich (BB code):
while(1)                        // endless Loop
{
ch='a';
HSerout(ch);//for testing uart is working

for(char t=0;t<6;t++){

c[t]= HSerin();

}
for(char t=0;t<5;t++) {
ch=c[t];
HSerout(ch); //sending back the data

}
}

But using pointer are not displaying back the data ....

Rich (BB code):
 while(1)                        // endless Loop
{
ch='a';
HSerout(ch);//for testing uart is working

for(char t=0;t<6;t++){

*c++= HSerin();

}
for(char t=0;t<5;t++) {
ch=*c++;
HSerout(ch); //sending back the data

}
}

#### RRITESH KAKKAR

Joined Jun 29, 2010
2,829
I think problem is here.....c addr is changing after storing...

Rich (BB code):
for(char t=0;t<5;t++) {
ch=*c++;
HSerout(ch); //sending back the data

}

#### RRITESH KAKKAR

Joined Jun 29, 2010
2,829
Hi,

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

Rich (BB 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);
}
}

}
}

#### DerStrom8

Joined Feb 20, 2011
2,390
Ritesh, you need to work on asking your questions in the form of a question.

Are you trying to ask us something with the above post, or make a statement?

If you can't ask questions properly, it is very difficult for us to answer them.

Matt

#### RRITESH KAKKAR

Joined Jun 29, 2010
2,829
I am just telling, problem solved......

#### DerStrom8

Joined Feb 20, 2011
2,390
I am just telling, problem solved......
I am very happy to hear that. Congratulations!

The reason I made my last post is because we cannot tell the difference between your questions and your statements. They often look alike.