Searching \ for '[PIC] Having function problems in MPLAB' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/languages.htm?key=mplab
Search entire site for: 'Having function problems in MPLAB'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Having function problems in MPLAB'
2006\03\17@040230 by mattchristisen

picon face

Hello all. I am working on a project using a 16f627a and I am quickly running
out of program space on the mcu. I am also very new to pic's and C.
To free up some space I am trying to use functions for repetetive code,
delays in my case. I added one function and everything worked fine, but when
I add more than one I seem to get compiler warnings ("function declared
implicit int") and the code stops working properly. The following is a
portion of the code that works(problem areas in bold):

int i, j, Acounter, Bcounter;            // if A or B counter = 1 then the
delay is approx. .35secs
unsigned long ABcounter;        // when ABcounter = 1 the delay is approx.
51.43 micro seconds

 
main()
{

  CMCON = 7;        //Turn Off Comparators
  PORTA = 0x3F;        //set port A1 thru A5 to high and A6 and A7 to low
  PORTB = 0xFF;        //set port b to high
  TRISB = 0;            //set port b to output for LED Display
  TRISA6 = 0;            //set port a6 to output for Bottle A output
  TRISA7 = 0;            //set port a7 to output for Bottle B output
     
  while (1 == 1)               //  Loop Forever
      {
        while ((RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) & (RA4==1))      
//Bottle A alarming
          {
              if ((Acounter == 300) & (RA0 ==1) & (RA1 == 0) & (RA2 ==0))  
//Bottle A finished timer
                  {
                      RA6 = 1;        //output alarm
                      RA7 = 0;
                      PORTB = 0x2;    //display A
                  }
              else                                                      
//Bottle A in timer
                  {
                      RA6 = 0;
                      RA7 = 0;
                      PORTB = 0x7F;    //clear display
                      DelayOne();
                      PORTB = 0x2;    //display A
                      for (i = 0; ((i < 75) & (RA0 == 1) & (RA1 == 0) &
(RA2 == 0) & (RA3==1) & (RA4==1)); i++)
                      for (j = 0; ((j < 75) & (RA0 == 1) & (RA1 == 0) &
(RA2 == 0) & (RA3==1) & (RA4==1)); j++);
                      if (Acounter < 300)     // 5 is 2 seconds and 300 is
1min45sec
                          Acounter++;
                  }
          }
}
DelayOne()
{
  for (i = 0; ((i < 100) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1)
& (RA4==1)); i++)
                       for (j = 0; ((j < 100 & (RA0 == 1) & (RA1 == 0) &
(RA2 == 0) & (RA3==1) & (RA4==1)); j++);
}




This DelayOne function seems to work great, but when I add a second (example
below), things do not work as I would expect:




int i, j, Acounter, Bcounter;            // if A or B counter = 1 then the
delay is approx. .35secs
unsigned long ABcounter;        // when ABcounter = 1 the delay is approx.
51.43 micro seconds

 
main()
{

   CMCON = 7;        //Turn Off Comparators
   PORTA = 0x3F;        //set port A1 thru A5 to high and A6 and A7 to low
   PORTB = 0xFF;        //set port b to high
   TRISB = 0;            //set port b to output for LED Display
   TRISA6 = 0;            //set port a6 to output for Bottle A output
   TRISA7 = 0;            //set port a7 to output for Bottle B output
     
   while (1 == 1)               //  Loop Forever
       {
         while ((RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) & (RA4==1))      
//Bottle A alarming
           {
               if ((Acounter == 300) & (RA0 ==1) & (RA1 == 0) & (RA2 ==0))  
//Bottle A finished timer
                   {
                       RA6 = 1;        //output alarm
                       RA7 = 0;
                       PORTB = 0x2;    //display A
                   }
               else                                                      
//Bottle A in timer
                   {
                       RA6 = 0;
                       RA7 = 0;
                       PORTB = 0x7F;    //clear display
                       DelayOne();
                       PORTB = 0x2;    //display A
                       DelayTwo();
                       if (Acounter < 300)     // 5 is 2 seconds and 300 is
1min45sec
                           Acounter++;
                   }
           }
}

DelayOne()
{
   for (i = 0; ((i < 100) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1)
& (RA4==1)); i++)
                       for (j = 0; ((j < 100 & (RA0 == 1) & (RA1 == 0) &
(RA2 == 0) & (RA3==1) & (RA4==1)); j++);
}

DelayTwo()
{
  for (i = 0; ((i < 75) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) &
(RA4==1)); i++)
                       for (j = 0; ((j < 75) & (RA0 == 1) & (RA1 == 0) &
(RA2 == 0) & (RA3==1) & (RA4==1)); j++);
}  



If anyone can give me some pointers or guidance with this issue it would be
greatly appreciated.

Thanks....
Matthew Christisen
--
View this message in context: www.nabble.com/-PIC-Having-function-problems-in-MPLAB-t1296436.html#a3451957
Sent from the MicroControllers - PIC forum at Nabble.com.

2006\03\17@045039 by William Chops Westfield

face picon face

On Mar 17, 2006, at 12:40 AM, mattchristisen wrote:

> I seem to get compiler warnings ("function declared implicit int")

The warnings are because you haven't specified a return type for
your functions, and it defaults to int.  They should be
void DelayOne()...
void DelayTwo()...
You should have gotten a warning with only one function as well.

> and the code stops working properly.

But that doesn't explain what goes wrong.

I think all your occurances of "&" should be "&&", and your
comparisons against one and zero should be needed:

> while ((RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) & (RA4==1))

Might become
       while (RA0 && (!RA1) && (!RA2) && RA3 && RA4)

Better optimization is possible, but I'm not going to do all
your homework :-)

I don't think this explains why it's not working, though.  The
bitwise operations OUGHT to work out the same as the logical
operations in the end, just less efficiently...

You're not going to save any space moving two inline delays
into two separate delay functions.  You have to "factor" the
code so that you can call the same function from multiple
places, perhaps with different arguments.

I'd move your oft-repeated test of the RA bits into a
subroutine, so you have things like
       while (running_properly()) {
and
       for (i=0; i<100 && running_properly(); i++)

(except that there's a better way to do the RA tests that
would make it simple enough not to justify a subroutine.)

BillW

       

2006\03\17@051254 by Jan-Erik Soderholm

face picon face
mattchristisen wrote :

> Hello all. I am working on a project using a 16f627a...

A 1 Kword device, right ?

> I am also very new to pic's and C...

1. Use a 16F628A (2 Kwords) or 16F648A (4 Kwords).

2. Use Assembler (probably the best option on the 627A...).

Best Regards,
Jan-Erik.



2006\03\17@051411 by Chris Levin

flavicon
face
mattchristisen wrote:

>Hello all. I am working on a project using a 16f627a and I am quickly running
>out of program space on the mcu ... I am trying to use functions for repetetive code ... I added one function and everything worked fine, but when
>I add more than one I seem to get compiler warnings ("function declared
>implicit int")
>
Hi Matthew,

What C compiler are you using?

The problem looks like the way you have defined DelayOne and DelayTwo.
Some (most,all?) C compilers expect you to specify the return type and
parameters. In your case, since you take no parameters and return
nothing you should write your functions like:

void DelayOne(void)
{
   // code here
}

void DelayTwo(void)
{
   // code here
}

You should place "forward declarations" for subroutines at the top of
your file like so:
void DelayOne(void);
void DelayTwo(void);

So your program will look like this:

/* the program */

// Subroutines
void DelayOne(void);
void DelayTwo(void);

// Globals
int i,j, Acounter, Bcounter;

/* main */
void main(void)
{
   // main code here
}

/* DelayOne */
void DelayOne(void)
{
   // delay
}

/* DelayTwo */
void DelayTwo(void)
{
   // another delay
}

/* end of program */


Based on the compiler warning I think this will fix your problem. Since
you are new to C programming I would also like to recomend that you pick
a commenting method and use it consistently. All of your functions,
function prototypes and global variables should have comment sections.
This helps them stand out when you are reading through your source code
and that makes debugging easier.

Also keep in mind that if your program grows and you split it into two
or more C files that the global variables and functions in one file are
not going to be visible to functions in another file unless you take
additional steps. If you don't know how to do this please feel free to ask.

A really good book for C programming is "The C Programming Language",
Second Edition by Brian Kernighan and Dennis Ritchie. This is the
classic C book and I have used it for many years. When I started doing
embedded C it came in handy even though it's written with a Unix
background. If you are new to C then grab this book.

Hope all of this helps. If you have more questions please ask.

-Chris


2006\03\17@060416 by mattchristisen

picon face

Thanks BillW. I have tried specifying the return value with "void DelayOne()"
but the compiler stops the build for "type redeclared" directly after the
implicit int warning. Sounds like I am doing it wrong based on the error.


I do plan on getting rid of the bitwise operators and moving to logical
operators but I havent completely wrapped my mind around it yet but I am
working on it. Thanks for tip "while (RA0 && (!RA1) && (!RA2) && RA3 &&
RA4)". Makes more sense to me now, will work on that next.

Checked out my problem again and I see I mis-represented my problem in the
original post. Ok, this code works just fine:

#include <pic.h>

__CONFIG(INTIO & WDTDIS & PWRTEN & LVPDIS & MCLRDIS & UNPROTECT & UNPROTECT
& BORDIS);

int i, j, Acounter, Bcounter;                        // if A or B counter = 1 then the delay is
.35secs
unsigned long ABcounter;                // when ABcounter = 1 the delay is 51.43 micro
seconds

       
main()
{

   CMCON = 7;                //Turn Off Comparators
       PORTA = 0x3F;                //set port A1 thru A5 to high and A6 and A7 to low
       PORTB = 0xFF;                //set port b to high
   TRISB = 0;                        //set port b to output for LED Display
       TRISA6 = 0;                        //set port a6 to output for Bottle A output
       TRISA7 = 0;                        //set port a7 to output for Bottle B output
               
   while (1 == 1)               //  Loop Forever
           {
               while ((RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) & (RA4==1))        
//Bottle A alarming
                       {
                               if ((Acounter == 300) & (RA0 ==1) & (RA1 == 0) & (RA2 ==0))        //Bottle A
finished timer
                                       {
                                               RA6 = 1;                //output alarm
                                               RA7 = 0;
                                               PORTB = 0x2;        //display A
                                       }
                               else                                                                                                                //Bottle A in timer
                                       {
                                               RA6 = 0;
                                               RA7 = 0;
                                               PORTB = 0x7F;        //clear display
                                               DelayOne();
                                               PORTB = 0x2;        //display A
                                               DelayTwo();
                                               if (Acounter < 300)        // 5 is 2 seconds and 300 is 1min45sec
                                                       Acounter++;
                                       }
                       }
               while ((RA0 == 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) & (RA4==1))                                        
//Bottle B in alarm
                       {
                               if ((Bcounter == 300) & (RA0 ==0) & (RA1 == 1) & (RA2 ==0))                //Bottle B
finished timer
                                       {
                                               RA6 = 0;
                                               RA7 = 1;        //output alarm
                                               PORTB = 0x18;                //display b
                                       }
                               else                                                                                                                        //Bottle B in timer
                                       {
                                               RA6 = 0;
                                               RA7 = 0;
                                               PORTB = 0x7F;        //clear display
                                               for (i = 0; ((i < 100) & (RA0 == 0) & (RA1 == 1) & (RA2 == 0) &
(RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 100) & (RA0 == 0) & (RA1 == 1) & (RA2 == 0) &
(RA3==1) & (RA4==1)); j++);
                                               PORTB = 0x18;        //display b
                                               for (i = 0; ((i < 75) & (RA0 == 0) & (RA1 == 1) & (RA2 == 0) &
(RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 75) & (RA0 == 0) & (RA1 == 1) & (RA2 == 0) &
(RA3==1) & (RA4==1)); j++);
                                               if (Bcounter < 300)
                                                       Bcounter++;
                                       }
                       }
}                

DelayOne()
{
       for (i = 0; ((i < 100) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) &
(RA4==1)); i++)
                                               for (j = 0; ((j < 100) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) &
(RA3==1) & (RA4==1)); j++);
}

DelayTwo()
{
       for (i = 0; ((i < 75) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) &
(RA4==1)); i++)
                                               for (j = 0; ((j < 75) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) &
(RA3==1) & (RA4==1)); j++);
}




