Mikroc, Library example – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 238

Advertising
background image

MikroElektronika: Development tools - Books - Compilers

230

page

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

Library Example

The following code tests MMC 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);

// Wait until MMC is initialized

while

(Mmc_Init(&PORTC, 2)) ;

// Fill the buffer with the 'M' character

for

(i = 0; i <= 511; i++) data[i] = "M";

// Write it to MMC card, sector 55

tmp = Mmc_Write_Sector(55, data);

// Fill the buffer with the 'E' character

for

(i = 0; i <= 511; i++) data[i] = "E";

// Write it to MMC card, sector 56

tmp = Mmc_Write_Sector(56, data);

/** Now to check sectors 55 and 56 **/

// Read from sector 55

tmp = Mmc_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 = Mmc_Read_Sector(56, data);

// Send 512 bytes from buffer to USART

if

(tmp == 0)

for

(i = 0; i < 512; i++) Usart_Write(data[i]);

}

//~!

Advertising
This manual is related to the following products: