- •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 |
$framesize = 40 |
' default use 40 |
for the frame space |
|
' These functions only works on BYTE and WORD arrays at the moment !!!!!
'Dim some variables
Dim Wb As Byte , B As Byte
Dim W(10) As Word ' or use a BYTE array
'fill the word array with values from 1 to 10
For B = 1 To 10 W(b) = B
Next
Print "Max number " ; Max(w(1))
Print "Min number " ; Min(w(1))
Dim Idx As Word , M1 As Word
Min(w(1) , M1 , Idx)
Print "Min number " ; M1 ; " index " ; Idx
Max(w(1) , M1 , Idx)
Print "Max number " ; M1 ; " index " ; Idx
End
MEMCOPY
Action
Copies a block of memory
Syntax
bts = MEMCOPY(source, target , bytes[ , option])
Remarks
bts |
The total number of bytes copied. This must be a word or integer |
source |
The first address of the source variable that will be copied. |
target |
The first address of the target variable that will be copied to. |
bytes |
The number of bytes to copy from "source" to "target" |
option |
An optional numeric constant with one of the following values : |
|
1 - only the source address will be increased after each copied byte |
|
2 - only the target address will be increased after each copied byte |
|
3 - both the source and target address will be copied after each copied byte |
|
|
By default, option 3 is used as this will copy a block of memory from one memory location to another location. But it it also possible to fill an entire array of memory block with the value of 1 memory location. For example to clear a whole block or preset it with a value.
And with option 2, you can for example get a number of samples from a register like PINB and store it into an array.
See also
page -571-
© MCS Electronics, 1995-2007
NONE
ASM
NONE
Example
'----------------------------------------------------------------------- |
: MEMCOPY.BAS |
'name |
|
'copyright |
: (c) 1995-2006, MCS Electronics |
'purpose |
: show memory copy function |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'use in simulator |
: possible |
'---------------------------------------------------------------------- |
' specify the used |
$regfile = "m88def.dat" |
|
micro |
' used crystal |
$crystal = 8000000 |
|
frequency |
' use baud rate |
$baud = 19200 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 16 |
|
for the SW stack |
|
$framesize = 40 |
|
Dim Ars(10) As Byte |
'source bytes |
Dim Art(10) As Byte |
'target bytes |
Dim J As Byte |
'index |
For J = 1 To 10 |
'fill array |
Ars(j) = J |
|
Next |
|
J = Memcopy(ars(1) , Art(1) , 4) |
'copy 4 bytes |
Print J ; " bytes copied" |
|
For J = 1 To 10 |
|
Print Art(j) |
|
Next |
|
J = Memcopy(ars(1) , Art(1) , 10 , 2) |
'assign them all |
with element 1 |
|
Print J ; " bytes copied" |
|
For J = 1 To 10 |
|
Print Art(j) |
|
Next |
|
Dim W As Word , L As Long |
|
W = 65511 |
'copy 2 bytes from |
J = Memcopy(w , L , 2) |
|
word to long |
|
End |
|
MIN
page -572-
© MCS Electronics, 1995-2007
Action
Returns the minimum value of a byte or word array.
Syntax
var1 = MIN(var2) MIN(ar(1), m , idx)
Remarks
var1 |
Variable that will be assigned with the minimum value. |
var2 |
The first address of the array. |
|
|
|
The MIN statement can return the index too |
Ar(1) |
Starting element to get the minimum value and index of |
M |
Returns the minimum value of the array |
Idx |
Return the index of the array that contains the minimum value. Returns 0 if |
|
there is no minimum value. |
|
|
The MIN() ans MAX() functions work on BYTE and WORD arrays only.
See also
MAX
Example
'----------------------------------------------------------------------------- |
|
------------ |
: minmax.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: show the MIN and MAX functions |
'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 |
|
' These functions only works on BYTE and WORD arrays at the moment !!!!!
'Dim some variables
Dim Wb As Byte , B As Byte
Dim W(10) As Word ' or use a BYTE array
page -573-
© MCS Electronics, 1995-2007
'fill the word array with values from 1 to 10
For B = 1 To 10 W(b) = B
Next
Print "Max number " ; Max(w(1))
Print "Min number " ; Min(w(1))
Dim Idx As Word , M1 As Word
Min(w(1) , M1 , Idx)
Print "Min number " ; M1 ; " index " ; Idx
Max(w(1) , M1 , Idx)
Print "Max number " ; M1 ; " index " ; Idx
End
MID
Action
The MID function returns part of a string (a sub string).
The MID statement replaces part of a string variable with another string.
Syntax
var = MID(var1 ,st [, l] ) MID(var ,st [, l] ) = var1
Remarks
var |
The string that is assigned. |
Var1 |
The source string. |
st |
The starting position. |
l |
The number of characters to get/set. |
|
|
See also
LEFT , RIGHT
Example
Dim S As String * 15 , Z As String * 15 |
|
S ="ABCDEFG" |
|
Z = Left(s , 5) |
'ABCDE |
Print Z |
|
Z = Right(s , 3) : Print Z |
|
Z = Mid(s , 2 , 3) : Print Z |
|
End |
|
NBITS
Action
page -574-
© MCS Electronics, 1995-2007
Set all except the specified bits to 1.
Syntax
Var = NBITS( b1 [,bn])
Remarks
Var |
The BYTE/PORT variable that is assigned with the constant. |
B1 , bn |
A list of bit numbers that NOT must be set to 1. |
|
|
While it is simple to assign a value to a byte, and there is special boolean notation &B for assigning bits, the Bits() and NBits() function makes it simple to assign a few bits.
B = &B01111101 : how many zero’s are there?
This would make it more readable: B = NBits(1, 7)
You can read from the code that bit 1 and bit 7 are NOT set to 1.
It does not save code space as the effect is the same.
The NBITS() function will set all bits to 1 except for the specified bits. It can only be used on bytes and port registers.
Valid bits are in range from 0 to 7.
See Also
BITS
Example
'----------------------------------------------------------------------------- |
|
--- |
: bits-nbits.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demo for Bits() AND Nbits() |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'use in simulator |
: possible |
'-----------------------------------------------------------------------------
---
$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 B As Byte |
|
'while you can use &B notation for setting bits, like B = &B1000_0111 'there is also an alternative by specifying the bits to set
B = Bits(0 , 1 , 2 , 7) 'set only bit 0,1,2 and 7
Print B
page -575-