But when I add and additional funtion to the following while statement, the
first while statement operates properly while the second while does not. For
example:




while (1 == 1)               //  Loop Forever
           {
               while ((RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) & (RA4==1))        
//Bottle A alarming
                       {
                               if ((Acounter == 300) & (RA0 ==1) & (RA1 == 0) & (RA2 ==0))        //Bottle A
finished timer
                                       {
                                               RA6 = 1;                //output alarm
                                               RA7 = 0;
                                               PORTB = 0x2;        //display A
                                       }
                               else                                                                                                                //Bottle A in timer
                                       {
                                               RA6 = 0;
                                               RA7 = 0;
                                               PORTB = 0x7F;        //clear display
                                               DelayOne();
                                               PORTB = 0x2;        //display A
                                               DelayTwo();
                                               if (Acounter < 300)        // 5 is 2 seconds and 300 is 1min45sec
                                                       Acounter++;
                                       }
                       }
               while ((RA0 == 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) & (RA4==1))                                        
//Bottle B in alarm
                       {
                               if ((Bcounter == 300) & (RA0 ==0) & (RA1 == 1) & (RA2 ==0))                //Bottle B
finished timer
                                       {
                                               RA6 = 0;
                                               RA7 = 1;        //output alarm
                                               PORTB = 0x18;                //display b
                                       }
                               else                                                                                                                        //Bottle B in timer
                                       {
                                               RA6 = 0;
                                               RA7 = 0;
                                               PORTB = 0x7F;        //clear display
                                               for (i = 0; ((i < 100) & (RA0 == 0) & (RA1 == 1) & (RA2 == 0) &
(RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 100) & (RA0 == 0) & (RA1 == 1) & (RA2 == 0) &
(RA3==1) & (RA4==1)); j++);
                                               PORTB = 0x18;        //display b
                                               for (i = 0; ((i < 75) & (RA0 == 0) & (RA1 == 1) & (RA2 == 0) &
(RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 75) & (RA0 == 0) & (RA1 == 1) & (RA2 == 0) &
(RA3==1) & (RA4==1)); j++);
                                               if (Bcounter < 300)
                                                       Bcounter++;
                                       }
                       }
}                

