Skip to content
GitLab
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Jan Kasprzak
tinyboard
Commits
fa1f7d30
Commit
fa1f7d30
authored
May 02, 2013
by
Jan Kasprzak
Browse files
buttons.c: button on PB0, status LED on PB1
parent
50ca2660
Changes
1
Hide whitespace changes
Inline
Side-by-side
projects/step-up/buttons.c
View file @
fa1f7d30
...
...
@@ -16,17 +16,17 @@ static unsigned char prev_state;
void
status_led_on_off
(
unsigned
char
mode
)
{
if
(
mode
)
PORTB
|=
_BV
(
PORTB
0
);
PORTB
|=
_BV
(
PORTB
1
);
else
PORTB
&=
~
_BV
(
PORTB
0
);
PORTB
&=
~
_BV
(
PORTB
1
);
}
void
init_buttons
()
{
DDRB
&=
~
_BV
(
DDB
1
);
DDRB
|=
_BV
(
DDB
0
);
PORTB
|=
_BV
(
PORTB
1
);
// enable internal pull-up
PORTB
&=
~
_BV
(
PORTB
0
);
// status led off
DDRB
&=
~
_BV
(
DDB
0
);
DDRB
|=
_BV
(
DDB
1
);
PORTB
|=
_BV
(
PORTB
0
);
// enable internal pull-up
PORTB
&=
~
_BV
(
PORTB
1
);
// status led off
GIMSK
&=
~
_BV
(
PCIE
);
// disable pin-change IRQs
PCMSK
=
0
;
// disable pin-change IRQs on all pins of port B
...
...
@@ -36,19 +36,19 @@ void init_buttons()
void
susp_buttons
()
{
DDRB
&=
~
(
_BV
(
DDB
1
));
// set as input
PORTB
|=
_BV
(
PORTB
1
);
// enable internal pull-up
PORTB
&=
~
_BV
(
PORTB
0
);
// set to zero
DDRB
&=
~
(
_BV
(
DDB
0
));
// set as input
PORTB
|=
_BV
(
PORTB
0
);
// enable internal pull-up
PORTB
&=
~
_BV
(
PORTB
1
);
// set to zero
GIMSK
|=
_BV
(
PCIE
);
PCMSK
=
_BV
(
PCINT
1
);
PCMSK
=
_BV
(
PCINT
0
);
// disable pin-change IRQs on all pins except PB1
}
void
timer_check_buttons
()
{
unsigned
char
cur
=
!
(
PINB
&
_BV
(
PINB
1
));
unsigned
char
cur
=
!
(
PINB
&
_BV
(
PINB
0
));
unsigned
char
prev
=
prev_state
;
prev_state
=
cur
;
...
...
@@ -118,8 +118,8 @@ unsigned char buttons_wait_for_release()
_delay_ms
(
100
);
pin
=
PINB
&
_BV
(
PINB
1
);
}
while
(
!
(
pin
&
_BV
(
PINB
1
)));
pin
=
PINB
&
_BV
(
PINB
0
);
}
while
(
!
(
pin
&
_BV
(
PINB
0
)));
status_led_on_off
(
0
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment