View previous topic :: View next topic |
Author |
Message |
Mounty
Joined: 12 Jul 2013 Posts: 12
|
Newby needs help switching on LED |
Posted: Fri Jul 12, 2013 11:47 am |
|
|
Hi,
I'm trying to interface a Playstation controller with a PIC16F628A to help with a robotics project at a local college.
I'm just in the early stages, and things seem to be going ok, I've got as far as sending control codes to put the PS2 controller into analogue mode etc.
Now I'm trying to light up an LED that's connected to RB0 when I press a button on the controller, but so far no luck. This is the syntax I'm using:
if(!bit_test(DATA5,7)) {output_b(0b00000001);} else{);} //If SQUARE pressed
Can anyone please help me with this?
Thanks in advance. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Jul 12, 2013 12:27 pm |
|
|
Code: |
if(!bit_test(DATA5,7)) output_high(PIN_B0);
|
assuming pin B0 has a 3.3k resistor in series with led ANODE and led Cathode is ground
then it comes down to your condtional expression being TRUE |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 12, 2013 1:26 pm |
|
|
330 ohms would work much better for the LED series resistor.
Quote: | if(!bit_test(DATA5,7)) {output_b(0b00000001);} else{);} //If SQUARE pressed
|
Post the statement where you define or declare DATA5. Also post if you
are using fast_io mode.
You really need to post a test program. There are so many things that
could be wrong. Posting one line won't quickly solve the problem.
For example, this thread in the link below on a button and an LED shows
a super simple test program. (Really too simple, in that it has no
debouncing on the button).
http://www.ccsinfo.com/forum/viewtopic.php?t=47380
This next link is an example of how not to post a test program.
http://www.ccsinfo.com/forum/viewtopic.php?t=50800
He has posted one million lines of code. Whatever you do, don't do that. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Jul 12, 2013 3:33 pm |
|
|
Code: | if(!bit_test(DATA5,7)) {output_b(0b00000001);} else{);} //If SQUARE pressed | This line has a syntax error so we know for sure this is not actual code you are using. Pointless to even try solving your problem.
There are so many things that can be wrong. Now you expect us to shoot from the hip and waste a lot of our time in mentioning all possible mistakes.
You have to put in a little bit more effort and post a tiny but complete program to reproduce your problem. I could post that 5 line program here, but it is your problem so I think you should do it.
Another tip for becoming a better programmer:
I assume DATA5 is an 8 bit variable (at least, that is what the bit_test function expects). If so, then it is good practice to write variable names in lower case, all capitals is reserved for constants and macro's. It makes reading a lot easier when everyone follows the same conventions. |
|
|
Mounty
Joined: 12 Jul 2013 Posts: 12
|
|
Posted: Sat Jul 13, 2013 2:38 am |
|
|
PCM programmer wrote: | 330 ohms would work much better for the LED series resistor.
Quote: | if(!bit_test(DATA5,7)) {output_b(0b00000001);} else{);} //If SQUARE pressed
|
Post the statement where you define or declare DATA5. Also post if you
are using fast_io mode.
You really need to post a test program. There are so many things that
could be wrong. Posting one line won't quickly solve the problem.
For example, this thread in the link below on a button and an LED shows
a super simple test program. (Really too simple, in that it has no
debouncing on the button).
http://www.ccsinfo.com/forum/viewtopic.php?t=47380
This next link is an example of how not to post a test program.
http://www.ccsinfo.com/forum/viewtopic.php?t=50800
He has posted one million lines of code. Whatever you do, don't do that. |
As Meatloaf once said - I won't do that...
Here's where DATA5 is declared.
Code: | #bit LED_L1 = PORTB.0 //LED connected to B0
int i,PSX_WRITE,PSX_READ,DATA4,DATA5,DATA6,DATA7,DATA8,DATA9; |
It's still not working. I'll probably start making more progress when I have access to a scope in a few days. In the meantime, any tips would be appreciated. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Mounty
Joined: 12 Jul 2013 Posts: 12
|
|
Posted: Sat Jul 13, 2013 12:57 pm |
|
|
Thanks guys but I got it sorted! It was a silly power supply problem. Thanks for your help. |
|
|
|