DelayOne()
{
       for (i = 0; ((i < 100) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) &
(RA4==1)); i++)
                                               for (j = 0; ((j < 100) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) &
(RA3==1) & (RA4==1)); j++);
}

DelayTwo()
{
       for (i = 0; ((i < 75) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) &
(RA4==1)); i++)
                                               for (j = 0; ((j < 75) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) &
(RA3==1) & (RA4==1)); j++);
}

--
View this message in context: www.nabble.com/-PIC-Having-function-problems-in-MPLAB-t1296436.html#a3453854
Sent from the MicroControllers - PIC forum at Nabble.com.

2006\03\17@061135 by mattchristisen

picon face

Thanks BillW. I have tried specifying the return value with "void DelayOne()"
but the compiler stops the build for "type redeclared" directly after the
implicit int warning. Sounds like I am doing it wrong based on the error.


I do plan on getting rid of the bitwise operators and moving to logical
operators but I havent completely wrapped my mind around it yet but I am
working on it. Thanks for tip "while (RA0 && (!RA1) && (!RA2) && RA3 &&
RA4)". Makes more sense to me now, will work on that next.

Checked out my problem again and I see I mis-represented my problem in the
original post. Ok, this code works just fine:

#include <pic.h>

__CONFIG(INTIO & WDTDIS & PWRTEN & LVPDIS & MCLRDIS & UNPROTECT & UNPROTECT
& BORDIS);

