I have the following
5v ------ switch ------10K resistor --- ground
|
|-- 330 resistor -- PORTD4
This is supposed to be a switch with a pull down resistor.
By default the pull up resistors should be on for a Atmega128 so I did
the following
DDRD &= 0xEF; // turn pin4 to input
PORTD &= 0xEF; // write 0 to pin4 to disable pullup
printf("pinb %i ",PIND4);
if (PIND4)
{
PORTB ^= 0x01; // off LED
}
else
{
PORTB |= 0x01; // on LED
}
Elsewhere in the program I am using PORTD0 and PORTD1 for I2C other than
the pin on the rest of the port is not being used.
No matter what the switch is (opened or closed) the printf always look
like pinb 4.
What am I doing wrong? I know the switch is working properly because I
tested it by having the wire that would go to a LED on a breadboard and
I can get the LED to light when the switch is closed.Message
Testing a switch on ATMega128
2005-01-18 by wbounce
Attachments
- No local attachments were found for this message.