Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
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}
dim MMC_chip_select as sbit at PORTB.B2
dim MMC_chip_select_direction as sbit at DDRB.B2
' universal variables
dim
k, i 
as word ' universal for loops and other stuff
' Variables for MMC routines
dData 
as byte[512]  ' Buffer for MMC sector reading/writing
data_for_registers 
as byte[16] ' buffer for CID and CSD registers
' Display byte in hex
sub procedure printhex(dim as byte)
dim bHi, bLo as byte
bHi = i 
and 0xF0               ' High nibble
bHi = bHi >> 4
bHi = bHi + "0"
if (bHi>"9") then
bHi = bHi + 7
end if
bLo = (i 
and 0x0F) + "0"       ' Low nibble
if (bLo>"9") then
bLo = bLo+7
end if
UART1_Write(bHi)
UART1_Write(bLo)
end sub
main:
DDRC = 255
PORTC = 0
{$IFDEF RS232_debug}
UART1_Init(19200)
{$ENDIF}
Delay_ms(10)
DDRA = 255
PORTA = 1
273
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6