Maker Pro
Maker Pro

AVR AT90S2313 basic question

J

Jean Tabel

Jan 1, 1970
0
Hi,

I am experimenting for the fist time with PB0 connected to a LED
and PB1 configured (?) as an input.

PB1 is directly connected to the GND, and I was assuming the LED
would stay on until I would connect it directly to VCC.

But I am executing outp (0x00, PORTB).
When this line is commented out, the LED stays on.

void main (void)
{
outp (0x01, DDRB); // PB0 output, PB1 input
outp (0x01, PORTB); // LED on PB0 set to on

for (;;) {
if (inp(PINB) & 0x02 != 0) {
// logical 1 in PB1 - setting LED on PB0 to off
outp (0x00, PORTB);
}
}
}

I tried to activate the pull-up internal resistor for PB1 by writing
0x03 into PORTB instread of 0x01, but this dis not change
anything.

Since I am basically a software guy, I must probably be missing
something very, very trivial.

Any clue anybody ?

Thanks in advance,

Jean Tabel
 
K

Ken Scharf

Jan 1, 1970
0
Jean said:
Hi,

I am experimenting for the fist time with PB0 connected to a LED
and PB1 configured (?) as an input.

PB1 is directly connected to the GND, and I was assuming the LED
would stay on until I would connect it directly to VCC.

But I am executing outp (0x00, PORTB).
When this line is commented out, the LED stays on.

void main (void)
{
outp (0x01, DDRB); // PB0 output, PB1 input
outp (0x01, PORTB); // LED on PB0 set to on

for (;;) {
if (inp(PINB) & 0x02 != 0) {
// logical 1 in PB1 - setting LED on PB0 to off
outp (0x00, PORTB);
}
}
}

I tried to activate the pull-up internal resistor for PB1 by writing
0x03 into PORTB instread of 0x01, but this dis not change
anything.

Since I am basically a software guy, I must probably be missing
something very, very trivial.

Any clue anybody ?

Thanks in advance,

Jean Tabel
Try it this way:
if (inp(PINB) & 0x02) { //if pinb1 input high next statement executed
// logical 1 in PB1 - setting LED on PB0 to off
outp (0x00, PORTB);
}
Also you might add an external pull up resistor, put your
input switch from pb1 to ground.
 
J

Jean Tabel

Jan 1, 1970
0
Ken Scharf said:
Jean Tabel wrote:
Try it this way:
if (inp(PINB) & 0x02) { //if pinb1 input high next statement executed
// logical 1 in PB1 - setting LED on PB0 to off
outp (0x00, PORTB);
}
Also you might add an external pull up resistor, put your
input switch from pb1 to ground.

The external pull-up resistor did the job, thank you very much.
Jean Tabel
 
Top