
- •Table of Contents
- •Index
- •Keyword Reference
- •Installation
- •Installation of BASCOM
- •BASCOM IDE
- •Running BASCOM-AVR
- •File New
- •File Close
- •File Save
- •File Save As
- •File Print Preview
- •File Print
- •File Exit
- •View PinOut
- •View PDF viewer
- •View Error Panel
- •Edit Undo
- •Edit Redo
- •Edit Cut
- •Edit Copy
- •Edit Paste
- •Edit Find
- •Edit Find Next
- •Edit Replace
- •Edit Goto
- •Edit Toggle Bookmark
- •Edit Goto Bookmark
- •Edit Indent Block
- •Edit Unindent Block
- •Edit Remark Block
- •Program Compile
- •Program Syntax Check
- •Program Show Result
- •Program Simulate
- •Program Send to Chip
- •Tools Terminal Emulator
- •Tools LCD Designer
- •Tools LIB Manager
- •Tools Graphic Converter
- •Tools Stack Analyzer
- •Tools Plugin Manager
- •Tools Batch Compile
- •Options Compiler
- •Options Compiler Chip
- •Options Compiler Output
- •Options Compiler Communication
- •Options Compiler I2C, SPI, 1WIRE
- •Options Compiler LCD
- •Options Communication
- •Options Environment
- •Options Simulator
- •Options Programmer
- •Supported Programmers
- •ISP programmer
- •PG302 programmer
- •Sample Electronics cable programmer
- •KITSRUS Programmer
- •MCS Universal Interface Programmer
- •STK500 Programmer
- •Lawicel BootLoader
- •AVR ISP Programmer
- •USB-ISP Programmer
- •MCS Bootloader
- •Options Monitor
- •Options Printer
- •Window Cascade
- •Window Tile
- •Window Arrange Icons
- •Window Minimize All
- •Help About
- •Help Index
- •Help MCS Forum
- •Help MCS Shop
- •Help Support
- •Help Knowledge Base
- •Help Credits
- •BASCOM Editor Keys
- •Program Development Order
- •PlugIns
- •Font Editor
- •PinOut
- •BASCOM HARDWARE
- •Additional Hardware
- •AVR Internal Hardware
- •AVR Internal Registers
- •AVR Internal Hardware TIMER0
- •AVR Internal Hardware TIMER1
- •AVR Internal Hardware Watchdog timer
- •AVR Internal Hardware Port B
- •AVR Internal Hardware Port D
- •Adding XRAM
- •Attaching an LCD Display
- •Memory usage
- •Using the 1 WIRE protocol
- •Using the SPI protocol
- •Power Up
- •Chips
- •ATtiny22
- •ATtiny13
- •ATtiny15
- •ATtiny25
- •ATtiny45
- •ATtiny85
- •ATtiny26
- •ATtiny2313
- •ATMEGA8
- •ATMEGA16
- •ATMEGA32
- •ATMEGA48
- •ATMEGA88
- •ATMEGA168
- •ATMEGA64
- •ATMEGA103
- •ATMEGA128
- •ATMEGA161
- •ATMEGA162
- •ATMEGA163
- •ATMEGA165
- •ATMEGA169
- •ATMEGA323
- •ATMEGA603
- •ATMEGA8515
- •ATMEGA8535
- •BASCOM Language Fundamentals
- •Changes compared to BASCOM-8051
- •Language Fundamentals
- •Mixing ASM and BASIC
- •Assembler mnemonics
- •Reserved Words
- •Error Codes
- •Newbie problems
- •Tips and tricks
- •ASCII chart
- •BASCOM Language Reference
- •$BAUD
- •$BAUD1
- •$BOOT
- •$CRYSTAL
- •$DATA
- •$DEFAULT
- •$EEPLEAVE
- •$EEPROM
- •$EEPROMHEX
- •$EXTERNAL
- •$FRAMESIZE
- •$HWSTACK
- •$INCLUDE
- •$INITMICRO
- •$LCDPUTCTRL
- •$LCDPUTDATA
- •$LCDRS
- •$LCDVFO
- •$LOADER
- •$LOADERSIZE
- •$NOCOMP
- •$NOINIT
- •$NORAMCLEAR
- •$PROG
- •$PROGRAMMER
- •$REGFILE
- •$ROMSTART
- •$SERIALINPUT
- •$SERIALINPUT1
- •$SERIALINPUT2LCD
- •$SERIALOUTPUT
- •$SERIALOUTPUT1
- •$SWSTACK
- •$TIMEOUT
- •$TINY
- •$WAITSTATE
- •$XRAMSIZE
- •$XRAMSTART
- •1WIRECOUNT
- •1WRESET
- •1WREAD
- •1WSEARCHFIRST
- •1WSEARCHNEXT
- •1WVERIFY
- •1WWRITE
- •ACOS
- •ALIAS
- •ASIN
- •BASE64DEC
- •BASE64ENC
- •BAUD
- •BAUD1
- •BINVAL
- •BIN2GRAY
- •BITWAIT
- •BITS
- •BLOAD
- •BSAVE
- •BUFSPACE
- •BYVAL
- •CALL
- •CHECKSUM
- •CIRCLE
- •CLEAR
- •CLOCKDIVISION
- •CLOSE
- •CLOSESOCKET
- •CONFIG
- •CONFIG 1WIRE
- •CONFIG ACI
- •CONFIG ADC
- •CONFIG ATEMU
- •CONFIG BCCARD
- •CONFIG CLOCK
- •CONFIG CLOCKDIV
- •CONFIG COM1
- •CONFIG COM2
- •CONFIG COMx
- •CONFIG DATE
- •CONFIG DCF77
- •CONFIG DEBOUNCE
- •CONFIG I2CDELAY
- •CONFIG I2CSLAVE
- •CONFIG INPUT
- •CONFIG INTx
- •CONFIG GRAPHLCD
- •CONFIG KBD
- •CONFIG KEYBOARD
- •CONFIG LCD
- •CONFIG LCDBUS
- •CONFIG LCDMODE
- •CONFIG LCDPIN
- •CONFIG PORT
- •CONFIG PRINT
- •CONFIG PRINTBIN
- •CONFIG PS2EMU
- •CONFIG RC5
- •CONFIG SDA
- •CONFIG SCL
- •CONFIG SERIALIN
- •CONFIG SERIALIN1
- •CONFIG SERIALOUT
- •CONFIG SERIALOUT1
- •CONFIG SINGLE
- •CONFIG SPI
- •CONFIG SERVOS
- •CONFIG TCPIP
- •CONFIG TIMER0
- •CONFIG TIMER1
- •CONFIG TIMER2
- •CONFIG TWI
- •CONFIG TWISLAVE
- •CONFIG WAITSUART
- •CONFIG WATCHDOG
- •CONFIG X10
- •CONFIG XRAM
- •CONST
- •COSH
- •COUNTER0 and COUNTER1
- •CPEEK
- •CPEEKH
- •CRYSTAL
- •CURSOR
- •DATA
- •DAYOFWEEK
- •DAYOFYEAR
- •DATE$
- •DATE
- •DEBUG
- •DEBOUNCE
- •DECR
- •DECLARE FUNCTION
- •DECLARE SUB
- •DEFxxx
- •DEFLCDCHAR
- •DELAY
- •DISABLE
- •DISKFREE
- •DISKSIZE
- •DISPLAY
- •DO-LOOP
- •DriveCheck
- •DriveGetIdentity
- •DriveInit
- •DriveReset
- •DriveReadSector
- •DriveWriteSector
- •DTMFOUT
- •ECHO
- •ELSE
- •ENABLE
- •ENCODER
- •EXIT
- •FILEATTR
- •FILEDATE
- •FILEDATETIME
- •FILELEN
- •FILETIME
- •FLUSH
- •FORMAT
- •FOR-NEXT
- •FOURTHLINE
- •FRAC
- •FREEFILE
- •FUSING
- •GETADC
- •GETATKBD
- •GETATKBDRAW
- •GETDSTIP
- •GETDSTPORT
- •GETKBD
- •GETRC
- •GETRC5
- •GETTCPREGS
- •GETSOCKET
- •GLCDCMD
- •GLCDDATA
- •GOSUB
- •GOTO
- •GRAY2BIN
- •HEXVAL
- •HIGH
- •HIGHW
- •HOME
- •I2CINIT
- •I2CRECEIVE
- •I2CSEND
- •I2START,I2CSTOP, I2CRBYTE, I2CWBYTE
- •IDLE
- •IF-THEN-ELSE-END IF
- •INCR
- •INITFILESYSTEM
- •INITLCD
- •INKEY
- •INPUTBIN
- •INPUTHEX
- •INPUT
- •INSTR
- •ISCHARWAITING
- •KILL
- •LCASE
- •LCDAT
- •LCDCONTRAST
- •LEFT
- •LINE
- •LINE INPUT
- •LTRIM
- •LOAD
- •LOADADR
- •LOADLABEL
- •LOADWORDADR
- •LOCAL
- •LOCATE
- •LOOKDOWN
- •LOOKUP
- •LOOKUPSTR
- •LOWERLINE
- •MAKEBCD
- •MAKEINT
- •MAKEDEC
- •MAKETCP
- •MEMCOPY
- •NBITS
- •ON INTERRUPT
- •ON VALUE
- •OPEN
- •PEEK
- •POKE
- •POPALL
- •POWER
- •POWERDOWN
- •POWERSAVE
- •PRINTBIN
- •PSET
- •PS2MOUSEXY
- •PULSEIN
- •PULSEOUT
- •PUSHALL
- •RC5SEND
- •RC5SENDEXT
- •RC6SEND
- •READ
- •READEEPROM
- •READMAGCARD
- •RESET
- •RESTORE
- •RETURN
- •RIGHT
- •ROTATE
- •ROUND
- •RTRIM
- •SECELAPSED
- •SECOFDAY
- •SEEK
- •SELECT-CASE-END SELECT
- •SETFONT
- •SETTCP
- •SETTCPREGS
- •SENDSCAN
- •SENDSCANKBD
- •SERIN
- •SEROUT
- •SETIPPROTOCOL
- •SHIFT
- •SHIFTCURSOR
- •SHIFTIN
- •SHIFTOUT
- •SHIFTLCD
- •SHOWPIC
- •SHOWPICE
- •SINH
- •SOCKETCONNECT
- •SOCKETLISTEN
- •SOCKETSTAT
- •SONYSEND
- •SOUND
- •SPACE
- •SPIIN
- •SPIINIT
- •SPIMOVE
- •SPIOUT
- •SPLIT
- •START
- •STCHECK
- •STOP
- •STRING
- •SYSSEC
- •SYSSECELAPSED
- •SYSDAY
- •SWAP
- •TCPCHECKSUM
- •TCPREAD
- •TCPWRITE
- •TCPWRITESTR
- •TANH
- •THIRDLINE
- •TIME$
- •TIME
- •TOGGLE
- •TRIM
- •UCASE
- •UDPREAD
- •UDPWRITE
- •UDPWRITESTR
- •UPPERLINE
- •VARPTR
- •VERSION
- •WAIT
- •WAITKEY
- •WAITMS
- •WAITUS
- •WHILE-WEND
- •WRITE
- •WRITEEEPROM
- •X10DETECT
- •X10SEND
- •#IF ELSE ENDIF
- •International Resellers
- •International Resellers
- •ASM Libraries
- •EXTENDED I2C
- •MCSBYTE
- •MCSBYTEINT
- •TCPIP
- •LCD4BUSY
- •GLCD
- •GLCDSED
- •LCD-EPSON
- •AVR-DOS File System
- •CF Card
- •Compact FlashCard Driver
- •Elektor CF-Interface
- •XRAM CF-Interface for simulation
- •New CF-Card Drivers
- •Floating Point
- •FP_TRIG
- •DOUBLE
- •I2C SLAVE
- •I2CSLAVE
- •I2C TWI Slave
- •SPISLAVE
- •DATE TIME
- •EUROTIMEDATE
- •DATETIME
- •PS2-AT Mouse and Keyboard Emulation
- •AT_EMULATOR
- •PS2MOUSE_EMULATOR
- •BCCARD
- •BCCARD
- •BCDEF
- •BCCALL
- •BCRESET
- •Tools
- •LCD RGB-8 Converter

