View previous topic :: View next topic |
Author |
Message |
shapito
Joined: 21 Feb 2012 Posts: 9
|
function not void and does not return a value |
Posted: Thu Mar 22, 2012 10:39 am |
|
|
can somebody help me.why when I compile this program, error was shown.
#include <16F876A.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <can-18xxx8.c>
#define GREEN_LED PIN_A5
#define YELLOW_LED PIN_B4
#define RED_LED PIN_B1
#define PUSH_BUTTON PIN_A4
light_one_led(int led) {
output_high(GREEN_LED);
output_high(YELLOW_LED);
output_high(RED_LED);
switch(led){
case 0 : output_low(GREEN_LED); break;
case 1 : output_low(YELLOW_LED); break;
case 2 : output_low(RED_LED); break;
}
}
wait_for_one_press() {
while(input(PUSH_BUTTON));
while(!input(PUSH_BUTTON));
}
void main(){
while(TRUE) {
light_one_led(0);
wait_for_one_press();
light_one_led(1);
wait_for_one_press();
light_one_led(2);
wait_for_one_press();
}
}
it said "function not void and does not return a value light_one_led" and
"function not void and does not return a value wait_for_one_press". |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Mar 22, 2012 10:45 am |
|
|
If I remember rightly, in C subroutines not explicitly given a return type are assumed to be functions returning int. Try:
Code: |
void light_one_led(int led) {
output_high(GREEN_LED);
output_high(YELLOW_LED);
output_high(RED_LED);
switch(led){
case 0 : output_low(GREEN_LED); break;
case 1 : output_low(YELLOW_LED); break;
case 2 : output_low(RED_LED); break;
}
}
|
...and please use the formatting to display code.
RF Developer |
|
|
shapito
Joined: 21 Feb 2012 Posts: 9
|
|
Posted: Thu Mar 22, 2012 11:10 am |
|
|
thanx..its working...but the code "blah" i still confused where to put it.. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Mar 22, 2012 1:39 pm |
|
|
shapito wrote: | thanx..its working...but the code "blah" i still confused where to put it.. | What we mean is that your posted source code is more readable when you use the special code formatting tags from this forum. For more info read http://www.sitepoint.com/forums/misc.php?do=bbcode. The code tag is described half way down the page. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Thu Mar 22, 2012 2:18 pm |
|
|
You're also going to find that your routine to wait for the button press then wait for it not pressed has a "minor" flaw - if your pushbutton bounces like most do, then it will go through there as many times as it bounces. Probably not an issue here, but something to be aware of when you expect a single "press" to do something only once.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
|