- •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
CONFIG PORT
Action
Sets the port or a port pin to the right data direction.
Syntax
CONFIG PORTx = state
CONFIG PINx.y = state
Remarks
state |
A numeric constant that can be INPUT or OUTPUT. |
|
INPUT will set the data direction register to input for port X. |
|
OUTPUT will set the data direction to output for port X. |
|
You can also use a number for state. &B0001111, wil set the upper |
|
nibble to input and the lower nibble to output. |
|
You can also set one port pin with the CONFIG PIN = state, |
|
statement. |
|
Again, you can use INPUT, OUTPUT or a number. In this case the |
|
number can be only zero or one. |
|
|
The best way to set the data direction for more than 1 pin, is to use the CONFIGPORT, statement and not multiple lines with CONFIG PIN statements.
Example
'----------------------------------------------------------------------------- |
|
------------ |
: port.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demo: PortB and PortD |
'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 A As Byte , Count As Byte |
|
'configure PORT D for input mode |
|
Config Portd = Input |
|
page -365-
© MCS Electronics, 1995-2007
'reading the PORT, will read the latch, that is the value 'you have written to the PORT.
'This is not the same as reading the logical values on the pins! 'When you want to know the logical state of the attached hardware, 'you MUST use the PIN register.
A = Pind
'a port or SFR can be treated as a byte A = A And Portd
Print A |
'print it |
|
Bitwait Pind.7 , Reset |
'wait until bit is |
|
low |
|
|
'We will use port B for output |
|
|
Config Portb = Output |
|
|
'assign value |
'set port B to 10 |
|
Portb = 10 |
||
Portb = Portb And 2 |
|
|
Set Portb.0 |
'set bit 0 of port |
|
B to 1 |
|
|
Incr Portb |
|
|
'Now a light show on the STK200 |
|
|
Count = 0 |
|
|
Do |
|
|
|
Incr Count |
|
|
Portb = 1 |
|
|
For A = 1 To 8 |
'rotate bits left |
|
Rotate Portb , Left |
|
|
Wait 1 |
|
|
Next |
|
|
'the following 2 lines do the same as the previous loop |
|
' |
'but there is no delay |
|
Portb = 1 |
|
|
' |
Rotate Portb , Left , 8 |
|
Loop Until Count = 10 |
|
|
Print "Ready" |
|
|
'Again, note that the AVR port pins have a data direction register 'when you want to use a pin as an input it must be set low first 'you can do this by writing zeros to the DDRx:
'DDRB =&B11110000 'this will set portb1.0,portb.1,portb.2 and portb.3 to use as inputs.
'So : when you want to use a pin as an input set it low first in the DDRx!
'and read with PINx
'and when you want to use the pin as output, write a 1 first
'and write the value to PORTx
End
CONFIG PRINT
Action
Configure the UART to be used for RS-485
page -366-
© MCS Electronics, 1995-2007
Syntax
CONFIG PRINT0 = pin
CONFIG PRINT1 = pin
Remarks
pin |
The name of the PORT pin that is used to control the |
|
direction of an RS-485 driver. |
mode |
SET or RESET |
|
|
Use PRINT or PRINT0 for the first serial port. Use PRINT1 for the second serial port.
When you use RS-485 half duplex communication you need a pin for the direction of the data. The CONFIG PRINT automates the manual setting/resetting. It will either SET or RESET the logic level of the specified pin before data is printed with the BASCOM print routines. After the data is sent, it will inverse the pin so it goes into receive mode.
You need to set the direction of the used pin to outputmode yourself.
See also
CONFIG PRINTBIN
Example
'------------------------------------------------------------------------------
'name |
:rs485.bas |
|
'copyright |
: (c) 1995-2006, MCS Electronics |
|
'purpose |
: demonstrates |
|
'micro |
:Mega48 |
|
'suited for demo |
: yes |
: no |
'commercial addon needed |
||
'------------------------------------------------------------------------------ |
|
' we use the M48 |
$regfile= "m48def.dat" |
||
$crystal= 8000000 |
|
|
$baud = 19200 |
|
|
$hwstack= 32 |
|
|
$swstack= 32 |
|
|
$framesize = 32 |
|
|
Config Print0= Portb.0 ,Mode = Set |
||
Config Pinb.0 = Output |
'set the direction yourself |
|
Dim Resp As String* 10 |
|
|
Do |
|
|
Print"test message" |
' get response |
|
Input Resp |
|
|
Loop |
|
|
CONFIG PRINTBIN
page -367-
© MCS Electronics, 1995-2007
Action
Configure PRINTBIN behavior
Syntax
CONFIG PRINTBIN = extended
Remarks
extended |
This mode is the only mode. It allows to send huge |
|
arrays(more then 255 elements) to the serial port. |
|
Without the CONFIG PRINTBIN option, the maximum |
|
number of elements is 255. Because support for big |
|
arrays cost more code, it is made optional. |
|
|
See also
CONFIG PRINT
Example
$regfile = "m103def.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 |
|
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Printbin = Extended
Dim A(1000)
Printbin A(1) ; 1000
CONFIG PS2EMU
Action
Configures the PS2 mouse data and clock pins.
Syntax
CONFIG PS2EMU= int , DATA = data, CLOCK=clock
Remarks
Int |
The interrupt used such as INT0 or INT1. |
page -368-
|
|
|
|
© MCS Electronics, 1995-2007 |
||
|
|
|
|
|
|
|
DATA |
The pin that is connected to the DATA line. This must be the same pin as |
|
||||
|
the used interrupt. |
|
|
|
||
CLOCK |
The pin that is connected to the CLOCK line. |
|
||||
|
|
|
|
|
||
|
|
|
5-pin DIN |
|
|
|
|
|
|
(AT/XT): |
|
||
|
|
|
1 |
- Clock |
|
|
|
|
|
2 |
- Data |
|
|
|
|
|
3 |
- Not |
|
|
|
|
|
Implemented |
|
||
|
|
|
4 |
- Ground |
|
|
|
|
|
5 |
- +5v |
|
|
|
|
|
|
|
|
|
6-pin Mini-DIN (PS/2):
1 - Data
2 - Not Implemented 3 - Ground 4 - +5v
5 - Clock
6 - Not Implemented
Old PC’s are equipped with a 5-pin DIN female connector. Newer PC’s have a 6-pin mini DIN female connector.
The male sockets must be used for the connection with the micro.
Besides the DATA and CLOCK you need to connect fromthe PC to the micro, you need to connect ground. You can use the +5V from the PC to power your microprocessor.
The config statement will setup an ISR that is triggered when the INT pin goes low. This routine you can find in the library.
The ISR will retrieve a byte from the PC and will send the proper commands back to the PC.
The SENDSCAN and PS2MOUSEXY statements allow you to send mouse commands.
Note that the mouse emulator is only recognized after you have booted your PC. Mouse devices can not be plugged into your PC once it has booted. Inserting a mouse or mouse device when the PC is already booted, may damage your PC.
See also
SENDSCAN, PS2MOUSEXY
Example
'----------------------------------------------------------------------------- |
|
------------ |
: ps2_emul.bas |
'name |
page -369-
|
© MCS Electronics, 1995-2007 |
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: PS2 Mouse emulator |
'micro |
: 90S2313 |
'suited for demo |
: NO, commercial addon needed |
'commercial addon needed |
: yes |
'-----------------------------------------------------------------------------
------------
$regfile = "2313def.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 |
|
$lib "mcsbyteint.lbx" |
' use optional lib |
since we use only bytes |
|
'configure PS2 pins
Config Ps2emu = Int1 , Data = Pind.3 , Clock = Pinb.0
' |
^------------------------ |
used interrupt |
' |
^----------- |
pin connected to DATA |
' |
^-- |
pin connected to clock |
'Note that the DATA must be connected to the used interrupt pin
Waitms 500 |
|
' optional delay |
Enable Interrupts |
|
' you need to turn |
on interrupts yourself since an INT is used |
|
|
Print "Press u,d,l,r,b, or t" |
|
|
Dim Key As Byte |
|
|
Do |
|
' get key from |
Key = Waitkey() |
|
|
terminal |
|
|
Select Case Key |
0 , 10 , 0 |
' up |
Case "u" : Ps2mousexy |
||
Case "d" : Ps2mousexy |
0 , -10 , 0 |
' down |
Case "l" : Ps2mousexy -10 , 0 , 0 |
' left |
|
Case "r" : Ps2mousexy |
10 , 0 , 0 |
' right |
Case "b" : Ps2mousexy |
0 , 0 , 1 |
' left button |
pressed |
0 , 0 , 0 |
' left button |
Ps2mousexy |
||
released |
|
' send a scan code |
Case "t" : Sendscan Mouseup |
||
Case Else |
|
|
End Select |
|
|
Loop |
|
|
Mouseup: |
|
' mouse up by 1 |
Data 3 , &H08 , &H00 , &H01 |
|
|
unit |
|
|
CONFIG RC5
page -370-
