Hi,
I'm new, and have just got a blinky program to work on a DB101 (ATmega1281), and now I would like to get input to control the LED.
Here's what I understand, and have so far.
I have 3 LEDs connected to to D5, D6, and D7. I am able to turn these on and off.
Input pins are set to 1, and therefor the button must be connected to ground to do anything.
I found this bit of code somewhere online to set the desired pins as input/output:
#define set_input(portdir,pin) portdir &= ~(1<<pin) #define set_output(portdir,pin) portdir |= (1<<pin) #define LED_1 PD7 #define BUTTON PB5 set_output(DDRD, LED_1); set_input(DDRB, BUTTON);
I'm assuming that PD7 and PB5 correspond to D7 and B5 on the PCB. It works for PD7 at least.
Also I'm not exactly sure what "|=" and "&=" mean so if someone could help me out with that I would be grateful.
The macro for set_input seems to set the desired pin to not 1? I'm assuming that's equivalent to setting it to 0 for input. What it doesn't seem to do is activate the pull up resistors for that pin. For that I do this
set_output(PORTB, BUTTON);
which looks like it should put put PORTB's PB5 pin to 1.
When I check the voltage of PB5 with a voltmeter I get 3.45V, instead of the regular 5V of an output, but I assume that's because of the voltage drop across the pull up resistor.
I'm not sure what to put in my if statement though.
I've seen this, but it won't compile for me.
if(PINB.BUTTON == 0)
and this never sees the button pressed.
if(PORTB & BUTTON)
I learned most of this from
http://elecrom.wordpress.com/200...
if there is a better place for me to get more info please let me know
Thanks,
Waspinator