
- •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 |
--- |
' we use the M163 |
$regfile = "m163def.dat" |
|
$crystal = 4000000 |
|
$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 |
|
'configure single mode and auto prescaler setting
'The single mode must be used with the GETADC() function
'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128 'Because the ADC needs a clock from 50-200 KHz
'The AUTO feature, will select the highest clockrate possible Config Adc = Single , Prescaler = Auto
'Now give power to the chip
Start Adc
'With STOP ADC, you can remove the power from the chip 'Stop Adc
Dim W As Word , Channel As Byte
Channel = 0
'now read A/D value from channel 0
Do
W = Getadc(channel)
Print "Channel " ; Channel ; " value " ; W Incr Channel
If Channel > 7 Then Channel = 0
Loop
End
'The new M163 has options for the reference voltage 'For this chip you can use the additional param :
'Config Adc = Single , Prescaler = Auto, Reference = Internal 'The reference param may be :
'OFF |
: |
AREF, |
internal reference turned off |
'AVCC |
: |
AVCC, |
with external capacitor at AREF pin |
'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF pin
'Using the additional param on chip that do not have the internal reference will have no effect.
CONFIG ATEMU
Action
Configures the PS/2 keyboard data and clock pins.
Syntax
CONFIG ATEMU = int , DATA = data, CLOCK=clock
page -316-

|
|
|
|
|
© MCS Electronics, 1995-2007 |
|||
Remarks |
|
|
|
|
|
|||
Int |
The interrupt used such as INT0 or INT1. |
|
||||||
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. |
|
||||||
|
|
|
|
|
|
|
|
|
Male |
|
Female |
5-pin DIN |
|
|
|
||
|
|
|
|
(AT/XT): |
|
|
||
|
|
|
|
1 - Clock |
|
|
||
|
|
|
|
2 - Data |
|
|
||
|
|
|
|
3 - Not |
|
|
||
(Plug) |
|
(Socket) |
Implemented |
|
|
|||
|
4 - Ground |
|
|
|
||||
|
|
|
|
|
|
|||
|
|
|
|
5 - +5v |
|
|
||
|
|
|
|
|
|
|
|
|
Male |
|
|
Female |
|
6-pin Mini-DIN |
|
|
|
|
|
|
|
|
(PS/2): |
|
||
|
|
|
|
|
1 - Data |
|
||
|
|
|
|
|
2 - Not |
|
||
|
|
|
|
|
Implemented |
|
||
(Plug) |
|
|
(Socket) |
|
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 SENDSCANKBD statement allows you to send keyboard commands.
Note that unlike the mouse emulator, the keyboard emulator is also recognized after your PC has booted.
The PS2 Keyboard and mouse emulator needs an additonal commercial addon library.
See also
page -317-

© MCS Electronics, 1995-2007
SENDSCANKBD
Example
'----------------------------------------------------------------------------- |
|
------------ |
: ps2_kbdemul.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: PS2 AT Keyboard emulator |
'micro |
: 90S2313 |
'suited for demo |
: no, ADD ONE 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 AT pins |
' you need to turn |
|
Enable Interrupts |
|
|
on interrupts yourself since an INT is used |
|
|
Config Atemu = 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 |
'rcall _AT_KBD_INIT
Print "Press t for test, and set focus to the editor window"
Dim Key2 As Byte , Key As Byte |
|
Do |
' get key from |
Key2 = Waitkey() |
|
terminal |
|
Select Case Key2 |
|
Case "t" : |
|
Waitms 1500 |
' send a scan code |
Sendscankbd Mark |
|
Case Else |
|
End Select |
|
Loop |
|
Print Hex(key) |
|
Mark: |
' send mark |
Data 12 , &H3A , &HF0 , &H3A , &H1C , &HF0 , &H1C , &H2D , &HF0 , &H2D , &H42
, &HF0 , &H42
'^ send 12 bytes
' |
m |
a |
r |
k |
page -318-

