CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Reset RCREG

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

Reset RCREG
PostPosted: Fri Apr 24, 2009 2:00 pm     Reply with quote

Hi!

You can reset RCREG directly? or the system is this:

Code:
while(kbhit())
{
   printf("the character is:%c", getc());
 }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 2:21 pm     Reply with quote

See the clear_usart_receiver() function in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=1571&start=3
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 3:33 pm     Reply with quote

hi!

PCM programmer wrote:
See the clear_usart_receiver() function in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=1571&start=3


if i use the program crashes, i think it is a problem with the USART:

Code:
#byte RCREG = 0x1A

void clear_usart_receiver(void)
{
char c;
c = RCREG;
c = RCREG;
c = RCREG;
}


if I use this I have no crashes:

Code:
void clear_usart(void)
{
char c;
c = getc();
c = getc();
c = getc();
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 3:52 pm     Reply with quote

Post your PIC.
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 5:33 pm     Reply with quote

Hi!

PCM programmer wrote:
Post your PIC.


with this work:

Code:
#include <16F877a.h>
#include <apricancello_gsm.h>
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <string.h>
#include <input.c>
#byte RCREG = 0x1A

#define  STRING_SIZE   51             // The number of characters allowed to input

 
void clear_usart(void)
{
char c;
c = getc();
c = getc();
c = getc();
}



void tipo_chiamata(char *chiamata)//, char *prima)
{
delay_ms (1000);
output_low (red_led);
printf("\n\nil valore di chiamata e' %s\n\n", chiamata); 
delay_ms (1000);
output_high (red_led);
delay_ms (1000);
clear_usart();
}

         
void inizializza()
{
printf("at+ipr=9600\r");
delay_ms(2000);
printf("at+clip=1\r");
delay_ms(1000);
printf("ate0\r");
delay_ms(2000);
clear_usart();
}


void main() {
int a;
char input_str[STRING_SIZE];
inizializza();

                   
                     while(true)
                     {
      for (a=0; a<4; a++)
      {
      get_string(input_str,STRING_SIZE);     // gets the string x4
      }

   printf("ath\r");
   tipo_chiamata(input_str);
                     }
}


This does not work:

Code:
void clear_usart(void)
{
char c;
c = RCREG;
c = RCREG;
c = RCREG;
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 5:42 pm     Reply with quote

The RCREG version immediately clears the UART receiver and returns.
This routine takes only maybe 2us to execute, with a 20 MHz crystal.

Your getc() version waits for the first 3 characters to arrive in the UART
and throws them away. It could wait forever, if there are no characters
in the UART, or if less than 3 characters arrive.

I don't really know what the purpose of your code is.
Ttelmah
Guest







PostPosted: Sat Apr 25, 2009 2:21 am     Reply with quote

The 'safe' way to ue the standard getc, to clear the UART, is:
Code:

void clear_usart(void) {
   char c;
   while (kbhit()) c=getc();
}

This will read any characters waiting in the hardware buffer, but unlike the three successive reads, won't hang if charcaters are not available.

Just reading RCREG three times, will generate much more compact code, and do the same job.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group