© MCS Electronics, 1995-2007
FOURTHLINE
Action
Set LCD cursor to the start of the fourth line.
Syntax
FOURTHLINE
Remarks
Only valid for LCD displays with 4 lines.
See also
HOME , UPPERLINE , LOWERLINE , THIRDLINE, LOCATE
Example
Thirdline |
|
Lcd "Line 3" |
|
Fourthline |
|
Lcd "Line 4" |
'goto home on line |
Home Third |
|
three |
|
Home Fourth |
|
Home F |
'first letter also works |
FRAC
Action
Returns the fraction of a single.
Syntax
var = FRAC( single )
Remarks
var |
A numeric single variable that is assigned with the fraction of |
|
variable single. |
single |
The single variable to get the fraction of. |
|
|
The fraction is the right side after the decimal point of a single.
See Also
INT
page -494-

|
© MCS Electronics, 1995-2007 |
Example |
|
'----------------------------------------------------------------------------- |
|
-- |
: (c) 1995-2005, MCS Electronics |
'copyright |
|
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'purpose |
: demonstrates FRAC function |
'-----------------------------------------------------------------------------
--
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 8000000 |
|
frequency |
' use baud rate |
$baud = 19200 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 40 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
Dim X As Single |
|
X = 1.123456 |
|
Print X |
|
Print Frac(x) |
|
End |
|
FREEFILE
Action
Returns a free Filenumber.
Syntax
bFileNumber = FREEFILE()
Remarks
bFileNumber
A byte variable , which can be used for opening next file
This function gives you a free file number, which can be used for file – opening statements. In contrast to VB this file numbers start with 128 and goes up to 255. Use range 1 to 127 for user defined file numbers to avoid file number conflicts with the system numbers from FreeFile()
This function is implemented for compatility with VB.
See also
INITFILESYSTEM , OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOC, LOF , EOF , FILEATTR , SEEK , BSAVE , BLOAD , KILL , DISKFREE , DISKSIZE , GET , PUT , FILEDATE , FILETIME ,
page -495-

