User manual

Table Of Contents
302
mikoC PRO for PIC32
MikroElektronika
Library Example
The following example writes 512 bytes at sector no.620, and then reads the data and sends it over UART1 for
a visual check. Hardware congurations in this example are made for the LV-32MX v6 development system and
PIC32MX460F512L.
Copy Code To Clipboard
// set compact ash pinout
char Cf_Data_Port at PORTE;
sbit CF_RDY at RD7_bit;
sbit CF_WE at LATD6_bit; // for writing to output pin always use latch
sbit CF_OE at LATD5_bit; // for writing to output pin always use latch
sbit CF_CD1 at RD4_bit;
sbit CF_CE1 at LATD3_bit; // for writing to output pin always use latch
sbit CF_A2 at LATD2_bit; // for writing to output pin always use latch
sbit CF_A1 at LATD1_bit; // for writing to output pin always use latch
sbit CF_A0 at LATD0_bit; // for writing to output pin always use latch
sbit CF_RDY_direction at TRISD7_bit;
sbit CF_WE_direction at TRISD6_bit;
sbit CF_OE_direction at TRISD5_bit;
sbit CF_CD1_direction at TRISD4_bit;
sbit CF_CE1_direction at TRISD3_bit;
sbit CF_A2_direction at TRISD2_bit;
sbit CF_A1_direction at TRISD1_bit;
sbit CF_A0_direction at TRISD0_bit;
// end of cf pinout
const LINE_LEN = 39;
char err_txt[20] = “FAT16 not found”;
char le_contents[LINE_LEN] = “XX CF FAT16 library by Anton Rieckert\n”;
char lename[14] = “MIKRO00x.TXT”; // File names
unsigned short loop, loop2;
unsigned long i, size;
char Buffer[512];
// UART1 write text and new line (carriage return + line feed)
void UART1_Write_Line(char *uart_text) {
UART1_Write_Text(uart_text);
UART1_Write(13);
UART1_Write(10);
}
// Creates new le and writes some data to it
void M_Create_New_File() {
lename[7] = ‘A’;
Cf_Fat_Set_File_Date(2005,6,21,10,35,0); // Set le date & time info
Cf_Fat_Assign(&lename, 0xA0); // Find existing le or create a new one
Cf_Fat_Rewrite(); // To clear le and start with new data
for(loop = 1; loop <= 99; loop++) {
UART1_Write(‘.’);
le_contents[0] = loop / 10 + 48;
le_contents[1] = loop % 10 + 48;