Sub Menu

Using ALFAT

Scope

This document discusses and provides solutions to enable a user of the Proton Development Suite to interface with the ALFAT Chip from GHI Electronics.

A ZIP file including a printable PDF version of this document and the necessary include files is available here.

Introduction

ALFAT™ is a full FAT12, 16 and 32 file system precompiled and programmed on a very small but powerful 32 bit LPC2114 ARM processor from Philips. ALFAT™ requires very few external components which means its ideal for interfacing to microcontrollers using nothing more than RS232 serial communications, or an SPI bus. The macro's outlined in this document are for using a USART RS232 interface.

ALFAT™ implements two modes for communication, the first one is text mode, which is a very simple text based command set that is very similar to a DOS operating system. The second mode is framed mode, which is based on data packets, and is more suited for professional applications, and is the method adopted by the macros in this document.

The ALFAT™ SD is a convenient medium in which to test, and use, the ALFAT™ chip. It consists of the ALFAT™ chip itself, along with its required voltage regulators and an SD socket. The necessary interfacing pins are brought out to a standard 2.54mm (0.1") SIL header.

The macros presented in this document offer a reference guide to interfacing to this remarkable device. They provide all the necessary pseudo commands for reading, writing and creating files and folders on a Secure Digital (SD), or Multi Media Card (MMC). 

The connections from the PICmicro® to the ALFAT™ SD are shown below. Note that handshaking takes place using the RTS and CTS pins. This ensures that no data is lost between transactions.

Of course, you can choose your own PICmicro® interfacing pins for CTS, RTS and RESET, but because the macros use the PICmicro's USART, the appropriate TX and RX pins must be used.

The CTS, RTS and RESET interfacing pins can be changed by altering the appropriate lines of code within the ALFAT_SUBS.INC file: -

Symbol ALFAT_RESET_PIN = PORTB.0      ' Output connected to the ALFAT RESET line
Symbol ALFAT_RTS_PIN = PORTB.1        ' Output connected to ALFAT CTS line
Symbol ALFAT_CTS_PIN = PORTB.2        ' Input from ALFAT RTS line

In order to use the pseudo commands (macros), simply include the ALFAT_SUBS.INC file at the top of your program (see examples in this document), and place the include file in the folder of the BASIC program. The include file creates all the appropriate variables and implements a method of assembler conditions that create a minimum of code space if a particular macro is not used, ensuring that maximum use is made of precious code memory.

Because macro's are firmly in the realms of assembler, and it's the compiler that brings them into the BASIC language, they have minimum error checking, and any errors that are produced will be assembler errors. Therefore ensure that the correct amount of parameters, and variable type\s are used with the macro. 

The examples shown in this document are all based around the Crownhill PROTON Development Board using a 20MHz crystal. The include file PROTON18_20.INC simply sets up the compiler for the configuration of this board, and is essentially a list of DECLARES. You will find this file and others within the compiler's INC folder.

If you are not using the PROTON board, simply remove the include directive and place your own declares in the main program.

The examples also use the STOP command extensively, however, this is for demonstration purposes only and an actual program should use a state machine based upon the previous ALFAT™ operation.

Each example shown has been tested, however, you may need to create a file on the SD card with some data in it for some of them. Therefore you will need a means of writing and reading an SD card on the PC. 

Note that because of the complex nature of the macro's, and their use of indirect addressing, they are only for use with a 16-bit core (18F) PICmicro®, and version 3.1 onwards of the PROTON+™ Compiler.

16-bit core (18F) devices now come in a variety of packages from 18, 28, and 40 pin DIL, to 80-pin TQFP monsters. All 18F devices offer a wealth of extras that make programming them both fun and easy. In addition to extra code memory, RAM, and eeprom memory, they also offer the ability of operating at 40Mhz while still only using a 10MHz crystal or resonator, and most have on-board 8MHz oscillators. However, for these macros its best to use an external crystal.

They also eliminate the dreaded PAGED memory that plagues 12 and 14-bit core devices, making the underlying assembler code streamlined and efficient. 

If you haven't used one before, here's your chance, you will not regret it! 

RESET_ALFAT

Syntax 

RESET_ALFAT 

Overview

Reset the ALFAT™ chip and wait for the startup text to finish.

Example

OPTIMISER_LEVEL = 6			' Set the optimiser to level 6
Include "PROTON18_20.INC"		' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"		' Load the ALFAT subroutines into memory

  Delayms 200				' Wait for things to stabilise
  Clear					' Clear all user RAM
Cls					' Clear the LCD

  RESET_ALFAT				' Reset the ALFAT chip
  FRAME_MODE_ON				' Enter Frame Mode
If ALFAT_ACK = 1 Then			' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  Print "FRAME MODE ON"
Endif 
Stop 

Notes

Before the ALFAT™ chip can be used for the first time, it requires a reset. This is accomplished by pulling its RESET line low, waiting a few milliseconds, then bringing its RESET line high.

The RESET_ALFAT macro will set the ALFAT_ACK bit if an error occurred while setting up the ALFAT™ device.

Top

FRAME_MODE_ON

Syntax 

FRAME_MODE_ON 

Overview

Place the ALFAT™ chip into Frame Mode.

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  Print "FRAME MODE ON"
Endif 
Stop 

Notes

The FRAME_MODE_ON macro must be used just after the RESET_ALFAT macro and before any other macro can be used, as the ALFAT™ device does not power up in Frame Mode.

Top

FRAME_MODE_OFF

Syntax 

FRAME_MODE_OFF 

Overview

Disable the ALFAT™ chip's Frame Mode.

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  Print "FRAME MODE ON"
Endif 
FRAME_MODE_OFF 
Print at 2,1,"FRAME MODE OFF"
Stop 

Notes

The FRAME_MODE_OFF macro can only be used if a FRAME_MODE_ON macro has previously been issued within the program.

Disabling Frame Mode will place the ALFAT™ SD back into text mode. See the ALFAT™ SD documentation for further information concerning this mode.

Top

CHANGE_DRIVE_A

Syntax 

CHANGE_DRIVE_A 

Overview

Direct file transfers to Drive A, which is SD or MMC memory. 

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
  Else
    Print "DRIVE A CHOSEN"
  Endif
Endif 
Stop 

Notes

When the ALFAT™ device first powers up, it's not pointing to any drive and must be given a valid drive letter. Drive A is an SD or MMC drive, while B and C are IDE or Compact Flash master and slave accordingly.

The CHANGE_DRIVE_A macro will set the ALFAT_ACK bit if an error occurred while changing drives, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Top

CHANGE_BAUDRATE_38400

CHANGE_BAUDRATE_57600

Syntax 

CHANGE_BAUDRATE_38400 

and 

CHANGE_BAUDRATE_57600 

Overview

Alter the baud rate of the serial interface to 38400 baud or 57600 baud. 

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  CHANGE_BAUDRATE_57600                ' Change the baudrate to 57600 bps
  If ALFAT_ACK = 1 Then
    Print "BAUD_ER", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
  Else
    Print at 1,1,"BAUD NOW 57600"
    Print at 2,1,"DRIVE A CHOSEN"
  Endif
Endif 
Stop 

Notes

The ALFAT™ device first powers up using a baud rate of 9600 8N1 (8-bit, no Parity, 1 Stop Bit). The CHANGE_BAUDRATE macros instruct the ALFAT™ to change to the appropriate baud rate and also change the speed of the PICmicro's serial interface to suit.

Both CHANGE_BAUDRATE macros will set the ALFAT_ACK bit if an error occurred while changing the baud, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received. The baud rate will not be changed if an error is indicated.

Top

GET_DRIVE_STATS

Syntax 

GET_DRIVE_STATS 

Overview

Read the total amount of sectors on the drive and the amount left. 

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
  Else
    GET_DRIVE_STATS                        ' Get the amount of sectors available
    If ALFAT_ACK = 0 Then                ' If successful..
      Print at 1,1,"TOTAL ", Dec ALFAT_FILESIZE ' Display the values
      Print at 2,1,"FREE ", Dec ALFAT_FREE_SECTORS
    Endif
  Endif
Endif 
Stop 

Notes

The GET_DRIVE_STATS macro will set the ALFAT_ACK bit if an error occurred while reading the drive, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

However, if no errors were detected, it will return the total amount of sectors on the drive in the DWORD variable ALFAT_FILESIZE, and the amount of free sectors in the DWORD variable ALFAT_FREE_SECTORS.

A single sector comprises of 512 bytes. 

Top

FORMAT_DRIVE

Syntax 

FORMAT_DRIVE 

Overview

Perform a quick format of the chosen drive. 

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
Print "FORMATTING"                        
  FORMAT_DRIVE                                ' Format the Drive
  If ALFAT_ACK = 1 Then                 ' Check if successful
   Print at 1,1,"FORMAT_ER ", Hex2 ALFAT_ERROR_VALUE
   Stop
  Endif
  Print at 1,1,"COMPLETE  "
Stop

Notes

The FORMAT_DRIVE macro will set the ALFAT_ACK bit if an error occurred while formatting the drive, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

The drive must have been chosen by issuing the CHANGE_DRIVE_A macro before the FORMAT_DRIVE macro can be used.

The FORMAT_DRIVE macro  resets the File Allocation Table (FAT) Only. No change occurs to the Boot Sector or MBR.

Usually new media cards are purchased preformatted, however, if not, the media MUST be formatted on a PC before ALFAT™ can use it.

Top

CREATE_DIRECTORY

Syntax 

CREATE_DIRECTORY FileName

Overview

Create a new directory on the drive. 

Operators

FileName Can be a quoted string of characters, or a STRING variable holding the name of the directory to delete. A maximum of 12 characters is allowed for the name and extension, and must follow standard DOS 8.3 rules with regard to characters used. The filename is in the form: "filename.ext"

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
CREATE_DIRECTORY "NEW_DIR"                ' Create a new directory named NEW_DIR
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "CREATE_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  Print "SUCCESS!" 
Endif 
Stop 

Notes

The CREATE_DIRECTORY macro will set the ALFAT_ACK bit if an error occurred while creating the new directory, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Top

CHANGE_DIRECTORY

Syntax 

CHANGE_DIRECTORY FileName

Overview

Move the path to a new directory on the drive. 

Operators

FileName Can be a quoted string of characters, or a STRING variable holding the name of the directory to delete. A maximum of 12 characters is allowed for the name and extension, and must follow standard DOS 8.3 rules with regard to characters used. The filename is in the form: "filename.ext"

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
CREATE_DIRECTORY "NEW_DIR"                ' Create a new directory named NEW_DIR
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "CREATE_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Endif 
CHANGE_DIRECTORY "NEW_DIR"                ' Point to the directory named NEW_DIR
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "CHANGE_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  Print "SUCCESS!" 
Endif 
Stop 

Notes

The CHANGE_DIRECTORY macro will set the ALFAT_ACK bit if an error occurred while changing to the new directory, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Top

DELETE_DIRECTORY

Syntax 

DELETE_DIRECTORY FileName

Overview

Delete a directory on the drive. 

Operators

FileName Can be a quoted string of characters, or a STRING variable holding the name of the directory to delete. A maximum of 12 characters is allowed for the name and extension, and must follow standard DOS 8.3 rules with regard to characters used. The filename is in the form: "filename.ext"

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
CREATE_DIRECTORY "NEW_DIR"                ' Create a new directory named NEW_DIR
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "CREATE_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Endif 
DELETE_DIRECTORY "NEW_DIR"                ' Delete the directory named NEW_DIR
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "DELETE_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  Print "SUCCESS!" 
Endif 
Stop 

Notes

The DELETE_DIRECTORY macro will set the ALFAT_ACK bit if an error occurred while deleting the directory, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Top

OPEN_FILE

Syntax 

OPEN_FILE FileName ,  File Handle , File Mode

Overview

Create or open a file on the drive. 

Operators

FileName Can be a quoted string of characters, or a STRING variable holding the name of the directory to delete. A maximum of 12 characters is allowed for the name and extension, and must follow standard DOS 8.3 rules with regard to characters used. The filename is in the form: "filename.ext"

File Handle Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the file handle of 0 to 15.

File Mode Can be a BYTE, WORD, or DWORD variable, or a user constant  that holds the type of file to open. "a" for an append mode file. "w" for a write mode file. "r" for a read mode file.

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
  Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
  Cls                                                  ' Clear the LCD
  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
OPEN_FILE "NEW_FILE.TXT",1,"w"        ' Create a file in write mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "OPEN_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  CLOSE_FILE 1                                ' Close handle 1 file
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE   
  Else
    Print "SUCCESS!" 
  Endif
Endif 
Stop 

Notes

The OPEN_FILE macro will set the ALFAT_ACK bit if an error occurred while opening the file, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Top

FIND_FILE

Syntax 

FIND_FILE FileName

Overview

Return the attributes of a file or directory (if found). Also return the file's size in bytes. 

Operators

FileName Can be a quoted string of characters, or a STRING variable holding the name of the file to find. A maximum of 12 characters is allowed for the name and extension, and must follow standard DOS 8.3 rules with regard to characters used. The filename is in the form: "filename.ext"

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
  Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
  Cls                                                  ' Clear the LCD
  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
FIND_FILE "NEW_FILE.TXT"                ' Locate the file named "NEW_FILE.TXT"
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "FIND_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  Print at 1,1,"ATTRIB ", Hex2 ALFAT_ATTRIB ' Display its attribute
  Print at 2,1,"FILESIZE ", Dec ALFAT_FILESIZE ' Display its size
Endif 
Stop 

Notes

The FIND_FILE macro will set the ALFAT_ACK bit if an error occurred while finding the file or directory, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received. The BYTE variable ALFAT_ATTRIB will hold the files attribute, while the DWORD variable ALFAT_FILESIZE will hold its size (in bytes).  

File attribute values (in hexadecimal) returned in variable ALFAT_ATTRIB :

READ ONLY         $01

HIDDEN                 $02

SYSTEM                 $04

VOLUME ID                 $08

DIRECTORY         $10

ARCHIVE                 $20

Top

FLUSH_FILE

Syntax 

FLUSH_FILE File Handle

Overview

Flush the ALFAT's write buffer into a previously opened file. FLUSH_FILE performs the same function as CLOSE_FILE but does not release the file's handle.

Operators

File Handle Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the file handle of a previously opened file.

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
OPEN_FILE "NEW_FILE.TXT",1,"w"        ' Create a file in write mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "OPEN_ER " , Hex2 ALFAT_ERROR_VALUE
Else 
  FLUSH_FILE 1                                ' Flush the write buffer
  If ALFAT_ACK = 1 Then                 ' Check if successful
          Print "FLUSH_ER ", Hex2 ALFAT_ERROR_VALUE
  Endif
  CLOSE_FILE 1                                ' Close handle 1 file
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE   
  Else
    Print "SUCCESS!" 
  Endif
Endif 
Stop 

Notes

The FLUSH_FILE macro will set the ALFAT_ACK bit if an error occurred while flushing the write buffer, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Top

RENAME_FILE

Syntax 

RENAME_FILE Original FileName , New FileName

Overview

Change the name of a file or directory. 

Operators

Original FileName Can be a quoted string of characters, or a STRING variable holding the original name of the file. A maximum of 12 characters is allowed for the name and extension, and must follow standard DOS 8.3 rules with regard to characters used. The filename is in the form: "filename.ext"

New FileName Can be a quoted string of characters, or a STRING variable holding the new name of the file. A maximum of 12 characters is allowed for the name and extension, and must follow standard DOS 8.3 rules with regard to characters used. The filename is in the form: "filename.ext"

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
  Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
RENAME_FILE "FNAME1.TXT","FNAME2.TXT"        ' Rename the file
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "RENAME_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  Print "SUCCESS!" 
Endif 
Stop 

Notes

The RENAME_FILE macro will set the ALFAT_ACK bit if an error occurred while renaming the file or directory, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Top

SEEK_FILE

Syntax 

SEEK_FILE File Handle , Position within File

Overview

Move to a specific location within a previously opened file. 

Operators

File Handle Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the file handle of a previously opened file.

Position within File Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the position within the file to move.

Example

OPTIMISER_LEVEL = 6                                ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                        ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
Dim MY_ARRAY[20] as Byte                        ' Create an array of 20 elements

  Delayms 200                                        ' Wait for things to stabilise
  Clear                                                        ' Clear all user RAM
Cls                                                          ' Clear the LCD

  RESET_ALFAT                                        ' Reset the ALFAT chip
  FRAME_MODE_ON                                         ' Enter Frame Mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                        ' Point to Drive A:
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
OPEN_FILE "NEW_FILE.TXT",1,"r"                ' Open a file in read mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "OPEN_ER " , Hex2 ALFAT_ERROR_VALUE
Else 
  SEEK_FILE 1,6                                        ' Goto location 6 within the file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "SEEK_ER ", Hex2 ALFAT_ERROR_VALUE
  Else
    READ_BYTES_FROM_FILE 1,MY_ARRAY,6        ' Read 6 bytes from the file
    If ALFAT_ACK = 1 Then                         ' Check if successful
      Print "READ_ER ", Hex2 ALFAT_ERROR_VALUE
    Else
      Print at 1,1,"VALUE " , Str MY_ARRAY\6
      Print at 2,1,"BYTES READ ", Dec ALFAT_READ_AMOUNT
    Endif 
  Endif
  CLOSE_FILE 1                                ' Close handle 1 file
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE   
  Endif
Endif 
Stop 

Notes

The SEEK_FILE macro will set the ALFAT_ACK bit if an error occurred while accessing the write buffer, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

The file to seek from must have previously been opened in READ mode. SEEK_FILE does not work with a file in WRITE or APPEND mode.

Top

CLOSE_FILE

Syntax 

CLOSE_FILE File Handle

Overview

Close an open file on the drive. 

Operators

File Handle Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the file handle of a previously opened file. This parameter can be omitted as long as the value held in the variable ALFAT_FILE_HANDLE has not been changed since the file was opened.

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory

  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
OPEN_FILE "NEW_FILE.TXT",1,"w"        ' Create a file in write mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "OPEN_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  CLOSE_FILE 1                                        ' Close handle 1 file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE   
  Else
    Print "SUCCESS!" 
  Endif
Endif 
Stop 

Notes

The CLOSE_FILE macro will set the ALFAT_ACK bit if an error occurred while closing the file, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Top

DELETE_FILE

Syntax 

DELETE_FILE FileName

Overview

Delete a file on the drive. 

Operators

FileName Can be a quoted string of characters, or a STRING variable holding the name of the directory to delete. A maximum of 12 characters is allowed for the name and extension, and must follow standard DOS 8.3 rules with regard to characters used. The filename is in the form: "filename.ext"

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
  Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
  Cls                                                  ' Clear the LCD
  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
OPEN_FILE "NEW_FILE.TXT",1,"w"                ' Create a file in write mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "OPEN_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  CLOSE_FILE 1                                        ' Close handle 1 file
  If ALFAT_ACK = 1 Then                         ' Check if successful
          Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE
  Else
      DELETE_FILE "NEW_FILE.TXT"                ' Delete the file named NEW_FILE.TXT
        If ALFAT_ACK = 1 Then                 ' Check if successful
            Print "DELETE_ER ", Hex2 ALFAT_ERROR_VALUE
        Else
        Print "SUCCESS!" 
      Endif
  Endif
Endif 
Stop 

Notes

The DELETE_FILE macro will set the ALFAT_ACK bit if an error occurred while deleting the file, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Top

WRITE_BYTE_TO_FILE

Syntax 

WRITE_BYTE_TO_FILE {File Handle ,} Variable

Overview

Write a single byte to an open file. 

Operators

File Handle Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the file handle of a previously opened file. This parameter can be omitted as long as the value held in the variable ALFAT_FILE_HANDLE has not been changed since the file was opened.

Variable  Can be a BYTE variable or an 8-bit constant value that will be written to a previously opened file.

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
  Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
  Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
  Cls                                                  ' Clear the LCD
  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
CREATE_DIRECTORY "NEW_DIR"                        ' Create a new directory        
OPEN_FILE "NEW_FILE.TXT",1,"w"                ' Create a file in write mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "OPEN_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  WRITE_BYTE_TO_FILE "A"                        ' Write the letter "A" to the file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "WRITE_ER ", Hex2 ALFAT_ERROR_VALUE
  Endif
  CLOSE_FILE 1                                        ' Close handle 1 file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE   
  Else
    Print "SUCCESS!"
  Endif
Endif 
Stop 

Notes

The WRITE_BYTE_TO_FILE macro will set the ALFAT_ACK bit if an error occurred while writing to the file, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received. Variable ALFAT_BYTES_WRITTEN will also hold the amount of bytes written.

Top

WRITE_ARRAY_TO_FILE

Syntax 

WRITE_ARRAY_TO_FILE File Handle , Byte Array {, Amount of Bytes}

Overview

Write a byte array to an open file. 

Operators

File Handle Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the file handle of a previously opened file.

Byte Array  Is the Byte array that holds the bytes to be written to the open file.

Amount of Bytes Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the amount of bytes to write to the file. If this parameter is omitted from the macro, the whole of the array will be written.

Example

OPTIMISER_LEVEL = 6                        ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
Dim MY_ARRAY[20] as Byte                ' Create an array to write to the file

Delayms 200                                ' Wait for things to stabilise
  Clear                                                ' Clear all user RAM
Cls                                                  ' Clear the LCD
Str MY_ARRAY = "HELLO WORLD\n\r"        ' Fill the array with some data

  RESET_ALFAT                                ' Reset the ALFAT chip
  FRAME_MODE_ON                                 ' Enter Frame Mode
If ALFAT_ACK = 1 Then                 ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                ' Point to Drive A:
  If ALFAT_ACK = 1 Then                 ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif        
CREATE_DIRECTORY "NEW_DIR"                        ' Create a new directory
OPEN_FILE "NEW_FILE.TXT",1,"w"                ' Create a file in write mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "OPEN_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  ' Write 13 bytes from MY_ARRAY to the file
  WRITE_ARRAY_TO_FILE 1,MY_ARRAY,13 
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "WRITE_ER ", Hex2 ALFAT_ERROR_VALUE
  Else
    Print "BYTES WRITTEN ", Dec ALFAT_BYTES_WRITTEN 
  Endif
  CLOSE_FILE 1                                        ' Close handle 1 file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE   
  Endif
Endif 
Print at 2,1,"FINISHED"
Stop 

Notes

The WRITE_ARRAY_TO_FILE macro will set the ALFAT_ACK bit if an error occurred while writing to the file, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Upon a successful write, the BYTE variable ALFAT_BYTES_WRITTEN will hold the amount of bytes written to the file.

Due to the RAM size reserved by the software, no more than 200 bytes should be written in one operation. In fact, the ALFAT™ documents, state that no more than 64 bytes should be written in one operation, but the author has successfully written many more.

Top

WRITE_STRING_TO_FILE

Syntax 

WRITE_STRING_TO_FILE File Handle , String Variable

Overview

Write a String variable to an open file. 

Operators

File Handle Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the file handle of a previously opened file.

String Variable  Is the String that will be written to the open file.

Example

OPTIMISER_LEVEL = 6                                ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                        ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
Dim MY_STRING as String * 20        ' Create an string to write to the file
  Delayms 200                                        ' Wait for things to stabilise
  Clear                                                        ' Clear all user RAM
Cls                                                          ' Clear the LCD
MY_STRING = "HELLO WORLD\n\r"                ' Fill the string with some text

  RESET_ALFAT                                        ' Reset the ALFAT chip
  FRAME_MODE_ON                                         ' Enter Frame Mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                        ' Point to Drive A:
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "DRIVE_ER ", Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif        
CREATE_DIRECTORY "NEW_DIR"                        ' Create a new directory
OPEN_FILE "NEW_FILE.TXT",1,"w"                ' Create a file in write mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "OPEN_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  WRITE_STRING_TO_FILE 1, MY_STRING         ' Write the string to the file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "WRITE_ER ", Hex2 ALFAT_ERROR_VALUE
  Else
    Print "BYTES WRITTEN " , Dec ALFAT_BYTES_WRITTEN 
  Endif
  CLOSE_FILE 1                                        ' Close handle 1 file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE   
  Endif
Endif 
Print at 2,1, "FINISHED"
Stop 

Notes

The WRITE_STRING_TO_FILE macro will set the ALFAT_ACK bit if an error occurred while writing to the file, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Upon a successful write, the BYTE variable ALFAT_BYTES_WRITTEN will hold the amount of bytes written to the file.

Due to the RAM size reserved by the software, no more than 200 bytes should be written in one operation. In fact, the ALFAT™ documents, state that no more than 64 bytes should be written in one operation, but the author has successfully written many more.

Top

READ_BYTE_FROM_FILE

Syntax 

READ_BYTE_FROM_FILE {File Handle ,} Variable

Overview

Read a single byte from an open file. 

Operators

File Handle Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the file handle of a previously opened file. This parameter can be omitted as long as the value held in the variable ALFAT_FILE_HANDLE has not been changed since the file was opened.

Variable  Should be a BYTE variable that will receive the value read from a previously opened file.

Example

OPTIMISER_LEVEL = 6                                ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                        ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
Dim VAR1 as Byte                                        ' Create a byte variable

Delayms 200                                        ' Wait for things to stabilise
  Clear                                                        ' Clear all user RAM
Cls                                                          ' Clear the LCD

  RESET_ALFAT                                        ' Reset the ALFAT chip
  FRAME_MODE_ON                                         ' Enter Frame Mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                        ' Point to Drive A:
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "DRIVE_ER " , Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
OPEN_FILE "NEW_FILE.TXT",1,"r"                ' Open a file in read mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "OPEN_ER ", Hex2 ALFAT_ERROR_VALUE
Else 
  READ_BYTE_FROM_FILE VAR1                        ' Read a byte from the file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "READ_ER ", Hex2 ALFAT_ERROR_VALUE
  Else
    Print at 1,1,"VALUE ", Dec VAR1
    Print at 2,1,"BYTES READ ", Dec ALFAT_READ_AMOUNT
  Endif
  CLOSE_FILE 1                                        ' Close handle 1 file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE   
  Endif
Endif 
Stop 

Notes

The READ_BYTE_FROM_FILE macro will set the ALFAT_ACK bit if an error occurred while reading from the file, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Variable ALFAT_READ_AMOUNT will  hold the amount of bytes read from the file. If the end of the file is reached, this variable will return holding 0, and the bit variable ALFAT_EOF will be set to 1.

Top

READ_BYTES_FROM_FILE

Syntax 

READ_BYTES_FROM_FILE {File Handle ,} Variable , Amount of Bytes

Overview

Read multiple bytes from an open file. 

Operators

File Handle Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the file handle of a previously opened file. This parameter can be omitted as long as the value held in the variable ALFAT_FILE_HANDLE has not been changed since the file was opened.

Variable  Can be a BYTE ARRAY or STRING variable that will receive the values read from a previously opened file.

Amount of Bytes Can be a BYTE, WORD, or DWORD variable, or a user constant that holds the amount of bytes to read from the file.

Example

OPTIMISER_LEVEL = 6                                ' Set the optimiser to level 6
  Include "PROTON18_20.INC"                        ' Use the PROTON Board for this demo
Include "ALFAT_SUBS.INC"                ' Load the ALFAT subroutines into memory
Dim MY_ARRAY[20] as Byte                        ' Create an array of 20 elements
Delayms 200                                        ' Wait for things to stabilise
  Clear                                                        ' Clear all user RAM
Cls                                                          ' Clear the LCD

  RESET_ALFAT                                        ' Reset the ALFAT chip
  FRAME_MODE_ON                                         ' Enter Frame Mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "START_ER ", Hex2 ALFAT_ERROR_VALUE
  Stop
Else 
  CHANGE_DRIVE_A                                        ' Point to Drive A:
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "DRIVE_ER " , Hex2 ALFAT_ERROR_VALUE
    Stop
  Endif
Endif 
OPEN_FILE "NEW_FILE.TXT",1,"r"                ' Open a file in read mode
If ALFAT_ACK = 1 Then                         ' Check if successful
  Print "OPEN_ER " , Hex2 ALFAT_ERROR_VALUE
Else 
  READ_BYTES_FROM_FILE 1,MY_ARRAY,6        ' Read 6 bytes from the file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "READ_ER ", Hex2 ALFAT_ERROR_VALUE
  Else
    Print at 1,1,"VALUE " , Str MY_ARRAY\6
    Print at 2,1,"BYTES READ ", Dec ALFAT_READ_AMOUNT
  Endif
  CLOSE_FILE 1                                        ' Close handle 1 file
  If ALFAT_ACK = 1 Then                         ' Check if successful
    Print "CLOSE_ER ", Hex2 ALFAT_ERROR_VALUE   
  Endif
Endif 
Stop 

Notes

The READ_BYTES_FROM_FILE macro will set the ALFAT_ACK bit if an error occurred while reading from the file, in which case, the BYTE variable ALFAT_ERROR_VALUE will hold the error value received.

Variable ALFAT_READ_AMOUNT will  hold the amount of bytes read from the file. This may not always be the amount of bytes stated within the macro if there are not that many bytes in the opened file, or an attempt to read past the end of the file is made.

If the end of the file is reached, this variable will return holding 0, and the bit variable ALFAT_EOF will be set to 1.

Error Codes

Below is a list of the error codes (in hexadecimal) that will be present in the variable ALFAT_ERROR_VALUE if the ALFAT_ACK bit is set upon returning from a macro.

Error Number         Description

0x00                         NO_ERROR

0x01                         ERROR_READ_SECTOR

0x02                         ERROR_WRITE_SECTOR

0x03                         ERROR_ERASE_SECTOR

0x11                         ERROR_MBR_SIGNATURE_MISSMATCH

0x12                         ERROR_BS_SIGNATURE_MISSMATCH

0x13                         ERROR_SECTOR_SIZE_NOT_512

0x14                         ERROR_FSINFO_SIGNATURE_MISSMATCH

0x21                         ERROR_CLUSTER_OVER_RANGE

0x22                         ERROR_CLUSTER_UNDER_RANGE

0x23                         ERROR_NEXT_CLUSTER_VALUE_OVER_RANGE

0x24                         ERROR_NEXT_CLUSTER_VALUE_UNDER_RANGE

0x25                         ERROR_NO_FREE_CLUSTERS

0x31                         ERROR_FILE_NAME_FORBIDDEN_CHAR

0x32                         ERROR_FILE_NAME_DIR_NAME_OVER_8

0x33                         ERROR_FILE_NAME_DIR_EXTENSION_OVER_3

0x34                         ERROR_FILE_NAME_FIRST_CHAR_ZERO

0x35                         ERROR_MEDIA_FULL

0x40                         DIR_ENT_FOUND

0x41                         DIR_ENT_NOT_FOUND

0x42                         ERROR_FOLDER_IS_CORRUPTED_FIRST_CLUSTER

0x43                         ERROR_FOLDER_IS_CORRUPTED_DIR_DOT_NOT_FOUND

0x44                         ERROR_FOLDER_IS_CORRUPTED_DIR_DOTDOT_NOT_FOUND

0x45                         ERROR_ROOT_DIRECTORY_IS_FULL

0x46                         ERROR_OPEN_FOLDER_FILE

0x47                         ERROR_WRTIE_TO_READ_MODE_FILE

0x48                         ERROR_SEEK_REQUIER_READ_MODE

0x49                         ERROR_INVALID_SEEK_POINTER

0x4A                         ERROR_FOLDER_NOT_EMPTY

0x4B                         ERROR_IS_NOT_FOLDER

0x4C                         ERROR_READ_MODE_REQUIRED

0x4D                         ERROR_END_OF_DIR_LIST

0x4E                         ERROR_FILE_PARAMETERS

0x4F                         ERROR_INVALID_HANDLE

0x61                         ERROR_COMMANDER_BAD_COMMAND

0x62                         ERROR_COMMANDER_STR_LEN_TOO_LONG

0x63                         ERROR_COMMANDER_NAME_NOT_VALID

0x64                         ERROR_COMMANDER_NUMBER_INVALID

0x65                         ERROR_COMMANDER_WRITE_PARTIAL_FAILURE

0x66                         ERROR_COMMANDER_UNKNOWN_MEDIA_LETTER

0x67                         ERROR_COMMANDER_FAILED_TO_OPEN_MEDIA

0x68                         ERROR_COMMANDER_INCORRECT_CMD_PARAMETER

0xFD                         ERROR_COMMANDER_UNKNOWN_ERROR

Top

Disclaimer

Crownhill reserves the right to make changes to the products contained in this publication in order to improve design, performance or reliability. Neither Crownhill Associates Limited or the author shall be responsible for any claims attributable to errors omissions or other inaccuracies in the information or materials contained in this publication and in no event shall Crownhill Associates or the author be liable for direct indirect or special incidental or consequential damages arising out of the use of such information or material. Neither Crownhill or the author convey any license under any patent or other right, and make no representation that the circuits are free of patent infringement. Charts and schedules contained herein reflect representative operating parameters, and may vary depending upon a user's specific application.

All terms mentioned in this document that are known to be trademarks or service marks have been appropriately marked. Use of a term in this publication should not be regarded as affecting the validity of any trademark.

ALFAT™ is a trade name of GHI Electronics, LLC.                 www.ghielectronics.com

PICmicro® is a trade name of Microchip Technologies Inc.           www.microchip.com

PROTON™ is a trade name of Crownhill Associates Ltd.               www.crownhill.co.uk

Web URL's were correct at the time of publication 

The PROTON+ compiler and this documentation was written by Les Johnson.
The PROTON+ compiler forms part of the Proton Development Suite enabling the programming of PICmicros using BASIC language. For more information visit www.picbasic.org

All Manufacturer Trademarks Acknowledged 

Top