Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC24FJ128GA010 serial port programming(UART1) using debugger MPLAB ICD 2

Status
Not open for further replies.
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:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top