With this code, I'm getting the same results as my first attempt, i.e. the A button is the only one registered, and it turns all output ports low. I think the problem is in
The A is the 8th data read so it would seem your code is over writing the bits..
I really can help much from what you said but maybe I can help you help your self.
I mean no offense here just trying to help
(NES_DATA_PIN & _BV(NES_DATA)) ? (nes_byte |= _BV(bit_counter)) : (nes_byte &= ~_BV(bit_counter));
first do the and (NES_DATA_PIN & _BV(NES_DATA) This checks the status of pinA, and checks to see if its high or low at that time in the cycle.
If ( aka the '?' ) hi then (nes_byte |= _BV(bit_counter))
otherwise (nes_byte &= ~_BV(bit_counter))
for the case of (nes_byte |= _BV(bit_counter)) your result is to bring the nes_byte BIT hi and leave the other bits alone.
for the case of (nes_byte &= ~_BV(bit_counter)) your result is to bring the nes_byte BIT low and leave the other bits alone.
than you just read the other bits one after the other and preform this same operation.
This is very basic but I know we all have to start somewhere..
To answer your question your code is perfect for the most part ( see notes ) .. I think the problem is deeper. Maybe the clock is not working, are you sure your pins changes are right.. is it clocking the nes correctly? Do you have a scope or analyzer?
NES_PORT |= _BV(NES_LATCH); //
turns the latch on _delay_us(12); //
nes nees 12 us to do this right NES_PORT &= ~_BV(NES_LATCH); //
turns the latch off _delay_us(6);//
not sure why this is here, its not needed, however I think its fine to keep it here.. for(uint8_t bit_counter = 0; bit_counter < 8; bit_counter++){//
ok lets get 8 bits ( a byte ) of data (NES_DATA_PIN & _BV(NES_DATA)) ? (nes_byte |= _BV(bit_counter)) : (nes_byte &= ~_BV(bit_counter));//
was it low or hi ? store the result in nes_byte NES_PORT |= _BV(NES_CLOCK); //
turns the clock on _delay_us(6);//
nes need 6 us here NES_PORT &= ~_BV(NES_CLOCK); //
turns the clock off _delay_us(6);//
nes need 6 us here }
The best way to beat this is with a logical analyzer. Like this
http://www.saleae.com/logic/ If you wish to go at this blind start by reducing the loop to 1 [
for(uint8_t bit_counter = 0; bit_counter < 1; bit_counter++){] and check nes_byte, it should default to all 11111111.Test this by not pressing any buttons... If you do this while B is pressed you should get 01111111 If this does not happen your wiring or clock is not working...