User manual
344
mikoPascal PRO for PIC32
MikroElektronika
//-------------- Main. Uncomment the function(s) to test the desired operation(s)
begin
{$DEFINE COMPLETE_EXAMPLE} // comment this line to get smaller example
err_txt := ‘FAT16 not found’;
le_contents := ‘XX MMC/SD FAT16 library by Anton Rieckert#’;
le_contents[41] := 10; // newline
lename := ‘MIKRO00xTXT’;
CHECON := 0x32;
AD1PCFG := 0xFFFF; // initialize AN pins as digital
// Initialize UART1 module
UART1_Init(56000);
Delay_ms(10);
UART_Write_Line(‘MCU-Started’); // MCU present report
//--- set up SPI for the le read
SPI2_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 64, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_
MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
Delay_ms(10);
// use fat16 quick format instead of init routine if a formatting is needed
if Mmc_Fat_Init() = 0 then
begin
// reinitialize spi at higher speed
SPI2_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 8, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_
MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
//--- Test start
UART_Write_Line(‘Test Start.’);
//--- Test routines. Uncomment them one-by-one to test certain features
M_Create_New_File();
{$IFDEF COMPLETE_EXAMPLE}
M_Create_New_File();
M_Create_Multiple_Files();
M_Open_File_Rewrite();
M_Open_File_Append();
M_Open_File_Read();
M_Delete_File();
M_Test_File_Exist();
M_Create_Swap_File();
{$ENDIF}
UART_Write_Line(‘Test End.’);
end
else
begin
UART_Write_Line(err_txt); // Note: Mmc_Fat_Init tries to initialize a card more
than once.
// If card is not present, initialization may last
longer (depending on clock speed)
end;
end.