You have several errors in your code.
1. Your "if" statement is bogus. Expand it out:
if ((PINE, 0x01) == 0)
Doesn't mean anything, although syntactically it is ok.
2. After reset all pins are INPUTS. You need to set the direction to OUTPUT
to properly drive the LED.
3. Which compiler are you using? If a recent GCC then you can skip the bit
manipulation macros and perform direct operations on the ports. The compiler
will do the right thing. E.g.:
#define TESTPIN2 (1<<2) // 0x02
#define TESTPIN1 (1<<1) // 0x01
while (!stop)
{
DDRE |= TESTPIN1; // Make output
PORTE |= TESTPIN1; // Drive high
if (PINE & TESTPIN2) // Test input
PORTE &= ~TESTPIN1; // Clear output (drive low)
}
Cheers!
-----Original Message-----
From: inpactmicro [mailto:brendan.oflynn@nmrc.ie]
Sent: Thursday, February 19, 2004 8:29 AM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] reading a pin
basic stuff I know but Im banging my head against a wall
Im trying to READ a pin (see if Its set high or low by a switch and
turning on another testpin - LED on the basis of that
the (supposedly) input pin is on PinE1 (on testpin2)
the output pin iis on PINEo (Testpin 1)
this is my definitions
#define TESTPIN2 (PINE, 0x01)
#define TESTPIN1_HI sbi(PORTE, 0x00)
#define TESTPIN2_HI sbi(PORTE, 0x01)
#define TESTPIN2_IN cbi(DDRE, 0x01)
#define TESTPIN1_LO cbi(PORTE, 0x00)
#define TESTPIN2_LO cbi(PORTE, 0x01)
//init_devices();
while (!stop)
{
TESTPIN1_HI; //light led
TESTPIN2_IN;//set direction of input pin (DDRE)
if ((TESTPIN2 == 0) //if switch is off
TESTPIN1_LO;
}
but nothing happens after the led comes on the first time
regardless of the polarity put on the TESTPIN2
can anyone help?Message
RE: [AVR-Chat] reading a pin
2004-02-19 by Larry Barello
Attachments
- No local attachments were found for this message.