On Jan 4, 2008, at 2:55 PM, J D Freeman wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I am trying to relearn the use of AVR's after far to long of not using them. And I am struggling to get something incredibly simple working. Whats more, I can't seem to find any useful documentation on it. Put simply, I want to use the input from switch to toggle an LED. I have an Atmega168. There is an LED attached to PC4 and a switch between PD0 and +5v. I then have: /* set PC4 to output */ DDRC |= (1<<DDC4); /* set PD0 to input and enable pullups */ DDRD = (0<<DDC0); PORTD = 0x00;
If your switch is betwen PD0 and +5V, why do you need the pullups enabled? That would make it always be +5V since when the switch is off, it would be pulled up by the pull-ups.
while(1) { uint8_t x; x = PIND; if( x != 0) { /* Toggle PC4 */ PORTC ^= (1<<PC4); } }
So, every iteration through the loop, PD0 is checked to see if it is 1. Because of the above, it always is. Then, it toggles PC4. Depending on how fast the clock is going, this could easily be toggling at a rate that the naked eye cannot see. For a 1MHz part, it could take 4 cycles to run an iteration of the loop, so the LED would be toggling at 250KHz, or stated another way, would have a 50% duty cycle at 125KHz.
The code compiles fine. It just doesn't seem to do something. I am sure I have missed something really simple. I just can't find a good exampleof someone reading a single input pin. I did find a few examples of using 8 inputs, but even they they didn't help much. Thanks in advance. J -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFHfrld42M0lILkmGIRAtQaAKDANqgiH2RU6hyDKrbByLZPyosZFgCgqyWj nM1+wD6xlTg1dduGoA4qxEk= =tpIn -----END PGP SIGNATURE----- _______________________________________________ AVR-chat mailing list AVR-chat@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-chat
-- Rick Altherr [EMAIL PROTECTED]"He said he hadn't had a byte in three days. I had a short, so I split it with him."
-- Slashdot signature
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ AVR-chat mailing list AVR-chat@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-chat