Alright, I don't really understand why this isn't working. I've worked with arduino before, but this is the first time i've gone into bare-bones AVRs(in this case, ATtiny2313). I'm making a controller mod, where you hit Right-click, left-click, right-trigger to engage rapid fire right-trigger mode, and the same combination only with left-trigger to turn the turbo mode off. So, this is how I have the pins going for the trip(NOTE: This isn't in the controller yet, i'm just using a DIP-switch and some LEDs for testing purposes).
PORTD
I:RC 2
I:LC 3
I:RT 4
I:LT 5
PORTB
O:RT 0
O:LED 1
The left shows the function, the right shows the bit in the register.
Alright, time for the code...weeeee.
[code]
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
typedef unsigned int u16;
typedef unsigned long u32;
int main(void)
{
DDRD = 0;
PORTD = 0;
DDRB = 0xFF;
PORTB = 0;
while(1)
{
while(bit_is_clear(PINB,1))
{
if(PIND == 0x1C)
{
PORTB |=(1<<1);
}
if(bit_is_set(PIND,4))
PORTB |=(1<<0);
else
PORTB &=~((1<<0));
}
while(bit_is_set(PINB,1))
{
if(PIND == 0x2C)
{
PORTB &=~((1<<1));
}
if(bit_is_clear(PIND,3) && bit_is_set(PIND,4))
{
PORTB |=(1<<0);
_delay_ms(100);
PORTB &=~((1<<0));
_delay_ms(100);
}
else
PORTB &=~((1<<0));
}
}
return 1;
}
[/code]
When I turn the chip on, the LEDs kinda freak out. The LED output LED stays solid, the RT output LED pulses a bit, but it should be off because i'm not supplying voltage to any of the input pins. Not sure what to do at this point. Any suggestions?Message
Problem with code(simulates in AVR Studio fine, but not in real life)
2009-06-09 by inuyasha10121
Attachments
- No local attachments were found for this message.