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

Newby needs help switching on LED

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



Joined: 12 Jul 2013
Posts: 12

View user's profile Send private message

Newby needs help switching on LED
PostPosted: Fri Jul 12, 2013 11:47 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Fri Jul 12, 2013 12:27 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 12, 2013 1:26 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 12, 2013 3:33 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 13, 2013 2:38 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 13, 2013 9:06 am     Reply with quote

You still didn't post an LED test program, so here's one:
http://www.ccsinfo.com/forum/viewtopic.php?t=43952&start=7
Mounty



Joined: 12 Jul 2013
Posts: 12

View user's profile Send private message

PostPosted: Sat Jul 13, 2013 12:57 pm     Reply with quote

Thanks guys but I got it sorted! It was a silly power supply problem. Thanks for your help.
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