sub Routine HELP

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
ELAB-raph
Posts: 9
Joined: 08 Feb 2011 09:53

sub Routine HELP

#1 Post by ELAB-raph » 08 Feb 2011 10:04

Hi,

I am building a controller that works in a bus configuration, here for I am making new subRoutine.

My question is how can I make a function like UART1_Data_Ready(), that I can use the if function directly on the function whitout using an extra char/int.

kind regards

Raphael Baars
ELAB electronic systems
The netherlands

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: sub Routine HELP

#2 Post by braus » 08 Feb 2011 19:00

hello ELAB-raph.
You can check the state of RCIF flag bit which sets when a new byte was received. You can develop a polled function to take care of this bit or you can write an interrupt sub routine to achieve the same results.
Best Regards
Omar Galicia
Mexico City

ELAB-raph
Posts: 9
Joined: 08 Feb 2011 09:53

Re: sub Routine HELP

#3 Post by ELAB-raph » 09 Feb 2011 10:29

tnx for te reply,

But I dont no how to make a function like that. :$

what I want is to do :

void function(???) {
?????? how do I do this
}

if (function() == 1) {
...
}

Best Regards

Raphael Baars
ELAB

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: sub Routine HELP

#4 Post by braus » 10 Feb 2011 22:51

polled form...

Code: Select all

   .
   .
   .
   if(PIR1.RCIF)   //with this conditional you are checking when a byte was received in RCREG register
      {            //this code could be in main program or in a function definition.
      the code to proccess the data is here
      PIR1.RCIF
      }
   .
   .
   .
interrupted form...

Code: Select all

void interrupt(){

   if(PIR1.RCIF){
   proccessing the data here
   PIR1.RCIF=0;
   }
}
Best Regards
Omar Galicia
Mexico City

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

Re: sub Routine HELP

#5 Post by drdoug » 11 Feb 2011 13:50

A couple observations.
As was pointed out to me not too long ago, the RCIF bit (in most if not all cases) is not writeable. It is however cleared when you read RCREG.

Also, ELAB-raph asked about
what I want is to do :

Code: Select all

void function(???) {
?????? how do I do this
}

if (function() == 1) {
...
}
in this case, you want a returning value not a void. (pseudo code)

Code: Select all

unsigned char NerdFunction(void) {
    if(cool ==1)
      return 0;
    else if (lame == 1)
      return 1;
    }

...
// Now you can use something  like
if(!NerdFunction())
  KissAGirl();
 
and if you want to pass a value into the function

Code: Select all

#define Cool 0
#define lame 1

unsigned char NerdFunction(unsigned char HairStyle) {
    if(HairStyle == Cool)
      return 0;
    else if (HairStyle == lame)
      return 1;
    }

...
// Now you can use something  like
if(!NerdFunction(MyHair))
  KissAGirl();
 
Hope it helps.

ELAB-raph
Posts: 9
Joined: 08 Feb 2011 09:53

Re: sub Routine HELP

#6 Post by ELAB-raph » 11 Feb 2011 15:43

tnx man,

This was exectly what I was looking for.

I wel try it out soon.

Raphael Baars
ELAB

Post Reply

Return to “mikroC PRO for PIC General”