hello all,
i am trying to connect micro sd card with pic18f4520 using mikroC.
but i have ready module of micro sd card socket with required push-pull and pulled down resisters.but i am not able to detect sd card.
i have attached my code below please give me solution as soon as fast.
thanks
i am trying to connect micro sd card with pic18f4520 using mikroC.
but i have ready module of micro sd card socket with required push-pull and pulled down resisters.but i am not able to detect sd card.
i have attached my code below please give me solution as soon as fast.
thanks
Rich (BB code):
// MMC module connections
sbit Mmc_Chip_Select at LATC0_bit; // for writing to output pin always use latch (PIC18 family)
sbit Mmc_Chip_Select_Direction at TRISC0_bit;
// eof MMC module connections
const LINE_LEN = 43;
char err_txt[20] = "FAT16 not found";
char file_contents[LINE_LEN] = "XX MMC/SD FAT16 library by Anton Rieckertn";
char filename[14] = "MIKRO00x.TXT"; // File names
unsigned short loop, loop2;
unsigned long i, size;
char Buffer[512];
void M_Create_New_File()
{
filename[7] = 'A';
Mmc_Fat_Set_File_Date(2010, 4, 19, 9, 0, 0); // Set file date & time info
Mmc_Fat_Assign(&filename, 0xA0); // Find existing file or create a new one
Mmc_Fat_Rewrite(); // To clear file and start with new data
for(loop = 1; loop <= 99; loop++)
{
UART1_Write('.');
file_contents[0] = loop / 10 + 48;
file_contents[1] = loop % 10 + 48;
Mmc_Fat_Write(file_contents, LINE_LEN-1); // write data to the assigned file
}
}
void main() {
#define COMPLETE_EXAMPLE // comment this line to make simpler/smaller example
ADCON1 |= 0x0F; // Configure AN pins as digital
CMCON |= 7; // Turn off comparators
// Initialize UART1 module
// UART1_Init(19200);
Delay_ms(10);
// UART1_Write_Line("PIC-Started"); // PIC present report
// Initialize SPI1 module
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
// use fat16 quick format instead of init routine if a formatting is needed
if (Mmc_Fat_Init() == 0) {
// reinitialize spi at higher speed
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
//--- Test start
UART1_Write_Line("Test Start.");
//--- Test routines. Uncomment them one-by-one to test certain features
M_Create_New_File();
}
Attachments
-
2 KB Views: 30
Last edited by a moderator: