SWITCHES
Switches come in many different shapes and sizes. The main idea or function is to either enable or disable something by simply turning it on/off. Thus it acts as an input device that users can use to control certain parts of the system. Below are the most common switches that you will come across
 |
| Push Button |
 |
ON-OFF Switch
In circuit diagrams, a switch is generally represented by
 |
| Switch Symbol |
After examining the Switch Symbol, I think it is quite clear how a switch actually works. It closes (connects) or opens (disconnects) a circuit. The Push Button behaves in the same fashion as it closes the circuit as long as you keep holding it in pressed state.
SWITCH INTERFACE CODE
Here is the C language code for the Switch Interface with the 8051 microcontroller-
 |
| SWITCH Interface C Language Code |
Let me explain the code in a step wise fashion
- PIN1.0 is renamed as sw using (for convenience)
- Similarly PIN1.1 is renamed as led (LED is connected to this pin)
- sw is declared as input pin (for reading switch status)
- led is declared as output (for driving LED on/off)
- if ( !sw ) statement is true only if switch is ON (sw = 0 and !sw = 1) and thus led will glow
- Otherwise led will stay OFF
The same code simulated in Proteus looks like this -
 |
| Proteus Simulation |
This concludes the topic for today. I hope that after reading this post, you have at least some basic idea of using a switch with the 8051 microcontroller.
|
No comments:
Post a Comment