|
|
|
|
@ -135,24 +135,25 @@ unsigned char mmc_read_byte (void)
|
|
|
|
|
unsigned char Byte = 0;
|
|
|
|
|
#if SPI_Mode //Routine für Hardware SPI
|
|
|
|
|
SPDR = 0xff;
|
|
|
|
|
while(!(SPSR & (1<<SPIF))){};
|
|
|
|
|
while(!(SPSR & (1 << SPIF))) {;}
|
|
|
|
|
Byte = SPDR;
|
|
|
|
|
|
|
|
|
|
#else //Routine für Software SPI
|
|
|
|
|
for (unsigned char a=8; a>0; a--) //das Byte wird Bitweise nacheinander Empangen MSB First
|
|
|
|
|
{
|
|
|
|
|
for(unsigned char a=8; a>0; a--) //das Byte wird Bitweise nacheinander Empangen MSB First
|
|
|
|
|
{
|
|
|
|
|
MMC_Write &=~(1<<SPI_Clock); //erzeugt ein Clock Impuls (Low)
|
|
|
|
|
WAIT_HALF_CLOCK;
|
|
|
|
|
|
|
|
|
|
if (bit_is_set(MMC_Read,SPI_DI) > 0) //Lesen des Pegels von MMC_DI
|
|
|
|
|
{
|
|
|
|
|
Byte |= (1<<(a-1));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Byte &=~(1<<(a-1));
|
|
|
|
|
}
|
|
|
|
|
MMC_Write |=(1<<SPI_Clock); //setzt Clock Impuls wieder auf (High)
|
|
|
|
|
if(bit_is_set(MMC_Read,SPI_DI) > 0) //Lesen des Pegels von MMC_DI
|
|
|
|
|
{
|
|
|
|
|
Byte |= (1<<(a-1));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Byte &=~(1<<(a-1));
|
|
|
|
|
}
|
|
|
|
|
MMC_Write |=(1<<SPI_Clock); //setzt Clock Impuls wieder auf (High)
|
|
|
|
|
WAIT_HALF_CLOCK;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return (Byte);
|
|
|
|
|
}
|
|
|
|
|
@ -165,23 +166,22 @@ void mmc_write_byte (unsigned char Byte)
|
|
|
|
|
{
|
|
|
|
|
#if SPI_Mode //Routine für Hardware SPI
|
|
|
|
|
SPDR = Byte; //Sendet ein Byte
|
|
|
|
|
while(!(SPSR & (1<<SPIF))) //Wartet bis Byte gesendet wurde
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
while(!(SPSR & (1 << SPIF))) {;}//Wartet bis Byte gesendet wurde
|
|
|
|
|
#else //Routine für Software SPI
|
|
|
|
|
for (unsigned char a=8; a>0; a--) //das Byte wird Bitweise nacheinander Gesendet MSB First
|
|
|
|
|
for(unsigned char a=8; a>0; a--) //das Byte wird Bitweise nacheinander Gesendet MSB First
|
|
|
|
|
{
|
|
|
|
|
if (bit_is_set(Byte,(a-1))>0) //Ist Bit a in Byte gesetzt
|
|
|
|
|
{
|
|
|
|
|
MMC_Write |= (1<<SPI_DO); //Set Output High
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MMC_Write &= ~(1<<SPI_DO); //Set Output Low
|
|
|
|
|
}
|
|
|
|
|
if(bit_is_set(Byte,(a-1))>0) //Ist Bit a in Byte gesetzt
|
|
|
|
|
{
|
|
|
|
|
MMC_Write |= (1<<SPI_DO); //Set Output High
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MMC_Write &= ~(1<<SPI_DO); //Set Output Low
|
|
|
|
|
}
|
|
|
|
|
MMC_Write &= ~(1<<SPI_Clock); //erzeugt ein Clock Impuls (LOW)
|
|
|
|
|
|
|
|
|
|
WAIT_HALF_CLOCK;
|
|
|
|
|
MMC_Write |= (1<<SPI_Clock); //setzt Clock Impuls wieder auf (High)
|
|
|
|
|
WAIT_HALF_CLOCK;
|
|
|
|
|
}
|
|
|
|
|
MMC_Write |= (1<<SPI_DO); //setzt Output wieder auf High
|
|
|
|
|
#endif
|
|
|
|
|
|