© MCS Electronics, 1995-2007
FILEDATETIME , DIR , FILELEN , WRITE , INPUT
ASM
Calls |
_GetFreeFileNumber |
|
Input |
none |
|
Output |
r24: Filenumber |
r25: Errorcode |
|
C-Flag: Set on Error |
|
|
|
|
Partial Example
Ff =Freefile() ' get file handle
Open"test.txt" For Input As #ff ' we can use a constant for the file too Print Lof(#ff);" length of file"
Print Fileattr(#ff);" file mode" ' should be 1 for input Do
LineInput #ff , S ' read a line
' line input is used to read a line of text from a file Print S ' print on terminal emulator
Loop UntilEof(ff)<> 0
'The EOF() function returns a non-zero number when the end of the file is reached 'This way we know that there is no more data we can read
Close #ff
FUSING
Action
FUSING returns a formatted string of a single value.
Syntax
target = FUSING(source, "mask")
Remarks
target |
The string that is assigned with the formatted string. |
source |
The source variable of the type SINGLE that will be converted |
mask |
The mask for formatting the string. |
|
The mask is a string constant that always must start with #. |
|
After the decimal point you can provide the number of digits you want |
|
the string to have: |
|
#.### will give a result like 123.456. Rounding is used when you use |
|
the # sign. So 123.4567 will be converted into 123.457 |
|
When no rounding must be performed, you can use the & sign instead of |
|
the # sign. But only after the DP. |
|
#.&&& will result in 123.456 when the single has the value 123.4567 |
|
|
When the single is zero, 0.0 will be returned, no matter how the mask is set up.
page -496-

© MCS Electronics, 1995-2007
See also
FORMAT , STR
Example
'----------------------------------------------------------------------------- |
|
------------ |
: fusing.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demo : FUSING |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'-----------------------------------------------------------------------------
------------
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 4000000 |
|
frequency |
' use baud rate |
$baud = 19200 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
Dim S As Single , Z As String * 10
'now assign a value to the single S = 123.45678
'when using str() you can convert a numeric value into a string Z = Str(s)
Print Z 'prints 123.456779477
Z = Fusing(s , "#.##")
'now use some formatting with 2 digits behind the decimal point with rounding Print Fusing(s , "#.##") 'prints 123.46
'now use some formatting with 2 digits behind the decimal point without
rounding |
'prints 123.45 |
Print Fusing(s , "#.&&") |
|
'The mask must start with #. |
|
'It must have at least one # or & after the point. |
|
'You may not mix & and # after the point. |
|
End |
|
GET
Action
Reads a byte from the hardware or software UART.
Reads data from a file opened in BINARY mode.
page -497-

© MCS Electronics, 1995-2007
Syntax
GET #channel, var
GET #channel, var , [pos] [, length]
Remarks
GET in combination with the software/hardware UART reads one byte fromthe UART.
GET in combination with the AVR-DOS file system is very flexible and versatile. It works on files opened in BINARY mode and you can reads all data types.
#channel |
A channel number, which identifies an opened file. This can be a hard coded |
|
constant or a variable. |
Var |
The variable or variable array that will be assigned with the data fromthe |
|
file |
Pos |
This is an optional parameter that may be used to specify the position where |
|
the reading must start from. This must be a long variable. |
Length |
This is an optional parameter that may be used to specify how many bytes |
|
must be read from the file. |
|
|
By default you only need to provide the variable name. When the variable is a byte, 1 byte will be read. When the variable is a word or integer, 2 bytes will be read. When the variable is a long or single, 4 bytes will be read. When the variable is a string, the number of bytes that will be read is equal to the dimensioned size of the string. DIM S as string * 10 , would read 10 bytes.
Note that when you specify the length for a string, the maximum length is 254. The maximum length for a non-string array is 65535.
Partial Example:
GET #1 , var ,,2 ' read 2 bytes, start at current position GET #1, var , PS ' start at position stored in long PS
GET #1, var , PS, 2 ' start at position stored in long PS and read 2 bytes
See also
INITFILESYSTEM , OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOC, LOF , EOF , FREEFILE , FILEATTR , SEEK , BSAVE , BLOAD , KILL , DISKFREE , DISKSIZE , PUT , FILEDATE , FILETIME , FILEDATETIME , DIR , FILELEN , WRITE , INPUT
ASM
current position |
goto new position first |
Byte: |
|
_FileGetRange_1 |
_FileGetRange_1 |
Input: |
Input: |
r24: File number |
r24: File number |
X: Pointer to variable |
X: Pointer to variable |
T-Flag cleared |
r16-19 (A): New position (1-based) |
page -498-

© MCS Electronics, 1995-2007
Word/Integer: _FileGetRange_2
Input:
r24: File number
X: Pointer to variable
T-Flag cleared
Long/Single: _FileGetRange_4
Input:
r24: File number
X: Pointer to variable
T-Flag cleared
String (<= 255 Bytes) with fixed length _FileGetRange_Bytes
Input:
r24: File number r20: Count of Bytes X: Pointer to variable T-Flag cleared
Array (> 255 Bytes) with fixed length _FileGetRange
Input:
r24: File number r20/21: Count of Bytes X: Pointer to variable T-Flag cleared
Output from all kind of usage:
T-Flag Set
_FileGetRange_2 Input:
r24: File number
X: Pointer to variable
r16-19 (A): New position (1-based) T-Flag Set
_FileGetRange_4 Input:
r24: File number
X: Pointer to variable
r16-19 (A): New position (1-based) T-Flag Set
_FileGetRange_Bytes Input:
r24: File number r20: Count of bytes
X: Pointer to variable
r16-19 (A): New position (1-based) T-Flag Set
_FileGetRange Input:
r24: File number r20/21: Count of bytes X: Pointer to variable
r16-19 (A): New position (1-based) T-Flag Set
page -499-