LOL thanks for the catch. That was stupid of me
Now its working "better" but still not right.
I changed the code as follows:
#define F_CPU 128000
#include <util/delay.h>
#include <avr/io.h>
#include <inttypes.h>
#define SCK _BV(PB4)
void shreg(uint16_t a){
int z;
//Start sequence ?
PORTB = 0; // All pins low
_delay_ms(1);
PORTB |= SCK; //SCK high
_delay_ms(1);
PORTB &= ~SCK; //SCK low
_delay_ms(1);
PORTB |= _BV(PB3); //Serial data high
_delay_ms(1);
PORTB |= SCK; //Sck high
_delay_ms(1);
PORTB &= ~SCK; //SCK LOW
_delay_ms(1);
for(z = 0;z<35;z++){
if(z < 14){
PORTB = (_BV(PB3) * (a&1)); //Output bit if < 14
a>>=1;
} else {
PORTB = 0; //Otherwise output nothing
}
_delay_ms(1);
PORTB |= _BV(PB4); //SCK high
_delay_ms(1);
PORTB &= ~_BV(PB4); //SCK low
_delay_ms(1);
/* PORTB = 0; //All pins off
_delay_ms(1);*/
}
}
int main(){
unsigned int cat = 0;
DDRB = _BV(PB3) | _BV(PB4);
PORTB = 0;
while(1){
shreg(0xFFFF);
_delay_ms(500);
}
}
With shreg(0xFF), it correctly lights all LEDS and shreg(0) turns them all off.
The problem is, shreg(1) or shreg(2) does not light the first or second LED.