Digital Input reading using 8051/89c51
Reading a digital input in 8051/89c51 is very simple. In this program I have read a digital input in 8051 through switch. I have also glow a LED to show that input is reading correctly. Main Program is showing in image below:-
In hardware part one terminal of switch is connected to P2.1 and the other is connected to ground. A LED is also connected to P2.0 for indication. Whenever a switch is pressed then Pin P2.1 gets connected to ground and 5V becomes 0 at Pin P2.1. In the program shown in image I have read a Pin P2.1 in while loop. I have read that if Pin P2.1 became 0 then LED will goes ON or if this Pin is at logic high (i.e. 1) the LED will goes OFF. Here till when we pressed the switch LED remains ON and when we release the switch LED goes OFF.
For the definition of Switch,pressed and LED you have to also considered the define.h shown in image below:-
For downloading complete code click here it is free of cost.
No comments:
Post a Comment