nikhilrajg
Member level 3
- Joined
- Mar 2, 2012
- Messages
- 63
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Manipal,Karnataka,India
- Activity points
- 1,834
So, you can not read the data that is transmitted from hyper-terminal to the PIC?
yes Exactly.. I can not read the data from hyper terminal to the PIC.
Thanks.
Regards.
Nikhil Raj.
Nikhil Raj
---------- Post added at 14:57 ---------- Previous post was at 12:58 ----------
hello,
This code is from the book "Learning to fly the PIC24 by Lucio Di Jasio",, This is really a good book to start with for newbies.. But I think that bellow code from this book is wrong .. can You just please check it.. Have a look over it,..
Code:
main()
{
char s[BUF_SIZE];
// 1. init the console serial port
initU2();
// 2. text prompt
clrscr();
home();
putsU2( “Learn to fl y with the PIC24!”);
// 3. main loop
while ( 1)
{
putU2(“>”); // prompt
// 3.1 read a full line of text
getsnU2( s, BUF_SIZE);
// 3.2 send a string to the serial port
putsU2( s);
// 3.3 send a carriage return
putU2(‘\r’);
} // main loop
}// main
Because He's calling the function ""getsnU2(s,BUF_SIZE)"" BUF_SIZE = 128.. But for now "s" does not have any value.. How can he pass "s" without value ?? So thats why the function is not reading the characters from the terminal if I am not wrong. Bellow are 2 different ""getsnU2"" fucntions.. Please check it..
Code:
char *getsnU2( char *s, int len)
{
char *p = s; // copy the buffer pointer
do{
*s = getU2(); // wait for a new character
if ( *s==’\r’) // end of line, end loop
break;
s++; // increment buffer pointer
len--;
} while ( len>1 ); // until buffer full
*s = ‘\0’; // null terminate the string
return p; // return buffer pointer
} // getsnU2
Code:
char *getsnU2( char *s, int len)
{
char *p = s; // copy the buffer pointer
int cc = 0; // character count
do{
*s = getU2(); // wait for a new character
putU2( *s); // echo character
if (( *s==BACKSPACE)&&( s>p))
{
putU2( ‘ ‘); // overwrite the last character
putU2( BACKSPACE);
len++;
s--; // back the pointer
continue;
}
if ( *s==’\n’) // line feed, ignore it
continue;
if ( *s==’\r’) // end of line, end loop
break;
s++; // increment buffer pointer
len--;
} while ( len>1 ); // until buffer full
*s = ‘\0’; // null terminate the string
return p; // return buffer pointer
} // getsnU2char *getsnU2( char *s, int len)
Thank You very much.
Regards,
Nikhil Raj.
Last edited: