Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SD Card interfacing with PIC18f452

Status
Not open for further replies.

monikaK29

New Member
hello, i've been trying to interface SD card with pic18f452 and display the text files on it on sd card.
i've written a code in MikroC the code is as follows :
Code:
// Lcd pinout settings
sbit RS at RD5_bit;
sbit RW at RD6_bit;
sbit EN at RD7_bit;
sbit D7 at RB7_bit;
sbit D6 at RB6_bit;
sbit D5 at RB5_bit;
sbit D4 at RB4_bit;
sbit D3 at RB3_bit;
sbit D2 at RB2_bit;
sbit D1 at RB1_bit;
sbit D0 at RB0_bit;




// MMC module connections
sbit Mmc_Chip_Select at RA5_bit;
sbit Mmc_Chip_Select_Direction at TRISA5_bit;

char character,size;
char filename[10]="MPS.txt";
int i;

// LCD routines
void command(char command)
{
RS=0;
RW=0;
PORTB=command;
EN=1;
Delay_ms(100);
EN=0;
}

void Data(char d)
{

RS=1;
RW=0;
PORTB=d;
EN=1;
Delay_ms(100);
EN=0;
}

//SPI Routines
void Init_SPI()
{
TRISC.F4 = 1; //SDI as input
TRISC.F5 = 0; //SDO as output
TRISC.F3 = 0; //SCK as output

TRISA.F5 = 0; //CS as output



Mmc_Chip_Select = 1;



SSPSTAT.SMP = 0; //set data to be sampled at the middle
SSPSTAT.CKE = 1; //Transmition occurs on transition from active to Idle clock state

SSPCON1.CKP = 0; //idle state of clock is LOW
SSPCON1.SSPM0 = 0; //spi clock is Fosc/64
SSPCON1.SSPM1 = 1;
SSPCON1.SSPM2 = 0;
SSPCON1.SSPM3 = 0;

SSPCON1.SSPEN = 1; //Enable the SPI Interface
}


void main()
{

TRISA=0x00;
TRISB=0x00;
TRISD=0x00;
TRISC.F0=0;
TRISC.F1=0;
TRISC.F2=0;
ADCON1=0x06;
EN=0;


command(0x38);
command(0x0e);
command(0x01);
command(0x06);

Data('m');
Data('i');
Data('n');
Data('i');
Data('p');
Data('r');
Data('o');
Data('j');
Data('e');
Data('c');
Data('t');
Delay_ms(1000);



/* if(!Mmc_Fat_Init())
{

SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
Init_SPI();
Mmc_Fat_Assign(&filename, 0);
Mmc_Fat_Reset(&size); // To read file, procedure returns size of file
for (i = 1; i <= size; i++)
{
Mmc_Fat_Read(&character);
Data(character);
}
} */

}
however when i simulate it in proteus8 , the code runs till the if loop if the part after if is comented. if not, the microcontroller pins all turn grey colour (neither high nor low) can you please help?
 

Attachments

  • Capture.PNG
    Capture.PNG
    133.3 KB · Views: 140
ohh..ok. Is there a place where i can find example. because the ones i downloaded wont work either. also, is there a way to write it in mplab? i read about the petit fatfs library, but i don't know how to use it. can you please help?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top