new home auto doubt
Discussion in "Project Doubts" started by asim amitav Mar 26, 2007.
Mon Mar 26 2007, 10:35 pm
thank u sir , but i have doubt
1. led is connected at the output port of mc with appropriate resistance . if we write bulb command then it will glow and it get voltage from the output of mc . and similarly case for off . but if initially we send " stat" command then what it will always show "off" beacuse initially led didn't get any volage from mc port .. can u plz explain me how through the programme it is reading status ( in cmd.c ) . .. ??
1. led is connected at the output port of mc with appropriate resistance . if we write bulb command then it will glow and it get voltage from the output of mc . and similarly case for off . but if initially we send " stat" command then what it will always show "off" beacuse initially led didn't get any volage from mc port .. can u plz explain me how through the programme it is reading status ( in cmd.c ) . .. ??
Mon Mar 26 2007, 11:50 pm
well.. its like this..
we are using -ve logic for LEDs or appliance section, because at startup, all the ports will be one.. so you cant let all your appliances to be on at startup. so we use -ve logic, so 1 = off and 0 = On so when you run, everything will be off.
Now how this is down.. This is done by sinking the current, instead of sourcing it. when you put 0 on port the voltage at port becomes zero so current flows from source->LED->controller pin completing the circuit, so LED glows. and when you send 1 to port, the voltage is 5 V at the o/p pin, so coz of same voltage level the current doesn't flow, and LED is off.
Now reading part, is same and as simple as setting on or off, as i explained you, 1 = off, and 0 = On. so when you send stat command. it read all the port pins for its state.
e.g. you want to read bulb1 then it will be like this..
if(bulb1){
//this bulb is Off coz bulb1 = 1
}
else{
//This bulb is on coz bulb1 = 0
}
this is how it is done simple isnt it? bulb1 is a port pin whose address is defined in the HAreg.h file
so it checks if bulb1 = 1 then off
else if bulb1 = 0 then bulb is on.
Hope this helped you. for anymore queries you may ask anytime Take care..!
we are using -ve logic for LEDs or appliance section, because at startup, all the ports will be one.. so you cant let all your appliances to be on at startup. so we use -ve logic, so 1 = off and 0 = On so when you run, everything will be off.
Now how this is down.. This is done by sinking the current, instead of sourcing it. when you put 0 on port the voltage at port becomes zero so current flows from source->LED->controller pin completing the circuit, so LED glows. and when you send 1 to port, the voltage is 5 V at the o/p pin, so coz of same voltage level the current doesn't flow, and LED is off.
Now reading part, is same and as simple as setting on or off, as i explained you, 1 = off, and 0 = On. so when you send stat command. it read all the port pins for its state.
e.g. you want to read bulb1 then it will be like this..
if(bulb1){
//this bulb is Off coz bulb1 = 1
}
else{
//This bulb is on coz bulb1 = 0
}
this is how it is done simple isnt it? bulb1 is a port pin whose address is defined in the HAreg.h file
so it checks if bulb1 = 1 then off
else if bulb1 = 0 then bulb is on.
Hope this helped you. for anymore queries you may ask anytime Take care..!
Powered by e107 Forum System