- •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
Input |
Z: SRAM-Address of buffer |
X: Address of Long-variable with |
|
*) |
sectornumber |
Output |
r25: Errorcode |
C-Flag: Set on Error |
This is not the address of wSRAMPointer, it is its content, which is the starting-address of the buffer.
Partial Example
Dim bError as Byte
Dim aBuffer(512)as Byte' Hold Sector to and from CF-Card
Dim wSRAMPointer as Word' Address-Pointer for write
Dim lSectorNumber as Long' Sector Number
'give Address of first Byte of the 512 Byte Buffer to Word-Variable wSRAMPointer =VarPtr(aBuffer(1))
'Set Sectornumber, sector 32 normally holds the Boot record sector of first partition lSectorNumber = 32
'Now read in sector 32 from CF-Card
bError = DriveReadSector( wSRAMPointer , lSectorNumber) ' Now Sector number 32 is in Byte-Array bBuffer
DriveWriteSector
Action
Write a Sector (512 Bytes) to the (Compact Flashcard-) Drive
Syntax
bErrorCode = DRIVEWRITESECTOR(wSRAMPointer, lSectorNumber)
Remarks
bErrorCode |
A Byte Variable, which is assigned with the error code of the function |
wSRAMPointer A Word Variable, which contains the SRAM address (pointer), from which the Sector to the Drive should be written
lSectorNumbe A Long Variable, which give the sector number on the drive to transfer. r
Writes a Sector (512 Bytes) from SRAM starting at the address, to which the content of the variable wSRAMPointer is pointing to the Drive to sector number lSectornumber. The functions returns 0 if no error occurred. For Error code see section Error codes.
For the meaning of wSRAMPointer see Note in DriveReadSector
See also
DriveCheck, DriveReset , DriveInit , DriveGetIdentity , DriveReadSector
page -471-
© MCS Electronics, 1995-2007
ASM
Calls |
_DriveWriteSector |
|
Input |
Z: SRAM-Address of buffer |
X: Address of Long-variable with |
|
*) |
sectornumber |
Output |
r25: Errorcode |
C-Flag: Set on Error |
|
|
|
This is not the address of wSRAMPointer, it is its content, which is the starting-address of the buffer.
Partial Example
Dim bError as Byte
Dim aBuffer(512) as Byte' Hold Sector to and from CF-Card
Dim wSRAMPointer as Word' Address-Pointer for read
Dim lSectorNumber as Long' Sector Number
'give Address of first Byte of the 512 Byte Buffer to Word-Variable wSRAMPointer =VarPtr(aBuffer(1))
'Set Sectornumber
lSectorNumber = 3
' Now Write in sector 3 from CF-Card
bError = DriveWriteSector( wSRAMPointer , lSectorNumber)
DTMFOUT
Action
Sends a DTMF tone to the compare1 output pin of timer 1.
Syntax
DTMFOUT number, duration
DTMFOUT string , duration
Remarks
Number |
A variable or numeric constant that is equivalent with the number of your |
|
phone keypad. |
Duration |
Time in mS the tone will be generated. |
string |
A string variable that holds the digits to be dialed. |
|
|
The DTMFOUT statement is based on an Atmel application note (314).
It uses TIMER1 to generate the dual tones. As a consequence, timer1 can not be used in interrupt mode by your application. You may use it for other tasks.
page -472-
© MCS Electronics, 1995-2007
Since the TIMER1 is used in interrupt mode you must enable global interrupts with the statement ENABLE INTERRUPTS. The compiler could do this automatic but when you use other interrupts as well it makes more sense that you enable them at the point where you want them to be enabled.
The working range is from 4 MHz to 10 MHz system clock(xtal).
The DTMF output is available on the TIMER1 OCA1 pin. For a 2313 this is PORTB.3.
Take precautions when connecting the output to your telephone line.
Ring voltage can be dangerous!
System Resources used
TIMER1 in interrupt mode
See also
NONE
ASM
The following routine is called from mcs.lib : _DTMFOUT
R16 holds the number of the tone to generate, R24-R25 hold the duration time in mS. Uses R9,R10,R16-R23
The DTMF table is remarked in the source and shown for completeness, it is generated by the compiler however with taking the used crystal in consideration.
Example
'----------------------------------------------------------------------------- |
|
------------ |
: dtmfout.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstrates DTMFOUT statement based on AN 314 |
from Atmel |
: Mega48 |
'micro |
|
'suited for demo |
: yes |
'commercial addon needed |
: no |
'----------------------------------------------------------------------------- |
|
------------ |
|
$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 = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
|
page -473- |
© MCS Electronics, 1995-2007
'since the DTMFOUT statement uses the TIMER1 interrupt you must enable 'global interrupts
'This is not done by the compiler in case you have more ISRs
Enable Interrupts
'the first sample does dtmfout in a loop
Dim Btmp As Byte , Sdtmf As String * 10
Sdtmf = "12345678" |
|
' number to dial |
Do |
|
|
Dtmfout Sdtmf , 50 |
' lets dial a |
|
number |
^ duration is 50 mS for each digit |
|
' |
' wait for one |
|
Waitms 1000 |
|
|
second |
|
|
'As an alternative you can send single digits
'there are 16 dtmf tones
For Btmp = 0 To 15 |
' dtmf out on |
||||
|
Dtmfout Btmp , 50 |
||||
PORTB.3 for the 2313 |
for 500 mS |
||||
|
'output is on the OC1A output pin |
||||
|
Waitms 500 |
|
' wait 500 msec |
||
Next |
|
|
|
|
|
Loop |
|
|
|
|
|
End |
|
|
|
|
|
'the keypad of most phones looks like this : |
|||||
'1 |
2 |
3 |
optional are A |
||
'4 |
5 |
6 |
|
|
B |
'7 |
8 |
9 |
|
|
C |
'* |
0 |
# |
|
|
D |
'the DTMFOUT translates a numeric value from 0-15 into : |
|||||
' numeric value |
phone key |
||||
' |
0 |
|
|
|
0 |
' |
1 |
|
|
|
1 |
' |
2 |
|
|
|
2 |
' |
3 |
|
|
|
3 |
' etc. |
|
|
|
9 |
|
' |
9 |
|
|
|
|
' |
10 |
|
|
|
* |
' |
11 |
|
|
|
# |
' |
12 |
|
|
|
A |
' |
13 |
|
|
|
B |
' |
14 |
|
|
|
C |
' |
15 |
|
|
|
D |
ECHO
Action
Turns the ECHO on or off while asking for serial INPUT.
Syntax
page -474-
© MCS Electronics, 1995-2007
ECHO value
Remarks
Value |
ON to enable ECHO and OFF to disable ECHO. |
|
|
When you use INPUT to retrieve values for variables, all info you type can be echoed back. In this case you will see each character you enter. When ECHO is OFF, you will not see the characters you enter.
In versions 1.11.6.2 and earlier the ECHO options were controlled by an additional parameter on the INPUT statement line like : INPUT "Hello " , var NOECHO
This would suppress the ECHO of the typed data. The new syntax works by setting ECHO ON and OFF. For backwards compatibility, using NOECHO on the INPUT statement line will also work. In effect it will turn echo off and on automatic.
By default, ECHO is always ON.
See also
INPUT
ASM
The called routines from mcs.lib are _ECHO_ON and _ECHO_OFF
The following ASM is generated when you turn ECHO OFF.
Rcall Echo_Off
This will set bit 3 in R6 that holds the ECHO state.
When you turn the echo ON the following code will be generated
Rcall Echo_On
Example
'----------------------------------------------------------------------------- |
|
------------ |
: input.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demo: INPUT, INPUTHEX |
'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 |
page -475-
