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.

USART reception in c18

Status
Not open for further replies.
hello

use balise CODE to post some code part.


here one extra " € " is coming.
it's because Transmit register is not empty at the begining of program.
Try to send a LF caractere before , witch is not a visible car
or try to init TRMT=0



what is that 13 means ?

13=code of CR=Carriage Retrurn retur to begining of the line
10= code of LF=Line Feed goto next line
sometimes to change the line you can use LF, or LF+CR depending of terminal configuration

Code:
//for that i use getsUSART(a,5);
putsUSART(a);

Pay attention to use a buffer to contain all caracteres of the string
"a" is one charactere size only !

You can use the same treatment as in #8 , in your main()


Code:
#define CR 13;
#define LF 10;
#define BS 8;

#define MAX_LEN 80
char buffer[MAX_LEN];	// buffer de reception



void main()
unsigned char a;
int i,k;
i=0;
buffer[0]=0;
....
....

while(1)
{


if(PIR1bits.RCIF) // si un car arrive
   {
   a =Read1USART(); // le lire => RAZ  RCIF
   if(RCSTAbits.FERR || RCSTAbits.OERR)  // error treatment
     {
      RCSTAbits.CREN = 0 ; RCSTAbits.CREN= 1 ;
     }
    while(Busy1USART()); // par sécurité
    if (PORTBbits.RB1==0) Write1USART(a); // echo on display if RB1=0
     if( a == BS)   // erase  the last car with touch Back Slash (<-)
        {
         if(i>0){
             i--;  }
        }
      else
      {
      if(a != CR && i<MAX_LEN)
      {
        buffer[i++]=a ; // stockage dans le buffer
        }else
        {
         buffer[i]='\0'; // fin de chaîne si CR ou taille maxi
         i=0;
        put_RS(CR);put_RS(LF); // new empty line on display
        k=PutStr_RS(buffer);  // print out the content of buffer
        buffer[0]=0;  // re-init buffer stating point at the beginning
       }
      }
    }
.....
.....
}
}




your string can be as long as MAX_LEN buffer size or can be terminated by CR (enter Touch)
so no matter for the exact size of string if between 1 to 80 cars
 

thanks
i tried the above example..but it is not working.. it is showing error in

if( a == BS)
how can we compare the input dtring with one predefined string?

and here in my project we are sending sms to modem. so in pic how can we calculate the sms length?
 

Je veux bien donner un coup de main, mais là , c'est trop.
Gentil, serviable mais pas con à ce point .
in french because i don't know to translate it correctly in english!

At least, i think is not a good way to help you like this.
Sorry but you will do more progress and get satisfaction by doing all yourself.
Spend more time to study C langage, Datasheet ...
and so, you will get answers.

good luck.
 

hi td micro!

what was the mistake when you were not receiving character from keyboard?

thank you
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top