© MCS Electronics, 1995-2007
CONFIG BCCARD
Action
Initializes the pins that are connected to the BasicCard.
Syntax
CONFIG BCCARD = port , IO=pin, RESET=pin
Remarks
Port |
The PORT of the micro that is connected to the BasicCard. This can |
|
be B or D for most micro’s. (PORTB and PORTD) |
IO |
The pin number that is connected to the IO of the BasicCard. Must |
|
be in the range from 0-7 |
RESET |
The pin number that is connected to the RESET of the BasicCard. |
|
Must be in the range from 0-7 |
|
|
The variables SW1, SW2 and _BC_PCB are automatically dimensioned by the CONFIG BCCARD statement.
This statements uses BCCARD.LIB, a library that is available separately fromMCS Electronics.
See Also
BCRESET , BCDEF , BCCALL
Example
'----------------------------------------------------------------------------- |
|
- |
BCCARD.BAS |
' |
' This AN shows how to use the BasicCard from Zeitcontrol
' |
www.basiccard.com |
'----------------------------------------------------------------------------- |
|
- |
|
'connections: |
|
'C1 = +5V
'C2 = PORTD.4 - RESET
' C3 = PIN 4 - CLOCK
'C5 = GND
'C7 = PORTD.5 - I/O
' |
/-------------------------------- |
|
|
\ |
' |
| |
C1 |
C5 |
| |
' |
| |
| |
||
' |
| |
C2 |
C6 |
| |
' |
| |
C3 |
C7 |
| |
' |
| |
C4 |
C8 |
| |
' |
| |
|
|
| |
' |
\-------------------------------- |
|
|
/ |
' |
|
|
|
|
page -319-
|
|
© MCS Electronics, 1995-2007 |
' |
|
|
'----------- |
configure the pins we use ------------ |
|
Config Bccard = D , Io = 5 , Reset = 4 |
||
' |
^ |
^ PORTD.4 |
' |
PORTD.5 |
|
' |
^--------------------- |
PORT D |
'Load the sample calc.bas into the basiccard
'Now define the procedure in BASCOM
'We pass a string and also receive a string
Bcdef Calc(string)
'We need to dim the following variables 'SW1 and SW2 are returned by the BasicCard
'BC_PCB must be set to 0 before you start a session
'Our program uses a string to pass the data so DIM it
Dim S As String * 15
'Baudrate might be changed $baud = 9600
' Crystal used must be 3579545 since it is connected to the Card too $crystal = 3579545
'Perform an ATR
Bcreset
'Now we call the procedure in the BasicCard
'bccall funcname(nad,cla,ins,p1,p2,PRM as TYPE,PRM as TYPE)
S = "1+1+3" ' we want to calculate the result of this expression
Bccall Calc(0 , &H20 , 1 , 0 , 0 , S) |
variable to pass that holds the |
|
' |
^--- |
|
expression |
^ |
P2 |
' |
||
' |
^----------- |
P1 |
' |
^--------------- |
INS |
' |
^-------------------- |
CLA |
'^-------------------------- NAD
'For info about NAD, CLA, INS, P1 and P2 see your BasicCard manual 'if an error occurs ERR is set
' The BCCALL returns also the variables SW1 and SW2 Print "Result of calc : " ; S
Print "SW1 = " ; Hex(sw1)
Print "SW2 = " ; Hex(sw2)
'Print Hex(_bc_pcb) ' for test you can see that it toggles between 0 and 40 Print "Error : " ; Err
'You can call this or another function again in this session
S = "2+2"
Bccall Calc(0 , &H20 , 1 , 0 , 0 , S) Print "Result of calc : " ; S
Print "SW1 = " ; Hex(sw1)
Print "SW2 = " ; Hex(sw2)
'Print Hex(_bc_pcb) ' for test you can see that it toggles between 0 and 40 Print "Error : " ; Err
page -320-