I probably do it like pedja089, but used the eeprom to save the setting!
I probably do it like pedja089, but used the eeprom to save the setting!
Thanks and Regards;
Gadelhas
Code:EE_Polarity DATA 0 ; Factory Default SW1 VAR PORTB.0 ; Switch input pin mosfet_gate VAR PORTB.1 ; mosfet output Polarity VAR BIT READ EE_Polarity, Polarity IF !SW1 THEN WRITE EE_Polarity, !Polarity READ EE_Polarity, Polarity mosfet_gate = 1 ^ Polarity ; Turn OFF OUTPUT mosfet_gate ;---------------------------------------------- mosfet_gate = 0 ^ Polarity ; Turn ON mosfet_gate = 1 ^ Polarity ; Turn OFF
Last edited by Darrel Taylor; - 17th May 2012 at 03:38. Reason: Oops, forgot to set the pin to output.
DT
That is XOR.
0^0=0
0^1=1
1^0=1
1^1=0
If Polarity is 1 or 0, depending on user settings. If Polarity is 0 then bit isn't inverted and result is same as:
mosfet_gate = 0 ; Turn ON
mosfet_gate = 1 ; Turn OFF
If Polarity is 1 then then bit are inverted so result is
mosfet_gate = 1 ; Turn ON
mosfet_gate = 0 ; Turn OFF
Bookmarks