- •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
'Now it is time to show a picture |
|
'SHOWPIC X,Y,label |
|
'The label points to a label that holds the image data |
|
Test: |
|
Showpic 0 , 0 , Plaatje |
' show 2 since we |
Showpic 0 , 64 , Plaatje |
|
have a big display |
|
Wait 2 |
' clear the text |
Cls Text |
|
End |
|
'This label holds the mage data Plaatje:
'$BGF will put the bitmap into the program at this location $bgf "mcs.bgf"
'You could insert other picture data here
PS2MOUSEXY
Action
Sends mouse movement and button information to the PC.
Syntax
PS2MOUSEXY X , Y, button
Remarks
X
Y
Button
The X-movement relative to the current position.
The range is –255 to 255.
The Y-movement relative to the current position.
The range is –255 to 255.
A variable or constant that represents the button state.
0 – no buttons pressed
1- left button pressed
2- right button pressed
4- middle button pressed
You can combine these values by adding them. For example, 6 would emulate that the right and middle buttons are pressed.
To send a mouse click, you need to send two ps2mouseXY statements. The first must indicate that the button is pressed, and the second must release the button.
Ps2mouseXY 0,0,1 ' left mouse pressed
PsmouseXY 0,0,0 ' left mouse released
The SENDSCAN statement could also be used.
page -594-
© MCS Electronics, 1995-2007
See also
SENDSCAN, CONFIG PS2EMU
PULSEIN
Action
Returns the number of units between two occurrences of an edge of a pulse.
Syntax
PULSEIN var , PINX , PIN , STATE
Remarks
var |
A word variable that is assigned with the result. |
PINX |
A PIN register like PIND |
PIN |
The pin number(0-7) to get the pulse time of. |
STATE |
May be 0 or 1. |
|
0 means sample 0 to 1 transition. |
|
1 means sample 1 to 0 transition. |
|
|
ERR variable will be set to 1 in case of a time out. A time out will occur after 65535 unit counts. With 10 uS units this will be after 655.35 mS.
You can add a bitwait statement to be sure that the PULSEIN statement will wait for the start condition. But when using the BITWAIT statement and the start condition will never occur, your program will stay in a loop.
The PULSIN statement will wait for the specified edge.
When state 0 is used, the routine will wait until the level on the specified input pin is 0. Then a counter is started and stopped until the input level gets 1.
No hardware timer is used. A 16 bit counter is used. It will increase in 10 uS units. But this depends on the XTAL. You can change the library routine to adjust the units.
See also
PULSEOUT
ASM
The following ASM routine is called from mcs.lib _pulse_in (calls _adjust_pin)
On entry ZL points to the PINx register , R16 holds the state, R24 holds the pin number to sample.
On return XL + XH hold the 16 bit value.
page -595-
© MCS Electronics, 1995-2007
Example
Dim w As Word
pulsein w , PIND , 1 , 0 'detect time from 0 to 1 print w
end
PULSEOUT
Action
Generates a pulse on a pin of a PORT of specified period in 1uS units for 4 MHz.
Syntax
PULSEOUT PORT , PIN , PERIOD
Remarks
PORT |
Name of the PORT. PORTB for example |
PIN |
Variable or constant with the pin number (0-7). |
PERIOD |
Number of periods the pulse will last. The periods are in uS |
|
when an XTAL of 4 MHz is used. |
|
|
The pulse is generated by toggling the pin twice, thus the initial state of the pin determines the polarity.
The PIN must be configured as an output pin before this statement can be used.
See also
PULSEIN
Example
Dim A As Byte |
'PORTB all output |
Config Portb = Output |
|
pins |
'all pins 0 |
Portb = 0 |
|
Do |
|
For A = 0 To 7 |
'generate pulse |
Pulseout Portb , A , 60000 |
|
Waitms 250 |
'wait a bit |
Next |
'loop for ever |
Loop |
PUSHALL
Action
Saves all registers that might be used by BASCOM.
page -596-
© MCS Electronics, 1995-2007
Syntax
PUSHALL
Remarks
When you are writing your own ASM routines and mix them with BASIC you are unable to tell which registers are used by BASCOM because it depends on the used statements and interrupt routines that can run on the background.
That is why Pushall saves all used registers. Use POPALL to restore the registers.
The saved registers are : R0-R5, R7,R10,R11 and R16-R31
See also
POPALL
PUT
Action
Writes a byte to the hardware or software UART.
Writes data to a file opened in BINARY mode.
Syntax
PUT #channel, var
PUT #channel, var ,[pos] [,length]
Remarks
PUT in combination with the software/hardware UART is provided for compatibility with BASCOM-8051. It writes one byte
PUT in combination with the AVR-DOS file system is very flexible and versatile. It works on files opened in BINARY mode and you can write 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 written to the file |
Pos |
This is an optional parameter that may be used to specify the position where |
|
the data must be written. This must be a long variable. |
Length |
This is an optional parameter that may be used to specify how many bytes |
|
must be written to the file. |
|
|
By default you only need to provide the variable name. When the variable is a byte, 1 byte will be written. When the variable is a word or integer, 2 bytes will be written. When the variable is a long or single, 4 bytes will be written. When the variable is a string, the number of bytes that will be written is equal to the dimensioned size of the string. DIM S as string * 10 , would write 10 bytes.
Note that when you specify the length for a string, the maximum length is 255. The maximum length for a non-string array is 65535.
page -597-
© MCS Electronics, 1995-2007
Example
PUT #1, var
PUT #1, var , , 2 ' write 2 bytes at default position
PUT #1, var ,PS, 2 ' write 2 bytes at location storied in variable PS
See also
INITFILESYSTEM , OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOC, LOF , EOF , FREEFILE , FILEATTR , SEEK , BSAVE , BLOAD , KILL , DISKFREE , DISKSIZE , GET, FILEDATE , FILETIME , FILEDATETIME , DIR , FILELEN , WRITE , INPUT
ASM
current position |
Goto new position first |
Byte: |
|
_FilePutRange_1 |
_FilePutRange_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) |
|
T-Flag Set |
Word/Integer: |
|
_FilePutRange_2 |
_FilePutRange_2 |
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) |
|
T-Flag Set |
Long/Single: |
|
_FilePutRange_4 |
_FilePutRange_4 |
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) |
|
T-Flag Set |
String (<= 255 Bytes) with fixed length |
|
_FilePutRange_Bytes |
_FilePutRange_Bytes |
Input: |
Input: |
r24: File number |
r24: File number |
r20: Count of Bytes |
r20: Count of bytes |
X: Pointer to variable |
X: Pointer to variable |
T-Flag cleared |
r16-19 (A): New position (1-based) |
|
T-Flag Set |
Array (> 255 Bytes) with fixed length |
|
_FilePutRange |
_FilePutRange |
Input: |
Input: |
r24: File number |
r24: File number |
r20/21: Count of Bytes |
r20/21: Count of bytes |
X: Pointer to variable |
X: Pointer to variable |
T-Flag cleared |
r16-19 (A): New position (1-based) |
|
T-Flag Set |
|
|
page -598-
© MCS Electronics, 1995-2007
Output from all kind of usage: r25: Error Code
C-Flag on Error
Example
'for the binary file demo we need some variables of different types Dim B AsByte, W AsWord, L AsLong, Sn AsSingle, Ltemp AsLong Dim Stxt AsString* 10
B = 1 : W = 50000 : L = 12345678 : Sn = 123.45 : Stxt ="test"
'open the file in BINARY mode Open"test.biN"ForBinaryAs#2 Put#2 , B ' write a byte Put#2 , W ' write a word Put#2 , L ' write a long
Ltemp =Loc(#2)+ 1 ' get the position of the next byte Print Ltemp ;" LOC"' store the location of the file pointer Print Seek(#2);" = LOC+1"
PrintLof(#2);" length of file"
PrintFileattr(#2);" file mode"' should be 32 for binary
Put#2 , Sn ' write a single
Put#2 , Stxt ' write a string
Flush#2 ' flush to disk
Close#2
'now open the file again and write only the single Open"test.bin"ForBinaryAs#2
L = 1 'specify the file position
B =Seek(#2 , L)' reset is the same as using SEEK #2,L Get#2 , B ' get the byte
Get#2 , W ' get the word Get#2 , L ' get the long Get#2 , Sn ' get the single Get#2 , Stxt ' get the string Close#2
RAD2DEG
Action
Converts a value in radians to degrees.
Syntax
var = RAD2DEG( Source )
Remarks
Var |
A numeric variable that is assigned with the angle of variable |
|
source. |
Source |
The single or double variable to get the angle of. |
|
|
page -599-
