Hello all,
I am trying to read the pin PB0 which is an internal pull-up resistor input pin. In my code logic,
Moderator edit: added code tags.
I am trying to read the pin PB0 which is an internal pull-up resistor input pin. In my code logic,
- if PB0 is HIGH then execute if-block
- if PB0 is LOW then execute else-block
Code:
#include<avr/io.h>
#include<util/delay.h>
int main(void)
{
//For testing
DDRD =0b11111111;
PORTD =0b00000000;
//CORRECTED CODE
DDRB |=(1<< PB1);// PB1 -output
DDRB &=~(1<< PB0);// PB0 -input
PORTB |=(1<< PB0);// Activated pullup in PB0
PORTB &=~(1<< PB1);// PB1 low
while(1)
{
_delay_ms(100);
if( PINB &(1<<PB0))
{
PORTD =0x00;
}
else
{
PORTD =0xFF;
}
_delay_ms(500);
}
}