User manual
mikroC PRO for dsPIC
MikroElektronika
321
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 congurations in this example are made for the dsPICPRO2 board and dsPIC30F6014A.
Copy Code To Clipboard
// set compact ash pinout
char Cf_Data_Port at PORTF;
sbit CF_RDY at RD7_bit;
sbit CF_WE at RD6_bit;
sbit CF_OE at RD5_bit;
sbit CF_CD1 at RD4_bit;
sbit CF_CE1 at RD3_bit;
sbit CF_A2 at RD2_bit;
sbit CF_A1 at RD1_bit;
sbit CF_A0 at RD0_bit;
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
char SignalPort at PORTB;
char SignalPort_direction at TRISB;
void InitCF() {
CF_CD1_direction = 1;
while (Cf_Detect() == 0) // wait until CF card is inserted
;
Cf_Init(); // initialize CF
while (!CF_RDY)
;
Delay_ms(2000); // wait for a while until the card is stabilized
} // period depends on used CF card
void TestBytes() {
unsigned int i;
///// Write numbers 0..511 to sector 590
Cf_Write_Init(590,1); // Initialize write at sector address 590
// for 1 sector
SignalPort = 0x03; // Notify that write has started
Delay_ms(1000);
for (i=0; i<=511; i++) // Write 512 bytes to sector 590
Cf_Write_Byte(i);