Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
Library Example
The following example demonstrates MMC library test. Upon flashing, insert a
MMC/SD card into the module, when you should receive the "Init-OK" message.
Then, you can experiment with MMC read and write functions, and observe the
results through the Usart Terminal.
// if defined, we have a debug messages on PC terminal
program MMC_Test;
{$DEFINE RS232_debug}
var MMC_chip_select : sbit at PORTB.B2;
var MMC_chip_select_direction : sbit at DDRB.B2;
// universal variables
var
k, i : word; // universal for loops and other stuff
// Variables for MMC routines
dData : 
array[512] of byte;// Buffer for MMC sector reading/writing
data_for_registers : 
array[16] of byte; // buffer for CID and CSD
registers
// Display byte in hex
procedure printhex(i : byte) ;
var bHi, bLo : byte;
begin
bHi := i 
and 0xF0;               // High nibble
bHi := bHi 
shr 4;
bHi := bHi + '0';
if (bHi>'9') then
bHi := bHi + 7;
bLo := (i 
and 0x0F) + '0';        // Low nibble
if (bLo>'9') then
bLo := bLo+7;
UART1_Write(bHi);
UART1_Write(bLo);
end;
begin
DDRC := 255;
PORTC := 0;
{$IFDEF RS232_debug}
UART1_Init(19200);
{$ENDIF}
Delay_ms(10);
DDRA := 255;
PORTA := 1;
286
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6