avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] Reading Ports?


From: Neil Davey
Subject: Re: [avr-chat] Reading Ports?
Date: Mon, 05 Jun 2006 14:01:53 +1000
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

Hi Chris,
If you are wanting to read a port pin you need to use PINx instead of PORTx

so it would read like:  loop_until_bit_is_set(PINB, PB4);

Regards
Neil Davey

address@hidden wrote:
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



--
--------------------------------------
Neil Davey
Griffith University

Griffith School of Engineering
Nathan Campus
Phone: 07-3735-7008
Fax: 07-3735-5112

School of Psychology - ACNRC
Mt Gravatt Campus
Phone: 07-3735-3395
--------------------------------------





reply via email to

[Prev in Thread] Current Thread [Next in Thread]