## AVR309 DLL description

Function prototypes in "AVR309.dll" library:

Delphi:

const
AVR309DLL= 'AVR309.dll';
//return values from AVR309DLL functions:
NO_ERROR = 0;
DEVICE_NOT_PRESENT = 1;
NO_DATA_AVAILABLE = 2;
INVALID_BAUDRATE = 3;
OVERRUN_ERROR = 4;
INVALID_DATABITS = 5;
INVALID_PARITY = 6;
INVALID_STOPBITS = 7;
function DoGetInfraCode(var TimeCodeDiagram:array of byte; var DiagramLength:integer):integer; stdcall external AVR309DLL name 'DoGetInfraCode';
function DoSetDataPortDirection(DirectionByte:byte):integer; stdcall external AVR309DLL name 'DoSetDataPortDirection';
function DoGetDataPortDirection(var DataDirectionByte:byte):integer; stdcall external AVR309DLL name 'DoGetDataPortDirection';
function DoSetOutDataPort(DataOutByte:byte):integer; stdcall external AVR309DLL name 'DoSetOutDataPort';
function DoGetOutDataPort(var DataOutByte:byte):integer; stdcall external AVR309DLL name 'DoGetOutDataPort';
function DoGetInDataPort(var DataInByte:byte):integer; stdcall external AVR309DLL name 'DoGetInDataPort';

