Maker Pro
Maker Pro

code for running 2 relays using 2 push buttons

trymore

May 8, 2016
5
Joined
May 8, 2016
Messages
5
hie ,
i would like to control the energizing and DE-energizing of two relays using push buttons and displaying information on an LCD .. using PIC16F877A iv attached my hex file and Proteus circuit
 

Attachments

  • relays and push buttons.PNG
    relays and push buttons.PNG
    60.6 KB · Views: 143

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Yes you can.
Read the status of the buttons, then set the outputs for LEDs and relays accordingly.
 

Amar Dhore

Dec 2, 2015
129
Joined
Dec 2, 2015
Messages
129
I would connect my LEDs to the Collector of Q2 and Q3 through suitable resistors, so you get the actual status of the relays.
 

Sadlercomfort

Ash
Feb 9, 2013
424
Joined
Feb 9, 2013
Messages
424
Did you need help with any written code?

The code should be relatively simple, the 4-BIT LCD would be the difficult part..:rolleyes:
 

trymore

May 8, 2016
5
Joined
May 8, 2016
Messages
5
What programming language are you using? C, Assembly?

Have you managed to write any code to operate the relays using switches?
im using mikroc and proteus yes i wrote a code but the buttons are not responding iv attatched my code
 

Attachments

  • push btn.txt
    1.6 KB · Views: 86

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
I'm not familiar with PICs and the microc dialect, but there seems to be missing the code for setting RD1_bit and RD2_bit for output.
 

Amar Dhore

Dec 2, 2015
129
Joined
Dec 2, 2015
Messages
129
Make sure your analog pins are disabled. Add denouncing for Push button (wait for button release for few mSec). I would try the code without LCD first, once my relays are working, I would work on LCD.

In your code, I am do not see you calling while() loop in the main function?
 

Sadlercomfort

Ash
Feb 9, 2013
424
Joined
Feb 9, 2013
Messages
424
I've added and modified some parts of your code. See attached.

You have not setup the input and output pins, this should be defined first. Then set at the start of your main function, I've added these to your txt file.

You also end the main function early with a parenthesis '}', I've deleted this from your code and the word 'else' from the second IF statement since it is not needed. Errors like these should have been picked up when you compiled your code.


I would recommended writing a simple code, just to get your leds on/off with a small delay to make them flash. Then included your push buttons, if the leds dont work.. you know there is a problem with your push button code. Then once this works, add control of the relays.... and so forth.

Another tip.. keep your definitions simple. Long worded definitions can easily be spelled incorrectly. For example:

uppersliddinggate >> UpperGate or Up_Gate

Using a capital or an underscore in-between words allows them to be read easily. Programmers need all the help they can get to make life simple.
 

Attachments

  • Push Button Modified.txt
    2.8 KB · Views: 85
Last edited:

trymore

May 8, 2016
5
Joined
May 8, 2016
Messages
5
I've added and modified some parts of your code. See attached.

You have not setup the input and output pins, this should be defined first. Then set at the start of your main function, I've added these to your txt file.

You also end the main function early with a parenthesis '}', I've deleted this from your code and the word 'else' from the second IF statement since it is not needed. Errors like these should have been picked up when you compiled your code.


I would recommended writing a simple code, just to get your leds on/off with a small delay to make them flash. Then included your push buttons, if the leds dont work.. you know there is a problem with your push button code. Then once this works, add control of the relays.... and so forth.

Another tip.. keep your definitions simple. Long worded definitions can easily be spelled incorrectly. For example:

uppersliddinggate >> UpperGate or Up_Gate

Using a capital or an underscore in-between words allows them to be read easily. Programmers need all the help they can get to make life simple.
thank you so much
 
Top