Hi, I do not see where your program variables and output port bits are reset upon program start. As long as you set TRIS only output state will be undetermined. I hope this helps. Regards, Imre +-----------------------------------------------------------------------+ | The information transmitted is intended only for the person or entity | | to which it is addressed and may contain confidential and/or | | privileged material. Any review, retransmission, dissemination or | | other use of, or taking of any action in reliance upon, this =09 | | information by persons or entities other than the intended recipient | | is prohibited. If you received this in error, please contact the | | sender and delete the material from any computer. | +-----------------------------------------------------------------------+ On Wed, 19 Dec 2001, Milan Pavlica (YU7AEC) wrote: > Hello! > I am going to build a simple PIC controlled electronics for opening gate > on garage. > Using PIC16F84 @4MHZ > Idea is that: > With IR TV remote control i am sending impulses to SFH506, he send > impulses to PIC, he will start first relay for opening - this relay > starting one contactor, which now will hold it self until gate is opened >=20 > Also, when i want to close, again i am sending impulses, but now second > relay will act. I am using (as outs) simple NPN transistor which drive > small 12V relay with only R in base - no PulUp or PullDown > Problem is that when i start PIC, he start to open-close respectively > first ans second relay.... > What is problem?? > THANKS! > p.s. I am using PBP compiler >=20 > '***DEFINITION OF I/O PORTS >=20 > TRISB.0=3D1 ' PORTB0 je input > TRISB.4=3D0 ' PORTB4 je output > TRISB.5=3D0 ' PORTB5 je output >=20 > '***DEFINI=D2ION OF VARIABLES >=20 > GATE_IS_UP VAR BYTE ' Show us that gate is up > GATE_IS_DOWN VAR BYTE ' Show us that gate is down > SENZOR VAR PORTB.0 ' Define PORTB0 as SENZOR > RELAY_OPEN VAR PORTB.4 ' Define PORTB4 - relay for opening UP > RELAY_CLOSE VAR PORTB.5 ' Define PORTB5 - relay for closing DOWN >=20 > '***MAIN PROGRAM >=20 >=20 > FIRST_CONDITION: > PauseUs 35 > IF SENZOR =3D 0 Then ' If there is 0 on senzor > GoTo SECOND_CONDITION: ' Go on Second_condition > Else > GoTo FIRST_CONDITION > EndIF >=20 > SECOND_CONDITION: > PauseUs 35 ' Wait for impulses > IF SENZOR =3D 1 Then ' If there is 1 on senzor > GoTo THIRD_CONDITION > Else > GoTo FIRST_CONDITION > EndIF >=20 > THIRD_CONDITION: > PauseUs 35 > IF SENZOR =3D 0 Then > GoTo GATE_DOWN > Else > GoTo FIRST_CONDITION > EndIF >=20 > GATE_DOWN: > IF Gate_Is_Down =3D 1 TheN > GoTo GATE_UP > Else > RELAY_CLOSE =3D 1 > Pause 1500 > RELAY_CLOSE =3D 0 > Pause 1000 > Gate_Is_Down =3D 1 > Gate_Is_Up =3D 0 > GoTo FIRST_CONDITION > EndIF > GATE_UP: > Gate_Is_Down =3D 0 > RELAY_OPEN =3D 1 > Pause 1500 > RELAY_OPEN =3D 0 > Gate_is_Up =3D 1 > GoTo FIRST_CONDITION > '***END OF PROGRAM >=20 >=20 -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.