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;
unsigned char tmp;
char data1[10];
unsigned char times;
unsigned char found1;
void M_Create_New_File() {
Mmc_Fat_Set_File_Date(2010, 4, 19, 9, 0, 0); // Set file date & time info
Mmc_Fat_Assign("TEST.txt", 0xA0); // Find existing file or create a new one
Mmc_Fat_Rewrite();
UART1_Write('.');
for(found1=0;found1<=times;found1++)
{
Mmc_Fat_Write(data1[found1],1); // write data to the assigned file
}
}
void main()
{
osccon=0b01110000;
ADCON1 |= 0x0F; // Configure AN pins as digital
CMCON |= 7; // Turn off comparators
UART1_Init(9600);
Delay_ms(10);
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
UART1_Write_Text("PIC-Started1"); // PIC present report
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
if (Mmc_Fat_Init() == 0) { // Mean that we have communcation
UART1_Write_Text("YES");
times = 0;
found1=0; // Array Pointer ..
while(1){
if (UART1_Data_Ready())
tmp = UART1_Read();
{
if (tmp=10) // If we find Enter ...
{
M_Create_New_File(); // Write to SD card
}
else // collect data
{
data1[found1]=tmp;
found1++;
times++;
}
}
}
}
}