I've written a simple test program to blink an LED according to the
status of two input bits on a port. The bits represent the status of
an actuator. One bit is high when the actuator is fully contracted,
and the other is high when the actuator is fully extended. These lines
also have pull-down resistors. There's also a control bit for making
the actuator extend and contract, and I've successfully tested that
bit, confirming that the actuator responds to the chip's signal.
However, my program doesn't cause the LED to blink, leaving me to
believe it's having a problem reading the two status bits. I've
manually confirmed that the hardware is setting the correct signals
based on actuator state, but the AVR acts like the they're always low,
even when I measure them high. The following is my short test program.
It should make the actuator extend and contract indefinitely, lighting
the LED while it's extending.
#include <avr/io.h>
int main(void) {
// initialize IO ports
DDRB |= _BV(PB3); // Output, actuator control line "ctrl", make = 1
to contract
DDRB &= ~(_BV(PB4)); // Input, actuator contracted signal "cn", 1 =
contracted
DDRB &= ~(_BV(PB5)); // Input, actuator extended signal "ex", 1 =
extended
DDRD |= _BV(PD1); // Output, LED
while(1) {
// Perform extention cycle.
PORTD &= ~(_BV(PD1)); // LED off
PORTB |= _BV(PB3); // Set control high to start contracting.
loop_until_bit_is_set(PORTB, PB4); // Wait until fully contracted.
// Perform extention cycle.
PORTD |= _BV(PD1); // LED on
PORTB &= ~(_BV(PB3)); // Set control low to start extending.
loop_until_bit_is_set(PORTB, PB5); // Wait until fully extended.
}
return 0;
}
Am I using DDRB/PORTB correctly? I've been trying to debug this for
hours and I've gotten no where, so any help is greatly appreciated.
Thanks,
Chris
_______________________________________________
AVR-chat mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-chat