본문 바로가기
임베디드/Atmega128

atmega128- 03_external_pulldown 외부 풀다운

by sj0020 2020. 12. 17.
/*
 * 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;
		}		
    }
}

PB0에 1을 주면 파워(왼쪽)에서 들어오는 1(항상 들어오고 있음)이랑 충돌해서(둘 다 1이라서 0으로 흘러갈 수가 없어서) 불이 꺼진다 


/*
 * 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;
		}		
    }
}