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 CCS Technical Support

Active low pin?

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



Joined: 19 Feb 2008
Posts: 5

View user's profile Send private message

Active low pin?
PostPosted: Tue Feb 19, 2008 3:35 am     Reply with quote

Hi

How to make active low assigment at a pin?

//At this assigment you must remember whitch is active low or not
#define led_r PIN_A4 //output is active low !
#define led_g PIN_A5 //output is active low !

--

//why cant i do this? making the pin as active low
#define led_r !PIN_A4 //output is active low !

//Flemming
Ttelmah
Guest







PostPosted: Tue Feb 19, 2008 3:53 am     Reply with quote

The definition 'PIN_A4', is not the actual pin, but a numeric value, to _address_ the pin. Inverting this, will simply result in addressing the wrong location.
The answer, if you are using -ve logic, is to define your own versions of the pin access functions, so something like:
Code:

#define led_r PIN_A4 //output is active low !
#define led_g PIN_A5 //output is active low !
#define TURN_ON(x) output_low(x)
#define TURN_OFF(x) output_high(x)


Then to turn on the LED, you use:

TURN_ON(led_r);

and similarly, use 'TURN_OFF' as needed. Obviously choose the names to make it plain what is going on.
You could also use the 'output_bit' function in a similar way, with:
Code:

#define ON (0)
#define OFF (1)

output_bit(led_r,ON);


Best Wishes
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Tue Feb 19, 2008 7:19 am     Reply with quote

Or, something like this:

#define LEDRed(on) output_bit (PIN_B4, on) // Active Hi

#define LEDRed(on) output_bit (PIN_B4, !on) // Active Lo

Then, LEDRed(0) turns it off; LEDRed(1) turns it on Smile

Ken
flemse



Joined: 19 Feb 2008
Posts: 5

View user's profile Send private message

PostPosted: Tue Feb 19, 2008 9:40 am     Reply with quote

Hi

Thanks a lot thats help:-)

Flemming
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