Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Program for FAT16 for MMC card using 8051

Status
Not open for further replies.

pratish86

Newbie level 4
Joined
Nov 5, 2006
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,358
i need to program a filesystem possibly fat16 (in c language) for mmc card(512 mb) using cygnal 8051 f040...cn ne 1 pls help me..is thr ne such code readily available?
 

fat16 8051

FAT16/32 file system driver
Source file
**broken link removed**
Header file
**broken link removed**

it is written for AVR, but can port to 8051 easily
 

    pratish86

    Points: 2
    Helpful Answer Positive Rating
sd card fat16 8051

hey thanx... but bfore doin tht i thnk i need to hav an idea on programming the mmc using spi interface can u give sm links whch ll give sample programs for writing n reading data on mmc?
 

fat16

hey pls check dis program i found..its not wrking properly..also it just transfers 1 char..wht if i ve to transfer strings..m using cygnal ide software.

//Uses SPI_Transfer function to send and receive information
// through the SPI p[ins. As information is sent, the progress of
// the program is sent out through the UART to be monitored.


//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <c8051f040.h> // SFR declarations
#include <stdio.h> // Standard I/O


sbit MOSI = P0^0; // Master Out / Slave In (output)
sbit MISO = P0^1; // Master In / Slave Out (input)
sbit SCK = P0^2; // Serial Clock (output)
sbit NSS = P0^3; // Slave Select (output to chip select)


//-----------------------------------------------------------------------------
// 16-bit SFR Definitions
//-----------------------------------------------------------------------------

sfr16 DP = 0x82; // data pointer
sfr16 TMR2RL = 0xca; // Timer2 reload value
sfr16 TMR2 = 0xcc; // Timer2 counter
sfr16 PCA0CP1 = 0xe9; // PCA0 Module 1 Capture/Compare
sfr16 PCA0CP2 = 0xeb; // PCA0 Module 2 Capture/Compare
sfr16 PCA0 = 0xf9; // PCA0 counter
sfr16 PCA0CP0 = 0xfb; // PCA0 Module 0 Capture/Compare

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------

#define SYSCLK 24500000 // SYSCLK frequency in Hz
#define BAUDRATE 115200 // Baud rate of UART in bps

//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------

void PORT_Init (void); // Port I/O configuration
void SYSCLK_Init (void); // SYSCLK Initialization
void UART0_Init (void); // UART0 Initialization

extern char SPI_Transfer (char); // SPI Transfer routine

char SPI_Transfer (char SPI_byte)
{
unsigned char SPI_count; // counter for SPI transaction

for (SPI_count = 8; SPI_count > 0; SPI_count--) // single byte SPI loop
{
MOSI = SPI_byte & 0x80; // put current outgoing bit on MOSI
SPI_byte = SPI_byte << 1; // shift next bit into MSB

SCK = 0x01; // set SCK high

SPI_byte |= MISO; // capture current bit on MISO

SCK = 0x00; // set SCK low
}

return (SPI_byte);

} // END SPI_Transfer

//-----------------------------------------------------------------------------
// Global VARIABLES
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------

void main (void) {

unsigned char test_counter, SPI_return; // used to test SPI routine

// Disable Watchdog timer
PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer
// enable)

SYSCLK_Init (); // initialize oscillator
PORT_Init (); // initialize ports and GPIO
UART0_Init (); // initialize UART0
EA = 1; // enable global interrupts

while (1)
{
for (test_counter = 0; test_counter <= 0xFF; test_counter++)
{

NSS = 0x00; // select SPI Slave device

SPI_return = SPI_Transfer(test_counter); // send/receive SPI byte

NSS = 0x01; // de-select SPI Slave device

printf("\nSPI Out = 0x%02X, SPI In = 0x%02X", (unsigned)test_counter,
(unsigned)SPI_return);
// send SPI data out to UART
// for verification purposes
}
}
}

//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Configure the Crossbar and GPIO ports.
// P0.0 - UART TX (push-pull)
// P0.1 - UART RX
// P0.2 - MOSI (push-pull)
// P0.3 - MISO
// P0.4 - SCK (push-pull)
// P0.5 - NSS (push-pull)
// P0.6 -
// P0.7 -
//
void PORT_Init (void)
{
XBR0 = 0x0F; // skip SPI pins in XBAR
XBR1 = 0x03; // UART0 TX and RX pins enabled
XBR2 = 0x40; // Enable crossbar and weak pull-ups
P0MDOUT |= 0x1D; // enable TX0, MOSI, SCK, and NSS as
// push-pull outputs
}

//-----------------------------------------------------------------------------
// SYSCLK_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to use the internal 24.5 MHz clock
// as its clock source.
//
void SYSCLK_Init (void)
{

OSCICN = 0x07; // select internal oscillator as SYSCLK
// source
}

//-----------------------------------------------------------------------------
// UART0_Init
//-----------------------------------------------------------------------------
//
// Configure the UART0 using Timer1, for <BAUDRATE> and 8-N-1.
//
void UART0_Init (void)
{
SCON0 = 0x10; // SCON0: 8-bit variable bit rate
// level of STOP bit is ignored
// RX enabled
// ninth bits are zeros
// clear RI0 and TI0 bits
if (SYSCLK/BAUDRATE/2/256 < 1)
{
TH1 = -(SYSCLK/BAUDRATE/2);
CKCON &= ~0x13;
CKCON |= 0x10; // T1M = 1; SCA1:0 = xx
}
else if (SYSCLK/BAUDRATE/2/256 < 4)
{
TH1 = -(SYSCLK/BAUDRATE/2/4);
CKCON &= ~0x13;
CKCON |= 0x01; // T1M = 0; SCA1:0 = 01
}
else if (SYSCLK/BAUDRATE/2/256 < 12)
{
TH1 = -(SYSCLK/BAUDRATE/2/12);
CKCON &= ~0x13; // T1M = 0; SCA1:0 = 00
}
else
{
TH1 = -(SYSCLK/BAUDRATE/2/48);
CKCON &= ~0x13;
CKCON |= 0x02; // T1M = 0; SCA1:0 = 10
}

TL1 = 0xff; // set Timer1 to overflow immediately
TMOD |= 0x20; // TMOD: timer 1 in 8-bit autoreload
TMOD &= ~0xD0; // mode
TR1 = 1; // START Timer1
TI0 = 1; // Indicate TX0 ready
}
 

reading fat16 sd program 8051

pratish86 said:
i need to program a filesystem possibly fat16 (in c language) for mmc card(512 mb) using cygnal 8051 f040...cn ne 1 pls help me..is thr ne such code readily available?

On Silabs application notes pages you can find a project with **broken link removed** for USB Mass Storage device (support for SD, MMC and CF). I think that this is all you need to start your project.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top