|
|
View previous topic :: View next topic |
Author |
Message |
Tim_R
Joined: 02 Mar 2004 Posts: 1 Location: nyc
|
EX5.C function from Exercise book stumps newbie |
Posted: Tue Mar 02, 2004 8:07 am |
|
|
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
|
|
Posted: Tue Mar 02, 2004 12:35 pm |
|
|
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. |
|
|
|
|
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
|