November 08, 2024, 03:05:33 AM

Power on = Relay on

Started by Ritmeester, January 20, 2014, 05:58:35 PM

Previous topic - Next topic

Ritmeester

I have the PIC-MAXI-WEB board.  When I power this board the two relay's are off.

I want to chance this situation in: when I power the board ONE relay is turning on.  (Pin goes high)

I think it has something to do with this code but I don't understand this code to make changes in it.

#define LED_PUT(a) LED0_IO = !!(a & 0x01);\
LED1_IO = !!(a & 0x02);\
LED2_IO = !!(a & 0x04);\
LED3_IO = !!(a & 0x08);\
LED4_IO = !!(a & 0x10);\
LED5_IO = !!(a & 0x20);\
LED6_IO = !!(a & 0x40);\
LED7_IO = !!(a & 0x80);\


Please explain to me on how to do this.

Thanks

Stanimir5F

Hello Ritmeester!

Sorry for the delay but I was inactive for the last few days.
As for your problem - you are right. The LED_PUT macro works for you. But this macro is made if you want to set a state to all the relays and LEDs. Check the HardwareProfile.h file, lines 140-156. There you can see the macro definitions of all LEDs, relays and also the backlight of the LCD. Since they are similar to LEDs (the way they are controlled) they are all defined like LEDs. So as you can see the comments on the right the mapping is as follow:
Macro; physical component
LED0 - LED0
LED1 - LED1
LED2 - LED2
LED3 - LCD backlight
LED4 - Relay 1
LED5 - Relay 2
LED6 - no element
LED7 - no element
And now let's take a look on macro LED_PUT.
#define LED_PUT(a) LED0_IO = !!(a & 0x01);\
LED1_IO = !!(a & 0x02);\
LED2_IO = !!(a & 0x04);\
LED3_IO = !!(a & 0x08);\
LED4_IO = !!(a & 0x10);\
LED5_IO = !!(a & 0x20);\
LED6_IO = !!(a & 0x40);\
LED7_IO = !!(a & 0x80);\

The value of the parameter 'a' defines the new state of all of them.
For example if we want to make the following - LED0 - ON (1); LED1 - ON (1); LED2 - OFF (0); LCD_Back - OFF (0); REL1 - ON (1); REL2 - OFF (0). This means the value of 'a' should be these ones and zeros in reverse order (the bits are 7 to 0; not 0 to 7) - 010011 (binary) --> 13 (hexadecimal).
So if we "call" the macro LED_PUT with this value like this:
LED_PUT (0x13);
we will set the values mentioned in the beginning.

But if you want to change the state of ONLY ONE of the LEDs (as it is in your case) you can use the specific for the element macro.
For example if you want to control only Relay 1 you should initialize it as an output:
LED4_TRIS = 0;  //in microchip microcontrollers 0 means output

And if you want to turn on the relay
BUTTON4_IO = 1;
or to turn it off:
BUTTON4_IO = 0;

Best regards!
Stan, Olimex
May the Source be with You!

Ritmeester

Hi Stan,

Thanks for your explanation.  I really appreciates this.

Regards,

Ritmeester