|
| |||||||
|
Опубликовано 2010-03-21 17:40:28 автором Ruslan How to connect to the microcontroller buttonsIn previous lessons I spoke about, as with the MK output information: connections seven-segment display and Lcd display . In this lesson we will enter the information using the buttons. Buttons are several types: fixing the clock. From the name of the button understandable principle of its work: the clock is pressed, contacts enclosed, open - розімкнулися; fixing - record their condition: pressed - bent contacts, again pressed розімкнулися.Standard wiring diagram buttons is very simple and looks like
#include <mega8.h>
#include <delay.h>
void main(void)
{
// initialize port D
PORTD is set=0b00000000;
DDRD=0b10000000;
while (1)
{
if (PIND & 0b00000100) /*check the logic level on the leg sign & that means bitwise "And"
for example in PIND is 0b00000100, then 0b00000100 & 0b00000100 = 0b00000100 that is true, and if PIND we
0b00000000 the 0b00000000 & 0b00000100 = 0b00000000 and this false */
PORTD is set=0b00000000; // write in zero the seventh bit of the port D
else
PORTD is set=0b10000000; // write the unit in the seventh bit of the port D
};
delay_ms(100); // make a delay of 100 milliseconds for protection against contact bounce
}In most modern microcontrollers is a built in pull-up resistor R1, so external are not necessarily
Комментарии - (0) Добавить комментарийДля отправки комментария вы должны авторизоваться. |
|||||||