int i, j, Acounter, Bcounter; // if A or B counter = 1 then the delay is
.35secs
unsigned long ABcounter; // when ABcounter = 1 the delay is 51.43 micro
seconds

     
main()
{

   CMCON = 7; //Turn Off Comparators
       PORTA = 0x3F; //set port A1 thru A5 to high and A6 and A7 to low
       PORTB = 0xFF; //set port b to high
   TRISB = 0; //set port b to output for LED Display
       TRISA6 = 0; //set port a6 to output for Bottle A output
       TRISA7 = 0; //set port a7 to output for Bottle B output
             
   while (1 == 1)               //  Loop Forever
           {
               while ((RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) &
(RA4==1)) //Bottle A alarming
                       {
                               if ((Acounter == 300) & (RA0 ==1) & (RA1 ==
0) & (RA2 ==0)) //Bottle A finished timer
                                       {
                                               RA6 = 1; //output alarm
                                               RA7 = 0;
                                               PORTB = 0x2; //display A
                                       }
                               else //Bottle A in timer
                                       {
                                               RA6 = 0;
                                               RA7 = 0;
                                               PORTB = 0x7F; //clear
display
                                               DelayOne();
                                               PORTB = 0x2; //display A
                                               DelayTwo();
                                               if (Acounter < 300) // 5 is
2 seconds and 300 is 1min45sec
                                                       Acounter++;
                                       }
                       }
               while ((RA0 == 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) &
(RA4==1)) //Bottle B in alarm
                       {
                               if ((Bcounter == 300) & (RA0 ==0) & (RA1 ==
1) & (RA2 ==0)) //Bottle B finished timer
                                       {
                                               RA6 = 0;
                                               RA7 = 1; //output alarm
                                               PORTB = 0x18; //display b
                                       }
                               else //Bottle B in timer
                                       {
                                               RA6 = 0;
                                               RA7 = 0;
                                               PORTB = 0x7F; //clear
display
                                               for (i = 0; ((i < 100) &
(RA0 == 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 100) &
(RA0 == 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) & (RA4==1)); j++);
                                               PORTB = 0x18; //display b
                                               for (i = 0; ((i < 75) & (RA0
== 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 75) & (RA0
== 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) & (RA4==1)); j++);
                                               if (Bcounter < 300)
                                                       Bcounter++;
                                       }
                       }
}

DelayOne()
{
       for (i = 0; ((i < 100) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) &
(RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 100) &
(RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) & (RA4==1)); j++);
}

