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 support@ccsinfo.com

reading RCREG 18f4520

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



Joined: 12 Jan 2009
Posts: 33

View user's profile Send private message

reading RCREG 18f4520
PostPosted: Fri Jan 23, 2009 5:00 am     Reply with quote

In the 18f4520 datasheet, it says how the RCIF flag can be used to alert incoming data, and this flag is cleared everytime the RCREG is read.

my code

Code:
      for (i=0;i<60;i++)
      {
         if(bit_RCIF == TRUE)
            string[i] = reg_RCREG;
      }


For some reason i can use this technique elsewhere, but when done here the RCIF bit never gets cleared.

matt
Ttelmah
Guest







PostPosted: Fri Jan 23, 2009 6:18 am     Reply with quote

Show your definitions of reg_RCREG, and bit_RCIF.
Also consider adding error checking. This code will fail if the OERR bit has become set.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Jan 23, 2009 8:19 am     Reply with quote

Your code example is too short to give a definitive answer, but what makes me suspicious is: why are you looping 60 times?
It will take some time for a character to be received over a serial line. Even 115kbaud is slow in computer terms. If you are sending a stream of data to the PIC it will read about 2 or 3 characters and then the 60-times loop will be finished. Checking the RCIF flag again, for example, a millisecond later will show the RCIF flag to be set again by the next character being received.

Not exactly sure what you want to achieve, but you'll have to redesign this piece of code. One of the best ways to receive data is to do it in the background and periodically have your main routine check data to be received. A good example of how to implement this is the ex_sisr.c example program supplied with your compiler.

Note that instead of:
Code:
if(bit_RCIF == TRUE)
  string[i] = reg_RCREG;
you can write:
Code:
if (kbhit())
    string[i] = getc();
I favour the second version as it is easier to read (more 'self explaining') and easier to port to another processor because you don't have to worry about register addresses.
mshearer



Joined: 12 Jan 2009
Posts: 33

View user's profile Send private message

PostPosted: Tue Jan 27, 2009 3:05 am     Reply with quote

using kbhit is a great idea thanks Smile

What i am trying to do is take receive 60bytes of Hex and place them all into an array.

This seems to work
Code:
      while (k<60)
      {
         if (kbhit())
         {
             string[k] = getc();
             k=k+1;
          }
       }


except my terminal program hangs up after about the 6th byte if i enter
0102030405060708091011121314151617-----60

I'll have a proper interface set up soon though.

thanks for the help,
matt
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