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

Problem with library of utility functions- CCS Example

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



Joined: 11 Feb 2009
Posts: 5
Location: High City .jb

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

Problem with library of utility functions- CCS Example
PostPosted: Wed Apr 13, 2011 1:26 am     Reply with quote

Compile no 0 error and 2 warnings but after run it does not work. It should be, Check that with each button press, the LEDs increment in a binary number 0-7 as shown here. LED on binary sequence, 001,010...
Hope somebody can help. Thank You
Code:

EX5
....................................
#include <prototype.h>
#include <utility.c>
void main() {
int count = 0;
//int n = 1;
while(TRUE) {
show_binary_on_leds(count);
wait_for_one_press();
count++;
}
}
.........................................

prototype.h
........................................
#include <18f4520.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay(clock=20000000)
#define GREEN_LED PIN_A0
#define YELLOW_LED PIN_B4
#define RED_LED PIN_B5
#define PUSH_BUTTON PIN_B1
................................................

utility.c
.........................................
wait_for_one_press() {
while(input(PUSH_BUTTON)) ;
while(!input(PUSH_BUTTON)) ;

}
show_binary_on_leds(int n) {
output_high(GREEN_LED);
output_high(YELLOW_LED);
output_high(RED_LED);
if( bit_test(n,0) )
output_low(GREEN_LED);
if( bit_test(n,1) )
output_low(YELLOW_LED);
if( bit_test(n,2) )
output_low(RED_LED);
}

thank you
_________________
bla -bla bla
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Apr 13, 2011 1:50 am     Reply with quote

What are the warnings?
What does it do?

Your problem is most likely due to bounce.
Do you find that when you press the button that the LEDS count up realy fast, prob too fast to notice and then stop at some random value?
This is because as you press the button it doesn't do a clean make/break but will do several, possibly 100s within a very short time. you need to account for this:-

Code:

while(input(PUSH_BUTTON));  // Wait for press
  delay_ms(10);                    // ignore bounce
while(!PUSH_BUTTON);          // Wait for lift
  delay_ms(10);                    // ignore bounce

Something like that.

But then again it could be your hardware.
Without knowing the symptoms it is hard to say.
khairul786



Joined: 11 Feb 2009
Posts: 5
Location: High City .jb

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

PostPosted: Wed Apr 13, 2011 3:20 am     Reply with quote

I try that all already. The warning
1. Utility.c "Line 2[1,19]: Function not Void and does not return a value wait for one press.
2. Utility.c "Line 11[1,20]:Function not valid and does not return a value show_binary_on_leds.

Hardware is verify for program with out call function, it ok. [/url]
_________________
bla -bla bla
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Apr 13, 2011 5:22 am     Reply with quote

So if you dont call the wait_for_one_press() function in main the leds flash ?

I suspect your putton is not working, prob due to hardware.
how have you got it wired up?
Pull UP, Pull down?
Ttelmah



Joined: 11 Mar 2010
Posts: 19368

View user's profile Send private message

PostPosted: Wed Apr 13, 2011 7:40 am     Reply with quote

The warnings, are not your problem.
They say exactly 'why' they are occurring. You have declared all your functions without any 'return' type. By default in this case, C assumes a function returns an int. Yet you then return nothing. So the warnings.
There is a 'void' return type to specifically say 'this function does not return a value'. Use it.
Code:

void wait_for_one_press(void) {
   while(input(PUSH_BUTTON)) ;
   while(!input(PUSH_BUTTON)) ;
}

However these are just _warnings_, not errors. They are saying 'you are not declaring this right - may matter or not'. Since you don't use the return value, it doesn't matter at all.

I have to agree with Wayne. Most likely problem is the button. Either the pull up resistor you have used is not pulling the pin properly high (you _do_ have a pull up resistor on the input.....), or the button is not pulling the signal low.

Best Wishes
khairul786



Joined: 11 Feb 2009
Posts: 5
Location: High City .jb

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

PostPosted: Wed Apr 13, 2011 10:03 pm     Reply with quote

Thank you very much.. IT solve after put VOID... Razz
_________________
bla -bla bla
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