Merge branch 'master' of ghostdub.de:gg-button

master
Paul Goeser 14 years ago
commit 42532aa047

52
mmc.c

@ -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

@ -8,11 +8,13 @@ Copyright (C) 2004 Ulrich Radig
#define _MMC_H_
#include <avr/io.h>
#include <util/delay.h>
#include "ringbuf_small.h"
//#define SPI_Mode 1 //1 = Hardware SPI | 0 = Software SPI
#define SPI_Mode 0
#define WAIT_HALF_CLOCK _delay_us(1)
#define MMC_Write PORTB //Port an der die MMC/SD-Karte angeschlossen ist also des SPI
#define MMC_Read PINB
@ -87,5 +89,3 @@ extern unsigned char mmc_read_cid (unsigned char *);
#define nop() __asm__ __volatile__ ("nop" ::)
#endif //_MMC_H_

Loading…
Cancel
Save