User`s manual

Compact Flash Library provides routines for accessing data on Compact Flash
card (abbrev. CF further in text). CF cards are widely used memory elements,
commonly found in digital cameras. Great capacity (8MB ~ 2GB, and more) and
excellent access time of typically few microseconds make them very attractive for
microcontroller applications.
In CF card, data is divided into sectors, one sector usually comprising 512 bytes
(few older models have sectors of 256B). Read and write operations are not per-
formed directly, but successively through 512B buffer. Following routines can be
used for CF with FAT16, and FAT32 file system.
Before write operation, make sure you don't overwrite boot or FAT sector as it
could make your card on PC or digital cam unreadable. Drive mapping tools, such
as Winhex, can be of a great assistance.
Following routines implement data access to Compact Flash:
Description of individual routines follows.
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
134
mikroBASIC
MikroElektronika: Development tools - Books - Compilers
making it simple...
page
Compact Flash Library
Sector 0
Sector Address
Byte
Address
Sector 1
Sector 2
Sector 3
0
512 bytes
512
1024
1536
sub procedure CF_INIT_PORT(dim byref CtrlPort as byte, dim byref DataPort as byte)
sub function CF_DETECT(dim byref CtrlPort as byte) as byte
sub procedure CF_WRITE_INIT(dim byref CtrlPort as byte, dim byref DataPort as byte,
dim Adr as longint, dim SectCnt as byte)
sub procedure CF_WRITE_BYTE(dim byref CtrlPort as byte, dim byref DataPort as byte,
dim BData as byte)
sub procedure CF_WRITE_WORD(dim byref CtrlPort as byte, dim byref DataPort as byte,
dim WData as word)
sub procedure CF_READ_INIT(dim byref CtrlPort as byte, dim byref DataPort as byte,
dim Adr as longint, dim SectCnt as byte)
sub function CF_READ_BYTE(dim byref CtrlPort as byte, dim byref DataPort as byte) as byte
sub function CF_READ_WORD(dim byref CtrlPort as byte, dim byref DataPort as byte) as word
sub procedure CF_SET_REG_ADR(dim byref CtrlPort as byte, dim adr as byte)