ABL electronic PIC12 Personal Computer User Manual


 
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
25 2
MikroElektronika:
Development
tools
-
Books
-
Compilers
page
Library Example
The following code tests SD library routines. First, we fill the buffer with 512 “M” characters and
write it to sector 56; then we repeat the sequence with character “E” at sector 56. Finally, we read
the sectors 55 and 56 to check if the write was successful.
unsigned i;
unsigned short tmp;
unsigned short data[512];
void main() {
Usart_Init(9600);
// Initialize ports
tmp = Sd_Init(&PORTC, 2);
// Fill the buffer with the 'M' character
for (i = 0; i <= 511; i++) data[i] = 'M';
// Write it to SD card, sector 55
tmp = Sd_Write_Sector(55, data);
// Fill the buffer with the 'E' character
for (i = 0; i <= 511; i++) data[i] = 'E'
// Write it to SD card, sector 56
tmp = Sd_Write_Sector(56, data);
/** Now to check sectors 55 and 56 **/
// Read from sector 55
tmp = Sd_Read_Sector(55, data);
// Send 512 bytes from buffer to USART
if (tmp == 0)
for (i = 0; i < 512; i++) Usart_Write(data[i]);
// Read from sector 56
tmp = Sd_Read_Sector(56, data);
// Send 512 bytes from buffer to USART
if (tmp == 0)
for (i = 0; i < 512; i++) Usart_Write(data[i]);
}
//~!