User manual
mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
405
//-------------- Main. Uncomment the function(s) to test the desired operation(s)
begin
err_txt := ‘FAT16 not found’;
le_contents := ‘XX MMC/SD FAT16 library by Anton Rieckert#’;
le_contents[41] := 10; // newline
lename := ‘MIKRO00xTXT’;
{$DEFINE COMPLETE_EXAMPLE}// comment this line to make simpler/smaller example
PORTD := 0;
TRISD := 0;
PORTF := 0;
TRISF := 0;
ADPCFG := 0xFFFF; // initialize AN pins as digital
//--- set up USART for the le read
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_
PRI_64,
_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
UART1_Init(19200); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
U1MODE.ALTIO := 1; // Switch Rx and Tx pins on their alternate locations.
// This is used to free the pins for other module, namely the SPI.
UART_Write_Line(‘dsPIC-Started’); // dsPIC present report
// 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
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_
PRI_4,
_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
//--- Test start
UART_Write_Line(‘Test Start.’);
M_Create_New_File();
{$IFDEF COMPLETE_EXAMPLE}
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: Cf_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.