View previous topic :: View next topic |
Author |
Message |
flemse
Joined: 19 Feb 2008 Posts: 5
|
Active low pin? |
Posted: Tue Feb 19, 2008 3:35 am |
|
|
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
|
|
Posted: Tue Feb 19, 2008 3:53 am |
|
|
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
|
|
Posted: Tue Feb 19, 2008 7:19 am |
|
|
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
Ken |
|
|
flemse
Joined: 19 Feb 2008 Posts: 5
|
|
Posted: Tue Feb 19, 2008 9:40 am |
|
|
Hi
Thanks a lot thats help:-)
Flemming |
|
|
|