DelayTwo()
{
       for (i = 0; ((i < 75) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) &
(RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 75) & (RA0
== 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) & (RA4==1)); j++);
}




But when I add and additional funtion to the following while statement, the
first while statement operates properly while the second while does not. For
example:




while (1 == 1)               //  Loop Forever
           {
               while ((RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) &
(RA4==1)) //Bottle A alarming
                       {
                               if ((Acounter == 300) & (RA0 ==1) & (RA1 ==
0) & (RA2 ==0)) //Bottle A finished timer
                                       {
                                               RA6 = 1; //output alarm
                                               RA7 = 0;
                                               PORTB = 0x2; //display A
                                       }
                               else //Bottle A in timer
                                       {
                                               RA6 = 0;
                                               RA7 = 0;
                                               PORTB = 0x7F; //clear
display
                                               DelayOne();
                                               PORTB = 0x2; //display A
                                               DelayTwo();
                                               if (Acounter < 300) // 5 is
2 seconds and 300 is 1min45sec
                                                       Acounter++;
                                       }
                       }
               while ((RA0 == 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) &
(RA4==1)) //Bottle B in alarm
                       {
                               if ((Bcounter == 300) & (RA0 ==0) & (RA1 ==
1) & (RA2 ==0)) //Bottle B finished timer
                                       {
                                               RA6 = 0;
                                               RA7 = 1; //output alarm
                                               PORTB = 0x18; //display b
                                       }
                               else //Bottle B in timer
                                       {
                                               RA6 = 0;
                                               RA7 = 0;
                                               PORTB = 0x7F; //clear
display
                                               DelayOne();
                                               PORTB = 0x18; //display b
                                               for (i = 0; ((i < 75) & (RA0
== 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 75) & (RA0
== 0) & (RA1 == 1) & (RA2 == 0) & (RA3==1) & (RA4==1)); j++);
                                               if (Bcounter < 300)
                                                       Bcounter++;
                                       }
                       }
}

