I simulated the below attached circuit in Proteus 8 and it works fine. When I made the same circuit with actual components I got the following problems:
1. The port 0 has all pins at 5V DC, I grounded the switches to account for that, but I dont know if the 5V is floating state or high logic in the above case.
2. Both my relays get switched ON and stay that way. I think the current from my port 2 is not enough to drive the uln2003an, will adding a pull up resistor solve it?
3. In my actual circuit I am using ILN2003an, i checked the datasheet and both seem the same to me.
Any suggestion as to correct my circuit or code will be appriciated.If my circuit is correct, I can then start troubleshooting for actual hardware faults instead of logical errors.
Since no one has answered my query. I will add a bit more detail about what the circuit is meant to do.The objective is to switch the relays (ON-OFF) for a specific number of cycles. the cycles are decided by the DIP switches connected to port 0.The number of cycles left are dislayed on the LCD. Right now niether by LCD is displaying anything nor are the relays switching they just remain ON. I really need to find the problem. Please help me.
Port0 is input port ,so you have to make it as input by PORT0=0Xff,
The 89c51 ports can only be made as active low, Is that your DIP swith connected as active low?
1. Yes I have made P0 as input by putting 0xff.
2. I grounded the DIP switches.
3. I removed the uln and checked the output at P2.6 and P2.7 and it works as expected. Only when I apply the uln and the relays(load) the circuit misbehaves, I think it is due to insufficient current from the uC pins i.e. the uC is unable to drive the ULN and relays.
4. I checked the ULN ground.
5. Also I found that current leaks from the relay coil, as when I gave +5V to the first LED and ground at 1C of ULN where the LED is connected, both the LED glow.
SO my final question is how can I modify the relay circuit to account for this.
PS: thank you for your replys. Here is the zip file.
If you look at my code you will see that the number is split and then 48 is added induvidually to each digit, therefore I can display numbers greater than 9. Besides the simulation is working perfectly so the code must be correct.
In the end it was only human error that prevented the circuit to work. After correcting the LCD VCC and VDD connections and correcting the contrast everything worked according to plan, except one minor change from the simulated circuit, the switches had to be grounded instead of pulled up.
With this I am marking this thread as solved and I want to thank, in no particular order, Mukesh, welove9051, milan and aamer for their valuable inputs.