i am working with 8051 and have connected relays with the port P2 how can i send command to turn on or off the relay, and then using the same port get the status of the appliances connected with the relays i.e. to check weather they r on or off?????????
and have connected relays with the port P2 how can i send command to turn on or off the relay, and then using the same port get the status of the appliances connected with the relays i.e. to check weather they r on or off????????? that must be SOME relay or SOME '51 derivative. I know of no '51 that can safely drive relays directly. You say "relays" you are aware, I hope, that, in addition to the max current per pin there also is a "max total current all port p1ns".
Anyhow the only way to totally ensure a relay is on or off is by an extra set of contacts read by another port pin. You can, in the code test if a relay hopefully is on by reading the port pin that drives the transistor that drives the relay.
Erik