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

EX5.C function from Exercise book stumps newbie

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



Joined: 02 Mar 2004
Posts: 1
Location: nyc

View user's profile Send private message

EX5.C function from Exercise book stumps newbie
PostPosted: Tue Mar 02, 2004 8:07 am     Reply with quote

Hi All -

I'm just getting started with PCWH and am going through the CCS Exercise Book. I've encountered a problem with the following function (from Ex5.C), that I've excerpted from the complete code:

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) ) //here is where the problem seems to be
output_low (Red_LED) ;
}

The problem is that the RED_LED is ALWAYS on (output_low), while the others behave properly in response to a button push that increments a binary number. I've checked my wiring, code, etc... I am NOT using the CCS ICD-S unit, or the Prototyping board. Instead, I'm using another programmer and a breadboarded circuit for the PIC. All of the other, previous exercises I have done from the booklet have worked perfectly.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 02, 2004 12:35 pm     Reply with quote

You need to see the value of the parameter that is being passed
to the function. One way to do this, is to put a printf statement
at the start of the function and display the value of n on a terminal
window on your PC. If n always has bit 2 set = 1, then that's
the reason why the Red LED is always on. In that case you should
check that code that is calling the function. Somewhere in that
code, it's setting bit 2 of the n parameter to 1.

show_binary_on_leds (int n) {
printf("n = %x \n\r", n); // Add this line to see the value of n
output_high (Green_LED) ;
output_high (Yellow_LED) ;

My assumption is that your test board supports RS232 output to
your PC, and that you have a terminal window running (such as
HyperTerminal). If your supports output to an LCD, then do this:
printf(lcd_putc, "n = %x \n\r", n);

Or, if you're using a debugger, then set a breakpoint and view the
value of n in a watch window.
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