DelayOne()
{
       for (i = 0; ((i < 100) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) &
(RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 100) &
(RA0 == 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) & (RA4==1)); j++);
}

DelayTwo()
{
       for (i = 0; ((i < 75) & (RA0 == 1) & (RA1 == 0) & (RA2 == 0) &
(RA3==1) & (RA4==1)); i++)
                                               for (j = 0; ((j < 75) & (RA0
== 1) & (RA1 == 0) & (RA2 == 0) & (RA3==1) & (RA4==1)); j++);
}
--
View this message in context: www.nabble.com/-PIC-Having-function-problems-in-MPLAB-t1296436.html#a3453961
Sent from the MicroControllers - PIC forum at Nabble.com.

2006\03\17@071624 by Byron A Jeff

face picon face
On Fri, Mar 17, 2006 at 11:12:54AM +0100, Jan-Erik Soderholm wrote:
> mattchristisen wrote :
>
> > Hello all. I am working on a project using a 16f627a...
>
> A 1 Kword device, right ?

Right.

>
> > I am also very new to pic's and C...
>
> 1. Use a 16F628A (2 Kwords) or 16F648A (4 Kwords).

Or a 16F88 with 4Kwords.

> 2. Use Assembler (probably the best option on the 627A...).

Always a debate. My current thesis is that newbies should learn
assembler first, then move to high level language. That way they can
communicate effectively and make intelligent decisions about
space allocations for algorithms.

But if it's a on off project and the code is working. Then
solution #1 (chip with more memory) is the right answer to
solve the problem.

BAJ

2006\03\17@072437 by Michael Rigby-Jones

picon face


>-----Original Message-----
>From: spam_OUTpiclist-bouncesTakeThisOuTspammit.edu [.....piclist-bouncesKILLspamspam@spam@mit.edu]
>Sent: 17 March 2006 11:04
>To: piclistspamKILLspammit.edu
>Subject: Re: [PIC] Having function problems in MPLAB
>
>
>
>Thanks BillW. I have tried specifying the return value with
>"void DelayOne()" but the compiler stops the build for "type
>redeclared" directly after the implicit int warning. Sounds
>like I am doing it wrong based on the error.

Yes, the whole point of function prototypes is that they must match the function definition exactly.  In your case you should have something like this:

#include <pic.h>

/* function prototypes */
void DelayOne(void);
void DelayTwo(void);


/* function definitions */
void DelayOne(void) {

/* delay stuff */

}

void DelayTwo(void) {

/* more delay stuff */

}

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

2006\03\17@110551 by Bob Axtell

face picon face
space?

Going to a PIC16F628A doubles your space. going to F648A makes it 4X.

You don't need to compress...

--Bob

mattchristisen wrote:

{Quote hidden}

--
Note: To protect our network,
attachments must be sent to
.....attachKILLspamspam.....engineer.cotse.net .
1-520-850-1673 USA/Canada
http://beam.to/azengineer

2006\03\17@121349 by Michael L. Ervin

picon face
Hi Matthew,
I've re-worked the code a bit to try to understand the logic.
I think you wanted to use "&&" instead of "&" for your logic tests.
I've also added function prototypes at the beginning of the code to
keep the compiler from producing the warnings.  You should put
these prototypes in some type of "header" file so they can be
used by other functions.
Hope this helps.

