임베디드/Atmega128
atmega128- 03_external_pulldown 외부 풀다운
sj0020
2020. 12. 17. 18:52
/*
* 03_external_pulldown.c
*
* Created: 2020-12-17 오후 6:08:40
* Author : User
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#define BUTTON1 PORTE0
#define BUTTON2 PORTE2
int main(void)
{
DDRE = 0x00;
DDRB = 0xff;
while (1)
{
if (PINE & (1 << BUTTON1) | PINE & (1<<BUTTON2)){
PORTB = 0b00000001;
}
else {
PORTB = 0b00000000;
}
}
}
/*
* 03_external_pulldown2.c
*
* Created: 2020-12-17 오후 6:35:00
* Author : User
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#define BUTTON1 PORTE0
#define BUTTON2 PORTE2
int main(void)
{
DDRE = 0x00;
DDRB = 0xff;
while (1)
{
if (PINE & (1 << BUTTON1) | PINE & (1<<BUTTON2)){
PORTB = 0b00000000;
}
else {
PORTB = 0b00000001;
}
}
}
/*
* 03_external_pullup.c
*
* Created: 2020-12-17 오후 6:55:00
* Author : User
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#define BUTTON1 PORTE0
#define BUTTON2 PORTE3
int main(void)
{
DDRE = 0x00;
DDRB = 0xff;
while (1)
{
if (PINE & (1 << BUTTON1) & (PINE & (1 << BUTTON2)))
{
PORTB = 0b00000000;
}
/* else if (PINE & (0 << BUTTON1) | (PINE & (0 << BUTTON2)))
{
PORTB = 0b00000001;
}*/
else {
PORTB = 0b00000001;
}
}
}