function DoSetDataPortDirections(DirectionByteB, DirectionByteC, DirectionByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name 'DoSetDataPortDirections';
function DoGetDataPortDirectio ns(var DataDirectionByteB, DirectionByteC, DirectionByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name 'DoGetDataPortDirections';
function DoSetOutDataPorts(DataOutByteB, DataOutByteC, DataOutByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name 'DoSetOutDataPorts';
function DoGetOutDataPorts(var DataOutByteB, DataOutByteC, DataOutByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name 'DoGetOutDataPorts';
function DoGetInDataPorts(var DataInByteB, DataInByteC, DataInByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name 'DoGetInDataPorts';
function DoEEPROMRead(Address:word; var DataInByte:byte):integer; stdcall external AVR309DLL name 'DoEEPROMRead';
function DoEEPROMWrite(Address:word; DataOutByte:byte):integer; stdcall external AVR309DLL name 'DoEEPROMWrite';
function DoRS232Send(DataOutByte:byte):integer; stdcall external AVR309DLL name 'DoRS232Send';
function DoRS232Read(var DataInByte:byte):integer; stdcall external AVR309DLL name 'DoRS232Read';
function DoSetRS232Baud(BaudRate:integer):integer; stdcall external AVR309DLL name 'DoSetRS232Baud';
function DoGetRS232Baud(var BaudRate:integer):integer; stdcall external AVR309DLL name 'DoGetRS232Baud';
function DoGetRS232Buffer(var RS232Buffer:array of byte; var RS232BufferLength:integer):integer; stdcall external AVR309DLL name 'DoGetRS232Buffer';
function DoRS232BufferSend(var RS232Buffer:array of byte; var RS232BufferLength:integer):integer; stdcall external AVR309DLL name 'DoRS232BufferSend';
function DoSetRS232DataBits(DataBits:byte):integer; stdcall external AVR309DLL name 'DoSetRS232DataBits';
function DoGetRS232DataBits(var DataBits:byte):integer; stdcall external AVR309DLL name 'DoGetRS232DataBits';
function DoSetRS232Parity(Parity:byte):integer; stdcall external AVR309DLL name 'DoSetRS232Parity';
function DoGetRS232Parity(var Parity:byte):integer; stdcall external AVR309DLL name 'DoGetRS232Parity';
function DoSetRS232StopBits(StopBits:byte):integer; stdcall external AVR309DLL name 'DoSetRS232StopBits';
function DoGetRS232StopBits(var StopBits:byte):integer; stdcall external AVR309DLL name 'DoGetRS232StopBits';

C++ Builder / Microsoft Visual C++:

#ifdef __cplusplus
extern "C" {
#endif
#define AVR309DLL "AVR309.dll";
//return values from AVR309DLL functions:
#define NO_ERROR 0;
#define DEVICE_NOT_PRESENT 1;
#define NO_DATA_AVAILABLE 2;
#define INVALID_BAUDRATE 3;
#define OVERRUN_ERROR 4;
#define INVALID_DATABITS 5;
#define INVALID_PARITY 6;
#define INVALID_STOPBITS 7;
int __stdcall DoGetInfraCode(uchar * TimeCodeDiagram, int DummyInt, int * DiagramLength);
int __stdcall DoSetDataPortDirection(uchar DirectionByte);
int __stdcall DoGetDataPortDirection(uchar * DataDirectionByte);
int __stdcall DoSetOutDataPort(uchar DataOutByte);
int __stdcall DoGetOutDataPort(uchar * DataOutByte);
int __stdcall DoGetInDataPort(uchar * DataInByte);

int __stdcall DoSetDataPortDirections(uchar DirectionByteB, uchar DirectionByte, uchar DirectionByte, uchar UsedPorts);
int __stdcall DoGetDataPortDirections(uchar * DataDirectionByteB, uchar * DataDirectionByteC, uchar * DataDirectionByteD, uchar * UsedPorts);
int __stdcall DoSetOutDataPorts(uchar DataOutByteB, uchar DataOutByteC, uchar DataOutByteD, uchar UsedPorts);
int __stdcall DoGetOutDataPorts(uchar * DataOutByteB, uchar * DataOutByteC, uchar * DataOutByteD, uchar * UsedPorts);
int __stdcall DoGetInDataPorts(uchar * DataInByteB, uchar * DataInByteC, uchar * DataInByteD, uchar * UsedPorts);

int __stdcall DoEEPROMRead(ushort Address, uchar * DataInByte);
int __stdcall DoEEPROMWrite(ushort Address, uchar DataOutByte);
int __stdcall DoRS232Send(uchar DataOutByte);
int __stdcall DoRS232Read(uchar * DataInByte);
int __stdcall DoSetRS232Baud(int BaudRate);
int __stdcall DoGetRS232Baud(int * BaudRate);
int __stdcall DoGetRS232Buffer(uchar * RS232Buffer, int DummyInt, int * RS232BufferLength);
int __stdcall DoRS232BufferSend(uchar * RS232Buffer, int DummyInt, int * RS232BufferLength);
int __stdcall DoSetRS232DataBits(uchar DataBits);
int __stdcall DoGetRS232DataBits(uchar * DataBits);
int __stdcall DoSetRS232Parity(uchar Parity);
int __stdcall DoGetRS232Parity(uchar * Parity);
int __stdcall DoSetRS232StopBits(uchar StopBits);
int __stdcall DoGetRS232StopBits(uchar * StopBits);
#ifdef __cplusplus
}
#endif

Visual Basic:

Public Const AVR309DLL="AVR309.dll";
'return values from AVR309DLL functions:
Public Const NO_ERROR = 0;
Public Const DEVICE_NOT_PRESENT = 1;
Public Const NO_DATA_AVAILABLE = 2;
Public Const INVALID_BAUDRATE = 3;
Public Const OVERRUN_ERROR = 4;
Public Const INVALID_DATABITS = 5;
Public Const INVALID_PARITY = 6;
Public Const INVALID_STOPBITS = 7;

Public Declare Function DoGetInfraCode Lib "AVR309.dll" (ByRef TimeCodeDiagram As Any, ByVal DummyInt As Long, ByRef DiagramLength As Long) As Long
Public Declare Function DoSetDataPortDirection Lib "AVR309.dll" (ByVal DirectionByte As Byte) As Long
Public Declare Function DoGetDataPortDirection Lib "AVR309.dll" (ByRef DataDirectionByte As Byte) As Long
Public Declare Function DoSetOutDataPort Lib "AVR309.dll" (ByVal DataOutByte As Byte) As Long
Public Declare Function DoGetOutDataPort Lib "AVR309.dll" (ByRef DataOutByte As Byte) As Long
Public Declare Function DoGetInDataPort Lib "AVR309.dll" (ByRef DataInByte As Byte) As Long

Public Declare Function DoSetDataPortDirections Lib "AVR309.dll" (ByVal DirectionByte B As Byte, ByVal DirectionByteC As Byte, ByVal DirectionByte D As Byte, ByVal UsedPorts As Byte) As Long
Public Declare Function DoGetDataPortDirections Lib "AVR309.dll" (ByRef DataDirectionByteB As Byte, ByRef DataDirectionByteC As Byte, ByRef DataDirectionByteD As Byte, ByRef UsedPorts As Byte) As Long
Public Declare Function DoSetOutDataPorts Lib "AVR309.dll" (ByVal DataOutByte B As Byte, ByVal DataOutByteC As Byte, ByVal DataOutByteD As Byte, ByVal UsedPorts As Byte) As Long
Public Declare Function DoGetOutDataPorts Lib "AVR309.dll" (ByRef DataOutByteB As Byte, ByRef DataOutByteC As Byte, ByRef DataOutByteD As Byte, ByRef UsedPorts As Byte) As Long
Public Declare Function DoGetInDataPorts Lib "AVR309.dll" (ByRef DataInByteB As Byte, ByRef DataInByteC As Byte, ByRef DataInByteD As Byte, ByRef UsedPorts As Byte) As Long

Public Declare Function DoEEPROMRead Lib "AVR309.dll" (ByVal Address As Word, ByRef DataInByte As Byte) As Long
Public Declare Function DoEEPROMWrite Lib "AVR309.dll" (ByVal Address As Word, ByVal DataOutByte As Byte) As Long
Public Declare Function DoRS232Send Lib "AVR309.dll" (ByVal DataOutByte As Byte) As Long
Public Declare Function DoRS232Read Lib "AVR309.dll" (ByRef DataInByte As Byte) As Long
Public Declare Function DoSetRS232Baud Lib "AVR309.dll" (ByVal BaudRate As Long) As Long
Public Declare Function DoGetRS232Baud Lib "AVR309.dll" (ByRef BaudRate As Long) As Long
Public Declare Function DoGetRS232Buffer Lib "AVR309.dll" (ByRef RS232Buffer As Any, ByVal DummyInt As Long, ByRef RS232BufferLength As Long) As Long
Public Declare Function DoRS232BufferSend Lib "AVR309.dll" (ByRef RS232Buffer As Any, ByVal DummyInt As Long, ByRef RS232BufferLength As Long) As Long
Public Declare Function DoSetRS232DataBits Lib "AVR309.dll" (DataBits As Byte) As Long
Public Declare Function DoGetRS232DataBits Lib "AVR309.dll" (ByRef DataBits As Byte) As Long
Public Declare Function DoSetRS232Parity Lib "AVR309.dll" (Parity As Byte) As Long
Public Declare Function DoGetRS232Parity Lib "AVR309.dll" (ByRef Parity As Byte) As Long
Public Declare Function DoSetRS232StopBits Lib "AVR309.dll" (StopBits As Byte) As Long
Public Declare Function DoGetRS232StopBits Lib "AVR309.dll" (ByRef StopBits As Byte) As Long

function DoGetInfraCode(var TimeCodeDiagram:array of byte; var DiagramLength:integer):integer; stdcall external AVR309DLL name 'DoGetInfraCode';

Function reads last received Infrared Code from microcontrollers infrared buffer and frees this infrared buffer.
Parameters
TimeCodeDiagram
[out] Array of bytes for infrared code storing. Every byte in this array represents duration of one signal level (H or L level). Duration
is in 85.3us steps (e.g. number 10 represents 853us duration of L or H level). Last number in array (with index DiagramLength) has
L level and the levels alternates in array (LHL.....HLHLHL). Maximum length of this array is 256.
DiagramLength
[out] Length of returned TimeCodeDiagram array. If DiagramLength=0 then no code was received since last request.

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

Notes:
Microcontroller stores infrared code into its internal buffer. If another code was received before reading stored code from microcontroller
by this function, then the second (3-th, 4-th, ...) code are lost.

function DoSetDataPortDirection(DirectionByte:byte):integer; stdcall;
function DoSetDataPortDirections(DirectionByteB, DirectionByteC, DirectionByteD, UsedPorts:byte):integer; stdcall;

Function sets transfer direction of microcontroller data pins (D0-D7).
Parameters
DirectionByte
[in] Byte which bits represents direction of given microcontroller pin. Bit value 1 represents output and bit value 0 represents input.
UsedPorts
[out] bit mask: which ports to set (combination of : 1=PortB, 2=PortC, 4=PortD).

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

function DoGetDataPortDirection(var DataDirectionByte:byte):integer; stdcall;
function DoGetDataPortDirections(var DataDirectionByteB, DirectionByteC, DirectionByteD, UsedPorts:byte):integer; stdcall;

Function reads transfer direction of microcontroller data pins (D0-D7).
Parameters
DataDirectionByte
[in] Byte which bits represents direction of microcontroller data pins. Bit value 1 represents output and bit value 0 represents input.
UsedPorts
[out] bit mask: which ports was readed (combination of : 1=PortB, 2=PortC, 4=PortD).

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

function DoSetOutDataPort(DataOutByte:byte):integer; stdcall;
function DoSetOutDataPorts(DataOutByteB, DataOutByteC, DataOutByteD, UsedPorts:byte):integer; stdcall;

Function sets given state on microcontroller output data pins or set pull-up resistors on microcontroller input data pins (D0-D7).
Parameters
DataOutByte
[in] Byte which bits represents output levels on data pins - if pins are in output direction. If data pin(s) are in input direction
then bit value 1 switch on pull-up resistor and bit value 0 switch off pull-up resistor (high impedance input) on input data pin.
UsedPorts
[out] bit mask: which ports to set (combination of : 1=PortB, 2=PortC, 4=PortD).

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

function DoGetOutDataPort(var DataOutByte:byte):integer; stdcall;
function DoGetOutDataPorts(var DataOutByteB, DataOutByteC, DataOutByteD, UsedPorts:byte):integer; stdcall;

Function reads state of microcontroller output level/pull-up values.
Parameters
DataOutByte
[out] Byte which bits represents output levels written to data pins - if pins are in output direction. If pin(s) are in input direction
then bit value 1 represent switched on pull-up resistor and bit value 0 represent switched off pull-up resistor (high impedance
input) on input data pin.
UsedPorts
[out] bit mask: which ports was readed (combination of : 1=PortB, 2=PortC, 4=PortD).

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

Notes:
The output values are not read from physical pins, but from internal register (stored value). For reading true physical values
on output data pins use function DoGetInDataPort.

function DoGetInDataPort(var DataInByte:byte):integer; stdcall;
function DoGetInDataPorts(var DataInByteB, DataInByteC, DataInByteD, UsedPorts:byte):integer; stdcall;

Function reads state of microcontroller data pins (D0-D7).
Parameters
DataOutByte
[out] Byte which bits represents levels on data pins (level on physical pins).
UsedPorts
[out] bit mask: which ports was readed (combination of : 1=PortB, 2=PortC, 4=PortD).

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

function DoEEPROMRead(Address:byte; var DataInByte:byte):integer; stdcall;

Function reads byte from given address of microcontroller data EEPROM.
Parameters
Address
[in] Byte which bits represents address of internal EEPROM (valid address range: 0 to 127).
DataInByte
[out] Value from EEPROM.

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

function DoEEPROMWrite(Address:byte; DataOutByte:byte):integer; stdcall;

Function writes byte to given address of microcontroller data EEPROM.
Parameters
Address
[in] Byte which bits represents address of internal EEPROM (valid address range: 0 to 127).
DataOutByte
[in] New value to write to EEPROM.

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

Notes:
Function waits for storing byte to EEPROM (write time is cca 4ms).

function DoRS232Send(DataOutByte:byte):integer; stdcall;

Function sends byte to microcontroller RS232 line at current baudrate.
Parameters
DataOutByte
[in] Value to send to microcontroller RS232 line.

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

Notes:
Function waits for transmitting given byte: all data bits + stop bit are transmitted before function end.

function DoRS232Read(var DataInByte:byte):integer; stdcall;

Function reads byte received by microcontroller RS232 line.
Parameters
DataInByte
[out] Byte received from microcontroller RS232 line.

Return values
The return values are:
NO_ERROR - one byte received (returned in DataInByte)
NO_DATA_AVAILABLE - no data was received (value DataInByte is not valid)
OVERRUN_ERROR - more bytes was received, but another received bytes was lost: in DataInByte is returned only the first received byte
DEVICE_NOT_PRESENT - error: device is disconnected

function DoSetRS232Baud(BaudRate:integer):integer; stdcall;

Function sets speed of microcontroller RS232 line.
Parameters
BaudRate
[in] Required baudrate of microcontroller RS232 line (in bps).

Return values
The return values are:
NO_ERROR - baudrate was set (error between required and set baudrate is less than 4%)
INVALID_BAUDRATE - not supported baudrate - baudrate was not set (error from required baudrate is more than 4%)
DEVICE_NOT_PRESENT - error: device is disconnected

Notes:
Valid baudrates are cca from 2900 Baud to 780 000 Baud.
Supported "standard" baudrates for AT90S2313 are 4800, 9600, 19200, 38400, 57600
Supported "standard" baudrates for ATmega8 are 600, 1200, 4800, 9600, 19200, 28800, 38400, 57600, 115200
To know internal baudrate - use function DoGetRS232Baud.
After power on - the baudrate is set to 57600.

function DoGetRS232Baud(var BaudRate:integer):integer; stdcall;

Function reads current baudrate of microcontroller RS232 line.
Parameters
BaudRate
[out] Exact value of current baudrate of microcontroller RS232 line.

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

Notes:
Function returns exact current baudrate value - may be slightly different from the required value (error up to 4%).

function DoGetRS232Buffer(var RS232Buffer:array of byte; var RS232BufferLength:integer):integer; stdcall;

Function reads data from microcontrollers internal RS232 buffer (into this buffer is received data from RS232 line).
Parameters
RS232Buffer
[out] Array of bytes for received RS232 bytes storing.
RS232BufferLength
[in/out] Maximum number to return (input to function). Number of bytes returned in RS232Buffer array. If RS232BufferLength=0 then no data was received from RS232 line.

Return values
If the function succeeds, the return value is NO_ERROR.

Notes:
Microcontroller stores received data from RS232 line into its internal buffer. From this FIFO buffer then computer reads the data.

function DoRS232BufferSend(var RS232Buffer:array of byte; var RS232BufferLength:integer):integer; stdcall;

Function sends data buffer to microcontrollers RS232 line.
Parameters
RS232Buffer
[in] Array of bytes to send to RS232 line.
RS232BufferLength
[in/out] Number of bytes to send from RS232Buffer. Returns number of bytes succesfully written to RS232 line.

Return values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is DEVICE_NOT_PRESENT (device is disconnected).

Notes:
Function waits for transmitting all bytes: including stop bit of last byte.

function DoSetRS232DataBits(DataBits:byte):integer; stdcall;

Function set the number of data bits used on RS232 communication line.
Parameters
DataBits
[in] Number of data bits to use (5,6,7,8).

Return values
If the function succeeds, the return value is NO_ERROR.
DEVICE_NOT_PRESENT - device is disconnected.
INVALID_DATABITS - unsupported number of databits.

Notes:
Function is supported only on ATmega8 microcontroller.

function DoGetRS232DataBits(var DataBits:byte):integer; stdcall;

Function returns the number of data bits currently used on RS232 communication line.
Parameters
DataBits
[out] Number of data bits currently used (5,6,7,8).

Return values
If the function succeeds, the return value is NO_ERROR.
DEVICE_NOT_PRESENT - device is disconnected.

Notes:
Function is supported only on ATmega8 microcontroller.

function DoSetRS232Parity(Parity:byte):integer; stdcall;

Function set the parity used on RS232 communication line.
Parameters
Parity
[in] Parity value used on RS232 line:
None = 0;
Odd = 1;
Even = 2;
Mark = 3;
Space = 4;

Return values
If the function succeeds, the return value is NO_ERROR.
DEVICE_NOT_PRESENT - device is disconnected.
INVALID_PARITY - unsupported parity number.

Notes:
Function is supported only on ATmega8 microcontroller.

function DoGetRS232Parity(var Parity:byte):integer; stdcall;

Function returns the parity currently used on RS232 communication line.
Parameters
Parity
[out] Parity currently used (0,1,2,3,4). - see DoSetRS232Parity

Return values
If the function succeeds, the return value is NO_ERROR.
DEVICE_NOT_PRESENT - device is disconnected.

Notes:
Function is supported only on ATmega8 microcontroller.

function DoSetRS232StopBits(StopBits:byte):integer; stdcall;

Function set the number of stopbits used on RS232 communication line.
Parameters
StopBits
[in] Number of stop bits used on RS232 line:
1 stop bit = 0;
2 stop bits = 1;

Return values
If the function succeeds, the return value is NO_ERROR.
DEVICE_NOT_PRESENT - device is disconnected.
INVALID_STOPBITS - unsupported stopbits number.

Notes:
Function is supported only on ATmega8 microcontroller.

function DoGetRS232StopBits(var StopBits:byte):integer; stdcall;

Function returns the number of stop bits currently used on RS232 communication line.
Parameters
StopBits
[out] Number of stop bits currently used (0,1). - see DoSetRS232StopBits

Return values
If the function succeeds, the return value is NO_ERROR.
DEVICE_NOT_PRESENT - device is disconnected.

Notes:
Function is supported only on ATmega8 microcontroller.

For more information see also file AVR309.dpr .

Author Ing. Igor Cesko, Slovakia, www.cesko.host.sk