Entschuldige, dass ich jetzt erst anworte. Ich habe die Tage noch an einem anderen Projekt gearbeitet und vergessen nochmal hier reinzuschauen.
Der Code sieht folgendermaßen aus:
Code:
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
unsigned char ReadData(void)
{
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
return TWDR;
}
int main(void)
{
unsigned char input;
DDRB = 0x01;
PORTB = 0x01;
TWBR = 0x01;;
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while(!(TWCR & (1<<TWINT)));
TWDR = 0b01000000;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
TWDR = 0b11111100;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
_delay_ms(1000);
TWDR = 0b00000100;
PORTB = 0x00;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
while(1)
{
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
TWDR = 0b01000001;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
input = ReadData();
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
if (input & 0b00000100)
{
PORTB = 0x01;
}
else
{
PORTB = 0x00;
}
}
}
Lesezeichen