Mike


void DelayOne();
void DelayTwo();

main()
{
   CMCON  = 7;           //Turn Off Comparators
   PORTA  = 0x3F;        //set port A1 thru A5 to high and A6 and A7 to low
   PORTB  = 0xFF;        //set port b to high
   TRISB  = 0;           //set port b to output for LED Display
   TRISA6 = 0;           //set port a6 to output for Bottle A output
   TRISA7 = 0;           //set port a7 to output for Bottle B output

   while( 1 )    //  Loop Forever
   {
       while( (RA0 == 1)    // Bottle A alarming
       &&     (RA1 == 0)
       &&     (RA2 == 0)
       &&     (RA3 == 1)
       &&     (RA4 == 1) )
       {
           if( (Acounter == 300) //Bottle A finished timer
           &&  (RA0 == 1)
           &&  (RA1 == 0)
           &&  (RA2 == 0) )

           {
               RA6   = 1;      //output alarm
               RA7   = 0;
               PORTB = 0x2;    //display A
           }
           else  //Bottle A in timer
           {
               RA6   = 0;
               RA7   = 0;
               PORTB = 0x7F;   //clear display

               DelayOne();

               PORTB = 0x2;    //display A

               DelayTwo();

               if( Acounter < 300 )   // 5 is 2 seconds and 300 is
1min45sec
                   Acounter++;
           }
       }
}

void DelayOne()
{
   for( i = 0;
        ((i < 100)
        && (RA0 == 1)
        && (RA1 == 0)
        && (RA2 == 0)
        && (RA3 == 1)
        && (RA4 == 1));
        i++ )
   {
       for( j = 0;
            ((j < 100 )       // <<<<--- Was missing paren...
            && (RA0 == 1)
            && (RA1 == 0)
            && (RA2 == 0)
            && (RA3 == 1)
            && (RA4 == 1));
            j++ );
   }
}

void DelayTwo()
{
   for( i = 0;
        ((i < 75)
        && (RA0 == 1)
        && (RA1 == 0)
        && (RA2 == 0)
        && (RA3 == 1)
        && (RA4 == 1));
        i++ )
   {
       for( j = 0;
            ((j < 75)
            && (RA0 == 1)
            && (RA1 == 0)
            && (RA2 == 0)
            && (RA3 == 1)
            && (RA4 == 1));
            j++ );
   }
}

{Original Message removed}

2006\03\17@124515 by John Temples

flavicon
face
On Fri, 17 Mar 2006, Michael L. Ervin wrote:

> I've also added function prototypes at the beginning of the code to
>
> void DelayOne();
> void DelayTwo();

Those are not function prototypes.  Function prototypes specify the
number and types of the arguments, as well as the return type:

void DelayOne(void);
void DelayTwo(void);

--
John W. Temples, III

2006\03\17@125502 by Michael L. Ervin

picon face
You're right... thanks for the correction.

----- Original Message -----
From: "John Temples" <EraseMEpiclistspam_OUTspamTakeThisOuTxargs.com>
To: "Microcontroller discussion list - Public." <piclistspamspam_OUTmit.edu>
Sent: Friday, March 17, 2006 9:45 AM
Subject: Re: [PIC] Having function problems in MPLAB


{Quote hidden}

> --

2006\03\18@052942 by mattchristisen

picon face

thanks for all the advice. no more warnings from the compiler and I have
switched to logical operator.
I also found out that my problem wasnt with the funtions at all, it was the
contents of the functions.
Turns out the code wasnt exactly repetitive in every case so the function
would contradict what was happening in the current statement....Thanks again
for all the help!
--
View this message in context: www.nabble.com/-PIC-Having-function-problems-in-MPLAB-t1296436.html#a3469796
Sent from the MicroControllers - PIC forum at Nabble.com.

More... (looser matching)
- Last day of these posts
- In 2006 , 2007 only
- Today
- New search...