Manual Bascom AVR
Manual Bascom AVR
, 1995-2021
BASCOM-AVR user manual
Introduction
by MCS Electronics
Dear reader.
BASCOM was "invented" in 1995. It was intended for personal usage only. I
decided to make it public as I found no other tool that was so simple to use.
Since that time, a lot of options and extensions were added. Without the help
and patience of the many users, BASCOM would not be what it is today :
"the best and most affordable tool for fast proto typing".
Please notice that the samples in the manual are intended as simple
samples. You should have a look at the sample code provided in the
SAMPLES directory.
All rights reserved. No parts of this work may be reproduced in any form or by any means - graphic, electronic, or
mechanical, including photocopying, recording, taping, or information storage and retrieval systems - without the
written permission of the publisher.
Products that are referred to in this document may be either trademarks and/or registered trademarks of the
respective owners. The publisher and the author make no claim to these trademarks.
While every precaution has been taken in the preparation of this document, the publisher and the author assume no
responsibility for errors or omissions, or for damages resulting from the use of information contained in this document
or from the use of programs and source code that may accompany it. In no event shall the publisher and the author be
liable for any loss of profit or any other commercial damage caused or alleged to have been caused directly or
indirectly by this document.
Printed: 21-4-2021
Cover Designer Luciano, Ian, Adrian and Kimmi, they are very active on
the user forum. They take the time to give other forum
B.F.de Graaff members free help and advise. They do this for free just to
help other BASCOM users.
Peter Maroudas, RIP, for his work on the FT800 and FT801
implementation.
Table of Contents
Foreword 0
Part I Index 27
1 Keyword...................................................................................................................................
Reference 28
2 Changes................................................................................................................................... 32
What is new
.........................................................................................................................................................
in 2084 32
What is new
.........................................................................................................................................................
in 2083 33
What is new
.........................................................................................................................................................
in 2082 35
What is new
.........................................................................................................................................................
in 2081 36
What is new
.........................................................................................................................................................
in 2080 37
What is new
.........................................................................................................................................................
in 2078-2079 38
3 About MCS
...................................................................................................................................
Electronics 42
Custom Designs
......................................................................................................................................................... 44
Application
.........................................................................................................................................................
Notes 45
About this.........................................................................................................................................................
Help 45
Part II Installation 47
1 Installation
...................................................................................................................................
of BASCOM 47
2 Updates ................................................................................................................................... 55
3 Move to new
...................................................................................................................................
PC 60
4 Installation
...................................................................................................................................
on multiple computers 61
5 Registration
................................................................................................................................... 61
19 Edit Replace
................................................................................................................................... 78
20 Edit Goto................................................................................................................................... 79
21 Edit Toggle
...................................................................................................................................
Bookmark 79
22 Edit Goto...................................................................................................................................
Bookmark 79
23 Edit Indent
...................................................................................................................................
Block 79
24 Edit Unindent
...................................................................................................................................
Block 79
25 Edit Remark
...................................................................................................................................
Block 79
26 Edit Insert
...................................................................................................................................
ASCII 80
27 Edit Fold...................................................................................................................................
All Subs and Functions 80
28 Edit Unfold
...................................................................................................................................
All Code 81
29 Edit Encrypt
...................................................................................................................................
Selected Code 81
30 Edit Proper
...................................................................................................................................
Indent 82
31 Edit Show
...................................................................................................................................
Excluded Code 83
32 Edit Show
...................................................................................................................................
Dead Code 84
33 View PinOut
................................................................................................................................... 86
34 View PDF...................................................................................................................................
viewer 90
35 View Error
...................................................................................................................................
Panel 92
36 View Tip ................................................................................................................................... 92
37 View Project
...................................................................................................................................
Files 93
38 View Code
...................................................................................................................................
Explorer 93
39 View Vertical
...................................................................................................................................
Splitter 99
40 Program...................................................................................................................................
Compile 100
41 Program...................................................................................................................................
Syntax Check 101
42 Program...................................................................................................................................
Show Result 102
43 Program...................................................................................................................................
Simulate 103
44 Program...................................................................................................................................
Send to Chip 116
45 Tools Terminal
...................................................................................................................................
Emulator 120
46 Tools LCD
...................................................................................................................................
Designer 122
47 Tools LIB
...................................................................................................................................
Manager 124
48 Tools Graphic
...................................................................................................................................
Converter 125
49 Tools Stack
...................................................................................................................................
Analyzer 126
50 Tools Plugin
...................................................................................................................................
Manager 126
51 Tools Batch
...................................................................................................................................
Compile 127
52 Tools PDF
...................................................................................................................................
Update 130
53 Tools Resource
...................................................................................................................................
Editor 132
54 Tools Font
...................................................................................................................................
Editor 133
55 Options...................................................................................................................................
Compiler 135
Options .........................................................................................................................................................
Compiler Chip 135
Options .........................................................................................................................................................
Compiler Output 137
Options .........................................................................................................................................................
Compiler Communication 138
Options .........................................................................................................................................................
Compiler I2C, SPI, 1WIRE 139
Options .........................................................................................................................................................
Compiler LCD 140
56 Options...................................................................................................................................
Communication 141
57 Options...................................................................................................................................
Environment 142
58 Options...................................................................................................................................
Simulator 151
59 Options...................................................................................................................................
Programmer 152
Supported
.........................................................................................................................................................
Programmers 154
ISP programmer
.................................................................................................................................................. 155
PG302 programmer
.................................................................................................................................................. 156
Sample ..................................................................................................................................................
Electronics cable programmer 156
KITSRUS ..................................................................................................................................................
Programmer 157
MCS Universal
..................................................................................................................................................
Interface Programmer 158
STK500..................................................................................................................................................
Programmer 160
Lawicel ..................................................................................................................................................
BootLoader 164
AVR ISP..................................................................................................................................................
Programmer 164
USB-ISP..................................................................................................................................................
Programmer 165
MCS Bootloader
.................................................................................................................................................. 174
PROGGY .................................................................................................................................................. 176
FLIP .................................................................................................................................................. 177
USBprog ..................................................................................................................................................
Programmer / AVR ISP mkII 180
KamProg ..................................................................................................................................................
for AVR 180
USBASP .................................................................................................................................................. 183
STK600.................................................................................................................................................. 184
ARDUINO .................................................................................................................................................. 187
BIPOM MINI-MAX/C
.................................................................................................................................................. 190
mySmartUSB..................................................................................................................................................
Light 190
UPDI Programmer
.................................................................................................................................................. 192
LIBUSB ......................................................................................................................................................... 195
60 Options...................................................................................................................................
Monitor 204
61 Options...................................................................................................................................
Printer 204
62 Options...................................................................................................................................
Select Settings File 205
63 Window...................................................................................................................................
Cascade 206
64 Window...................................................................................................................................
Tile 207
65 Window...................................................................................................................................
Tile Vertically 208
66 Window...................................................................................................................................
Arrange Icons 208
67 Windows
...................................................................................................................................
Maximize All 208
68 Window...................................................................................................................................
Minimize All 208
69 Help About
................................................................................................................................... 209
70 Help Index
................................................................................................................................... 210
71 Help MCS
...................................................................................................................................
Forum 210
72 Help MCS
...................................................................................................................................
Shop 211
73 Help Support
................................................................................................................................... 212
74 Help Knowledge
...................................................................................................................................
Base 212
75 Help Credits
................................................................................................................................... 213
76 Help Update
................................................................................................................................... 214
77 Help Wiki
................................................................................................................................... 216
78 BASCOM
...................................................................................................................................
Editor Keys 216
79 Program...................................................................................................................................
Development Order 217
80 PlugIns ................................................................................................................................... 217
Font Editor
......................................................................................................................................................... 217
1 Additional
...................................................................................................................................
Hardware 221
2 AVR Internal
...................................................................................................................................
Hardware 221
3 AVR Internal
...................................................................................................................................
Registers 222
4 AVR Internal
...................................................................................................................................
Hardware TIMER0 224
5 AVR Internal
...................................................................................................................................
Hardware TIMER1 225
6 AVR Internal
...................................................................................................................................
Hardware Watchdog timer 227
7 AVR Internal
...................................................................................................................................
Hardware Port B 227
8 AVR Internal
...................................................................................................................................
Hardware Port D 229
9 Adding ...................................................................................................................................
XRAM with External Memory Interface 230
10 Adding ...................................................................................................................................
XRAM to XMEGA using EBI 234
11 Adding ...................................................................................................................................
SRAM 4-port Non Multiplexed 236
12 Attaching
...................................................................................................................................
an LCD Display 245
13 Memory...................................................................................................................................
usage 246
14 Statements
...................................................................................................................................
and Hardware Resources 257
15 Using the
...................................................................................................................................
UART 257
16 USING RS485
................................................................................................................................... 264
17 Using the
...................................................................................................................................
I2C protocol 266
18 Using the
...................................................................................................................................
1 WIRE protocol 278
19 Using the
...................................................................................................................................
SPI protocol 282
20 Using USI
...................................................................................................................................
(Universal Serial Interface) 289
21 Power Up
................................................................................................................................... 293
22 Reference
...................................................................................................................................
Designs 294
EM4095 .........................................................................................................................................................
RFID Reader 294
ATTINY12
......................................................................................................................................................... 320
ATTINY13
......................................................................................................................................................... 321
ATTINY13A
......................................................................................................................................................... 321
ATTINY15
......................................................................................................................................................... 321
ATTINY20
......................................................................................................................................................... 321
ATTINY22
......................................................................................................................................................... 322
ATTINY24
......................................................................................................................................................... 322
ATTINY25
......................................................................................................................................................... 323
ATTINY26
......................................................................................................................................................... 323
ATTINY43U
......................................................................................................................................................... 324
ATTINY44
......................................................................................................................................................... 324
ATTINY45
......................................................................................................................................................... 324
ATTINY48
......................................................................................................................................................... 325
ATTINY84
......................................................................................................................................................... 326
ATTINY85
......................................................................................................................................................... 326
ATTINY87
......................................................................................................................................................... 326
ATTINY88
......................................................................................................................................................... 327
ATTINY167
......................................................................................................................................................... 327
ATTINY261
......................................................................................................................................................... 328
ATTINY441
......................................................................................................................................................... 328
ATTINY461
......................................................................................................................................................... 329
ATTINY828
......................................................................................................................................................... 329
ATTINY841
......................................................................................................................................................... 330
ATTINY861
......................................................................................................................................................... 331
ATTINY1634
......................................................................................................................................................... 331
ATTINY2313
......................................................................................................................................................... 331
ATTINY2313A
......................................................................................................................................................... 332
ATTINY4313
......................................................................................................................................................... 333
ATTINY4313A
......................................................................................................................................................... 333
5 ATMEGA
................................................................................................................................... 334
ATMEGA8
......................................................................................................................................................... 334
ATMEGA8A
......................................................................................................................................................... 334
ATMEGA8U2
......................................................................................................................................................... 334
ATMEGA16
......................................................................................................................................................... 336
ATMEGA16A
......................................................................................................................................................... 337
ATMEGA16U2
......................................................................................................................................................... 337
ATMEGA16U4
......................................................................................................................................................... 339
ATMEGA16M1
......................................................................................................................................................... 340
ATMEGA32
......................................................................................................................................................... 341
ATMEGA32A
......................................................................................................................................................... 342
ATMEGA32C1
......................................................................................................................................................... 343
ATMEGA32M1
......................................................................................................................................................... 344
ATMEGA32U2
......................................................................................................................................................... 344
ATMEGA32U4
......................................................................................................................................................... 346
ATMEGA48
......................................................................................................................................................... 347
ATMEGA48P-ATMEGA48PA
......................................................................................................................................................... 347
ATMEGA48PB
......................................................................................................................................................... 348
ATMEGA64
......................................................................................................................................................... 349
ATMEGA64C1
......................................................................................................................................................... 350
ATMEGA64M1
......................................................................................................................................................... 351
ATMEGA88
......................................................................................................................................................... 351
ATMEGA88A
......................................................................................................................................................... 352
ATMEGA88P-ATMEGA88PA
......................................................................................................................................................... 353
ATMEGA88PB
......................................................................................................................................................... 354
ATMEGA103
......................................................................................................................................................... 354
ATMEGA128
......................................................................................................................................................... 356
ATMEGA128RFA1
......................................................................................................................................................... 357
ATMEGA161
......................................................................................................................................................... 358
ATMEGA162
......................................................................................................................................................... 358
ATMEGA163
......................................................................................................................................................... 359
ATMEGA164P
......................................................................................................................................................... 360
ATMEGA164PA
......................................................................................................................................................... 360
ATMEGA165
......................................................................................................................................................... 362
ATMEGA165A
......................................................................................................................................................... 362
ATMEGA168
......................................................................................................................................................... 364
ATMEGA168P
......................................................................................................................................................... 364
ATMEGA168PB
......................................................................................................................................................... 365
ATMEGA169
......................................................................................................................................................... 365
ATMEGA169P
......................................................................................................................................................... 366
ATMEGA169PA
......................................................................................................................................................... 367
ATMEGA323
......................................................................................................................................................... 368
ATMEGA324A
......................................................................................................................................................... 369
ATMEGA324P
......................................................................................................................................................... 370
ATMEGA324PA
......................................................................................................................................................... 370
ATMEGA324PB
......................................................................................................................................................... 371
ATMEGA325
......................................................................................................................................................... 372
ATMEGA328
......................................................................................................................................................... 373
ATMEGA328P
......................................................................................................................................................... 373
ATMEGA328PB
......................................................................................................................................................... 374
ATMEGA329
......................................................................................................................................................... 375
ATMEGA406
......................................................................................................................................................... 375
ATMEGA603
......................................................................................................................................................... 376
ATMEGA640
......................................................................................................................................................... 378
ATMEGA644
......................................................................................................................................................... 379
ATMEGA644P
......................................................................................................................................................... 379
ATMEGA644PA
......................................................................................................................................................... 380
ATMEGA645
......................................................................................................................................................... 381
ATMEGA649
......................................................................................................................................................... 382
ATMEGA649PA
......................................................................................................................................................... 382
ATMEGA1280
......................................................................................................................................................... 384
ATMEGA1281
......................................................................................................................................................... 385
ATMEGA1284
......................................................................................................................................................... 386
ATMEGA1284P
......................................................................................................................................................... 386
ATMEGA2560
......................................................................................................................................................... 388
ATMEGA2561
......................................................................................................................................................... 389
ATMEGA3250P
......................................................................................................................................................... 390
ATMEGA6450P
......................................................................................................................................................... 391
ATMEGA8515
......................................................................................................................................................... 392
ATMEGA8535
......................................................................................................................................................... 392
6 ATXMEGA
................................................................................................................................... 393
ATXMEGA
......................................................................................................................................................... 393
ATXMEGA8E5
......................................................................................................................................................... 401
ATXMEGA16A4
......................................................................................................................................................... 402
ATXMEGA16D4
......................................................................................................................................................... 403
ATXMEGA16E5
......................................................................................................................................................... 404
ATXMEGA32A4
......................................................................................................................................................... 405
ATXMEGA32A4U
......................................................................................................................................................... 407
ATXMEGA32D4
......................................................................................................................................................... 407
ATXMEGA32E5
......................................................................................................................................................... 408
ATXMEGA64A1
......................................................................................................................................................... 409
ATXMEGA64A3
......................................................................................................................................................... 411
ATXMEGA64D3
......................................................................................................................................................... 411
ATXMEGA64D4
......................................................................................................................................................... 412
ATXMEGA128A1
......................................................................................................................................................... 413
ATXMEGA128A3
......................................................................................................................................................... 415
ATXMEGA128A4U
......................................................................................................................................................... 416
ATXMEGA128B1
......................................................................................................................................................... 416
ATXMEGA128B3
......................................................................................................................................................... 418
ATXMEGA128C3
......................................................................................................................................................... 418
ATXMEGA128D3
......................................................................................................................................................... 419
ATXMEGA128D4
......................................................................................................................................................... 420
ATXMEGA192A3
......................................................................................................................................................... 421
ATXMEGA192D3
......................................................................................................................................................... 422
ATXMEGA256A3
......................................................................................................................................................... 423
ATXMEGA256A3B
......................................................................................................................................................... 424
ATXMEGA256A3BU
......................................................................................................................................................... 426
ATXMEGA256D3
......................................................................................................................................................... 426
ATXMEGA384C3
......................................................................................................................................................... 428
7 XTINY ................................................................................................................................... 428
XTINY ......................................................................................................................................................... 428
ATXTINY202
......................................................................................................................................................... 432
ATXTINY204
......................................................................................................................................................... 433
ATXTINY212
......................................................................................................................................................... 434
ATXTINY214
......................................................................................................................................................... 435
ATXTINY402
......................................................................................................................................................... 436
ATXTINY404
......................................................................................................................................................... 437
ATXTINY406
......................................................................................................................................................... 438
ATXTINY412
......................................................................................................................................................... 439
ATXTINY414
......................................................................................................................................................... 440
ATXTINY416
......................................................................................................................................................... 441
ATXTINY417
......................................................................................................................................................... 442
ATXTINY804
......................................................................................................................................................... 443
ATXTINY806
......................................................................................................................................................... 444
ATXTINY807
......................................................................................................................................................... 445
ATXTINY814
......................................................................................................................................................... 446
ATXTINY816
......................................................................................................................................................... 447
ATXTINY817
......................................................................................................................................................... 448
ATXTINY1604
......................................................................................................................................................... 449
ATXTINY1606
......................................................................................................................................................... 450
ATXTINY1607
......................................................................................................................................................... 451
ATXTINY1614
......................................................................................................................................................... 452
ATXTINY1616
......................................................................................................................................................... 453
ATXTINY1617
......................................................................................................................................................... 454
ATXTINY3216
......................................................................................................................................................... 455
ATXTINY3217
......................................................................................................................................................... 456
8 ATMEGAX
................................................................................................................................... 457
MEGAX ......................................................................................................................................................... 457
ATMEGAX4809
......................................................................................................................................................... 458
9 ASCII chart
................................................................................................................................... 505
$SERIALINPUT
......................................................................................................................................................... 602
$SERIALINPUT1
......................................................................................................................................................... 604
$SERIALINPUT2LCD
......................................................................................................................................................... 605
$SERIALOUTPUT
......................................................................................................................................................... 605
$SERIALOUTPUT1
......................................................................................................................................................... 606
$SIM ......................................................................................................................................................... 607
$STACKDUMP
......................................................................................................................................................... 607
$SWSTACK
......................................................................................................................................................... 609
$TIMEOUT
......................................................................................................................................................... 612
$TINY ......................................................................................................................................................... 614
$TYPECHECK
......................................................................................................................................................... 614
$VERSION
......................................................................................................................................................... 615
$WAITSTATE
......................................................................................................................................................... 616
$XA ......................................................................................................................................................... 616
$XRAMSIZE
......................................................................................................................................................... 617
$XRAMSTART
......................................................................................................................................................... 617
$XTEAKEY
......................................................................................................................................................... 618
4 1WIRE ................................................................................................................................... 619
1WIRECOUNT
......................................................................................................................................................... 619
1WRESET
......................................................................................................................................................... 622
1WREAD......................................................................................................................................................... 624
1WSEARCHFIRST
......................................................................................................................................................... 626
1WSEARCHNEXT
......................................................................................................................................................... 628
1WVERIFY
......................................................................................................................................................... 631
1WWRITE
......................................................................................................................................................... 633
5 ADR , ADR2
................................................................................................................................... 635
6 ALIAS ................................................................................................................................... 639
7 Math ................................................................................................................................... 640
ABS ......................................................................................................................................................... 640
ACOS ......................................................................................................................................................... 641
AND ......................................................................................................................................................... 642
ASIN ......................................................................................................................................................... 644
ATN ......................................................................................................................................................... 645
ATN2 ......................................................................................................................................................... 646
CHECKFLOAT
......................................................................................................................................................... 648
COS ......................................................................................................................................................... 649
COSH ......................................................................................................................................................... 650
DEG2RAD
......................................................................................................................................................... 651
EXP ......................................................................................................................................................... 652
FIX ......................................................................................................................................................... 653
FRAC ......................................................................................................................................................... 653
INT ......................................................................................................................................................... 654
LOG10 ......................................................................................................................................................... 655
LOG ......................................................................................................................................................... 656
NOT ......................................................................................................................................................... 656
OR ......................................................................................................................................................... 659
POWER ......................................................................................................................................................... 662
QSIN ......................................................................................................................................................... 663
QCOS ......................................................................................................................................................... 667
RAD2DEG
......................................................................................................................................................... 668
ROUND ......................................................................................................................................................... 668
SGN ......................................................................................................................................................... 669
TANH ......................................................................................................................................................... 670
TAN ......................................................................................................................................................... 671
SQR ......................................................................................................................................................... 671
SINH ......................................................................................................................................................... 672
FORMAT......................................................................................................................................................... 732
FUSING ......................................................................................................................................................... 734
GRAY2BIN
......................................................................................................................................................... 735
HEXVAL......................................................................................................................................................... 736
HEX ......................................................................................................................................................... 737
MANCHESTERDEC
......................................................................................................................................................... 738
MANCHESTERENC
......................................................................................................................................................... 739
STR ......................................................................................................................................................... 740
STR2DIGITS
......................................................................................................................................................... 741
VAL ......................................................................................................................................................... 743
16 CAN ................................................................................................................................... 744
CANBAUD
......................................................................................................................................................... 744
CANGETINTS
......................................................................................................................................................... 745
CANID ......................................................................................................................................................... 746
CANCLEARALLMOBS
......................................................................................................................................................... 746
CANCLEARMOB
......................................................................................................................................................... 747
CANRECEIVE
......................................................................................................................................................... 747
CANRESET
......................................................................................................................................................... 748
CANSELPAGE
......................................................................................................................................................... 748
CANSEND
......................................................................................................................................................... 749
17 CLEAR ................................................................................................................................... 750
18 CLOCKDIVISION
................................................................................................................................... 751
19 CLOSE ................................................................................................................................... 752
20 COMPARE
................................................................................................................................... 755
21 CONFIGURATION
................................................................................................................................... 756
CONFIG ......................................................................................................................................................... 757
CONFIG .........................................................................................................................................................
1WIRE 759
CONFIG .........................................................................................................................................................
ACI 764
CONFIG .........................................................................................................................................................
ACX 764
CONFIG .........................................................................................................................................................
ACAX|ACBX 765
CONFIG .........................................................................................................................................................
ADC 767
CONFIG .........................................................................................................................................................
ADCA|ADCB 769
CONFIG .........................................................................................................................................................
ADC0-ADCX 783
CONFIG .........................................................................................................................................................
ATEMU 786
CONFIG .........................................................................................................................................................
BASE 788
CONFIG .........................................................................................................................................................
BCCARD 789
CONFIG .........................................................................................................................................................
CANBUSMODE 792
CONFIG .........................................................................................................................................................
CANMOB 796
CONFIG .........................................................................................................................................................
CLOCK 798
CONFIG .........................................................................................................................................................
CLOCKDIV 812
CONFIG .........................................................................................................................................................
COM1 812
CONFIG .........................................................................................................................................................
COM2 814
CONFIG .........................................................................................................................................................
COMx 816
CONFIG .........................................................................................................................................................
DACA|DACB 819
CONFIG .........................................................................................................................................................
DACX 824
CONFIG .........................................................................................................................................................
DATE 826
CONFIG .........................................................................................................................................................
DCF77 828
CONFIG .........................................................................................................................................................
DEBOUNCE 835
CONFIG .........................................................................................................................................................
DMA 836
CONFIG .........................................................................................................................................................
DMACHx 837
CONFIG .........................................................................................................................................................
EDMA 843
CONFIG .........................................................................................................................................................
EDMAx 844
CONFIG .........................................................................................................................................................
DMXSLAVE 848
CONFIG .........................................................................................................................................................
DP 851
CONFIG .........................................................................................................................................................
EEPROM 851
CONFIG .........................................................................................................................................................
ERROR 852
CONFIG .........................................................................................................................................................
EVENT_SYSTEM 853
CONFIG .........................................................................................................................................................
EVENT_SYSTEM XTINY 856
CONFIG .........................................................................................................................................................
EXTENDED_PORT 858
CONFIG .........................................................................................................................................................
FT800 858
CONFIG .........................................................................................................................................................
GRAPHLCD 862
CONFIG .........................................................................................................................................................
HITAG 867
CONFIG .........................................................................................................................................................
I2CBUS 871
CONFIG .........................................................................................................................................................
I2CDELAY 872
CONFIG .........................................................................................................................................................
I2CSLAVE 875
CONFIG .........................................................................................................................................................
INPUT 880
CONFIG .........................................................................................................................................................
INPUTBIN 881
CONFIG .........................................................................................................................................................
INTx 882
CONFIG .........................................................................................................................................................
INTVECTORSELECTION 884
CONFIG .........................................................................................................................................................
KBD 885
CONFIG .........................................................................................................................................................
KEYBOARD 886
CONFIG .........................................................................................................................................................
LCD 889
CONFIG .........................................................................................................................................................
LCDBUS 895
CONFIG .........................................................................................................................................................
LCDMODE 898
CONFIG .........................................................................................................................................................
LCDPIN 898
CONFIG .........................................................................................................................................................
MODBUS 902
CONFIG .........................................................................................................................................................
OSC 902
CONFIG .........................................................................................................................................................
PORT 904
CONFIG .........................................................................................................................................................
PORT_MUX 906
CONFIG .........................................................................................................................................................
POWERMODE 910
CONFIG .........................................................................................................................................................
POWER_REDUCTION 916
CONFIG .........................................................................................................................................................
PRIORITY XMEGA 918
CONFIG .........................................................................................................................................................
PRIORITY XTINY 920
CONFIG .........................................................................................................................................................
PRINT 921
CONFIG .........................................................................................................................................................
PRINTBIN 922
CONFIG .........................................................................................................................................................
PS2EMU 923
CONFIG .........................................................................................................................................................
RAINBOW 925
CONFIG .........................................................................................................................................................
RC5 929
CONFIG .........................................................................................................................................................
RND 932
CONFIG .........................................................................................................................................................
SDA 934
CONFIG .........................................................................................................................................................
SCL 936
CONFIG .........................................................................................................................................................
SERIALIN 939
CONFIG .........................................................................................................................................................
SERIALOUT 945
CONFIG .........................................................................................................................................................
SINGLE 947
CONFIG .........................................................................................................................................................
SHIFTIN 948
CONFIG .........................................................................................................................................................
SPI 948
CONFIG .........................................................................................................................................................
SPIx XTINY 953
CONFIG .........................................................................................................................................................
SPIx XMEGA 955
CONFIG .........................................................................................................................................................
SERVOS 958
CONFIG .........................................................................................................................................................
SUBMODE 962
CONFIG .........................................................................................................................................................
SYSCLOCK XMEGA 964
CONFIG .........................................................................................................................................................
SYSCLOCK XTINY 965
CONFIG .........................................................................................................................................................
TCA0 967
CONFIG .........................................................................................................................................................
TCB0-TCB1 970
CONFIG .........................................................................................................................................................
TCD0 972
CONFIG .........................................................................................................................................................
TCXX 977
CONFIG .........................................................................................................................................................
TCPIP 980
CONFIG .........................................................................................................................................................
TIMER0 991
CONFIG .........................................................................................................................................................
TIMER1 994
CONFIG .........................................................................................................................................................
TIMER2 997
CONFIG .........................................................................................................................................................
TWI, TWIx 999
CONFIG
.........................................................................................................................................................
TWISLAVE 1005
CONFIG
.........................................................................................................................................................
TWIxSLAVE 1010
CONFIG
.........................................................................................................................................................
USB 1014
CONFIG
.........................................................................................................................................................
USI 1021
CONFIG
.........................................................................................................................................................
VPORT 1025
CONFIG
.........................................................................................................................................................
VREF 1027
CONFIG
.........................................................................................................................................................
WAITSUART 1028
CONFIG
.........................................................................................................................................................
WATCHDOG 1029
CONFIG
.........................................................................................................................................................
X10 1032
CONFIG
.........................................................................................................................................................
XPIN 1034
CONFIG
.........................................................................................................................................................
XRAM 1036
22 CONTINUE
................................................................................................................................... 1043
23 CONST................................................................................................................................... 1045
24 COUNTER0
...................................................................................................................................
and COUNTER1 1047
25 CPEEK................................................................................................................................... 1048
26 CPEEKH
................................................................................................................................... 1049
27 CRYSTAL
................................................................................................................................... 1051
28 DATA ................................................................................................................................... 1052
29 Date and
...................................................................................................................................
Time 1055
DAYOFWEEK
......................................................................................................................................................... 1055
DAYOFYEAR
......................................................................................................................................................... 1065
DATE$ ......................................................................................................................................................... 1066
DATE ......................................................................................................................................................... 1068
SECELAPSED
......................................................................................................................................................... 1077
SECOFDAY
......................................................................................................................................................... 1077
SYSSEC......................................................................................................................................................... 1079
SYSSECELAPSED
......................................................................................................................................................... 1080
SYSDAY......................................................................................................................................................... 1081
TIME$ ......................................................................................................................................................... 1083
TIME ......................................................................................................................................................... 1083
30 DBG ................................................................................................................................... 1085
31 DCF77TIMEZONE
................................................................................................................................... 1085
32 DEBUG................................................................................................................................... 1086
33 DEBOUNCE
................................................................................................................................... 1087
34 DECR ................................................................................................................................... 1089
35 DECLARE
...................................................................................................................................
FUNCTION 1090
36 DECLARE
...................................................................................................................................
SUB 1093
37 DEFxxx
................................................................................................................................... 1098
38 DELAY................................................................................................................................... 1098
39 DIM ................................................................................................................................... 1099
40 DISABLE
................................................................................................................................... 1111
41 DO-LOOP
................................................................................................................................... 1114
42 DTMFOUT
................................................................................................................................... 1115
43 ECHO ................................................................................................................................... 1117
44 ELSE ................................................................................................................................... 1119
45 ENABLE
................................................................................................................................... 1120
46 ENCODER
................................................................................................................................... 1124
47 END ................................................................................................................................... 1126
48 EXIT ................................................................................................................................... 1127
49 FLIP ................................................................................................................................... 1129
50 FOR-NEXT
................................................................................................................................... 1130
51 GET ................................................................................................................................... 1132
52 GETADC
................................................................................................................................... 1135
53 GETATKBD
................................................................................................................................... 1140
54 GETATKBDRAW
................................................................................................................................... 1144
55 GETKBD
................................................................................................................................... 1145
56 GETRC................................................................................................................................... 1147
57 GETRC5
................................................................................................................................... 1148
58 GETREG
................................................................................................................................... 1152
59 GOSUB
................................................................................................................................... 1153
60 GOTO ................................................................................................................................... 1154
61 HIGH ................................................................................................................................... 1155
62 HIGHW................................................................................................................................... 1156
63 Encryption-Decryption
................................................................................................................................... 1157
AESENCRYPT
......................................................................................................................................................... 1157
AESDECRYPT
......................................................................................................................................................... 1159
DESENCRYPT
......................................................................................................................................................... 1161
DESDECRYPT
......................................................................................................................................................... 1163
XTEAENCODE
......................................................................................................................................................... 1165
XTEADECODE
......................................................................................................................................................... 1167
64 I2C-TWI
................................................................................................................................... 1168
I2CINIT......................................................................................................................................................... 1168
I2CRECEIVE
......................................................................................................................................................... 1172
I2CSEND......................................................................................................................................................... 1173
I2START,I2CSTOP,
.........................................................................................................................................................
I2CRBYTE, I2CWBYTE, I2CREPSTART 1174
65 IDLE ................................................................................................................................... 1181
66 IF-THEN-ELSE-END
...................................................................................................................................
IF 1181
67 INCR ................................................................................................................................... 1183
68 INP ................................................................................................................................... 1183
69 LCD Commands
................................................................................................................................... 1185
BOX ......................................................................................................................................................... 1185
BOXFILL
......................................................................................................................................................... 1187
CIRCLE......................................................................................................................................................... 1187
CLS ......................................................................................................................................................... 1190
CURSOR......................................................................................................................................................... 1193
DEFLCDCHAR
......................................................................................................................................................... 1196
DISPLAY
......................................................................................................................................................... 1197
FOURTHLINE
......................................................................................................................................................... 1200
GLCDCMD
......................................................................................................................................................... 1201
GLCDDATA
......................................................................................................................................................... 1201
HOME ......................................................................................................................................................... 1202
INITLCD
......................................................................................................................................................... 1202
LCD ......................................................................................................................................................... 1204
LCDAUTODIM
......................................................................................................................................................... 1207
LCDAT ......................................................................................................................................................... 1207
LCDCMD......................................................................................................................................................... 1209
LCDDATA
......................................................................................................................................................... 1210
LCDCONTRAST
......................................................................................................................................................... 1210
LCDFONT
......................................................................................................................................................... 1211
LINE ......................................................................................................................................................... 1212
LOCATE......................................................................................................................................................... 1215
LOWERLINE
......................................................................................................................................................... 1215
PSET ......................................................................................................................................................... 1216
RGB8TO16
......................................................................................................................................................... 1219
SETFONT
......................................................................................................................................................... 1219
SHIFTCURSOR
......................................................................................................................................................... 1221
SHIFTLCD
......................................................................................................................................................... 1222
SHOWPIC
......................................................................................................................................................... 1223
SHOWPICE
......................................................................................................................................................... 1223
THIRDLINE
......................................................................................................................................................... 1225
UPPERLINE
......................................................................................................................................................... 1225
70 LOAD ................................................................................................................................... 1226
71 LOADADR
................................................................................................................................... 1226
72 LOADLABEL
................................................................................................................................... 1227
73 LOADWORDADR
................................................................................................................................... 1227
74 LOCAL................................................................................................................................... 1228
75 LOOKDOWN
................................................................................................................................... 1231
76 LOOKUP
................................................................................................................................... 1233
77 LOOKUPSTR
................................................................................................................................... 1234
78 LOW ................................................................................................................................... 1235
79 MACRO
................................................................................................................................... 1236
80 MAKEBCD
................................................................................................................................... 1237
81 MAKEDEC
................................................................................................................................... 1237
82 MAKEINT
................................................................................................................................... 1238
83 MAX ................................................................................................................................... 1238
84 MEMCOPY
................................................................................................................................... 1240
85 MEMFILL
................................................................................................................................... 1242
86 MIN ................................................................................................................................... 1243
87 MOD ................................................................................................................................... 1244
88 NBITS ................................................................................................................................... 1245
89 NOP ................................................................................................................................... 1246
90 ON INTERRUPT
................................................................................................................................... 1247
91 ON VALUE
................................................................................................................................... 1251
92 OPEN ................................................................................................................................... 1254
93 OUT ................................................................................................................................... 1262
94 PEEK ................................................................................................................................... 1263
95 POKE ................................................................................................................................... 1264
96 POPALL
................................................................................................................................... 1265
97 POWER
...................................................................................................................................
MODE 1265
98 POWERDOWN
................................................................................................................................... 1266
99 POWERSAVE
................................................................................................................................... 1267
100 PS2MOUSEXY
................................................................................................................................... 1267
101 PULSEIN
................................................................................................................................... 1268
102 PULSEOUT
................................................................................................................................... 1269
103 PUSHALL
................................................................................................................................... 1270
RB_ROTATERIGHT
......................................................................................................................................................... 1343
RB_SHIFTLEFT
......................................................................................................................................................... 1344
RB_SHIFTRIGHT
......................................................................................................................................................... 1345
RB_SETTABLECOLOR
......................................................................................................................................................... 1345
RB_GETCOLOR
......................................................................................................................................................... 1349
RB_LOOKUPCOLOR
......................................................................................................................................................... 1350
RB_COLOR
......................................................................................................................................................... 1350
RB_COPY
......................................................................................................................................................... 1352
135 Serial Data
...................................................................................................................................
RS232-RS485 1354
BAUD ......................................................................................................................................................... 1354
BAUD1-BAUDx
......................................................................................................................................................... 1355
BUFSPACE
......................................................................................................................................................... 1357
INKEY ......................................................................................................................................................... 1358
INPUT ......................................................................................................................................................... 1359
INPUTHEX
......................................................................................................................................................... 1362
INPUTBIN
......................................................................................................................................................... 1363
ISCHARWAITING
......................................................................................................................................................... 1364
MAKEMODBUS
......................................................................................................................................................... 1365
PRINT ......................................................................................................................................................... 1367
PRINTBIN
......................................................................................................................................................... 1370
SERIN ......................................................................................................................................................... 1371
SPC ......................................................................................................................................................... 1373
SEROUT......................................................................................................................................................... 1374
WAITKEY
......................................................................................................................................................... 1377
136 SPI ................................................................................................................................... 1379
SPIIN ......................................................................................................................................................... 1379
SPIINIT......................................................................................................................................................... 1380
SPIMOVE......................................................................................................................................................... 1381
SPIOUT......................................................................................................................................................... 1384
SPI1INIT,
.........................................................................................................................................................
SPI1IN, SPI1OUT, SPI1MOVE 1384
137 STRINGS
................................................................................................................................... 1385
CHARPOS
......................................................................................................................................................... 1385
DELCHAR
......................................................................................................................................................... 1386
DELCHARS
......................................................................................................................................................... 1387
INSERTCHAR
......................................................................................................................................................... 1388
INSTR ......................................................................................................................................................... 1389
LCASE ......................................................................................................................................................... 1390
LEFT ......................................................................................................................................................... 1391
LEN ......................................................................................................................................................... 1392
LTRIM ......................................................................................................................................................... 1392
MID ......................................................................................................................................................... 1393
RIGHT ......................................................................................................................................................... 1393
QUOTE......................................................................................................................................................... 1394
RTRIM ......................................................................................................................................................... 1394
SPACE......................................................................................................................................................... 1395
SPLIT ......................................................................................................................................................... 1396
STRING......................................................................................................................................................... 1397
TRIM ......................................................................................................................................................... 1398
UCASE......................................................................................................................................................... 1399
138 START................................................................................................................................... 1400
139 STCHECK
................................................................................................................................... 1402
140 STOP ................................................................................................................................... 1406
141 SUB ................................................................................................................................... 1407
142 SWAP ................................................................................................................................... 1407
Clear_B
.................................................................................................................................................. 1489
ClearColorA
.................................................................................................................................................. 1490
ClearColorRGB
.................................................................................................................................................. 1491
ClearColorRGBdw
.................................................................................................................................................. 1492
ClearStencil
.................................................................................................................................................. 1493
ClearTag
.................................................................................................................................................. 1493
ClearScreen
.................................................................................................................................................. 1494
CMD8 .................................................................................................................................................. 1494
CMD16.................................................................................................................................................. 1495
CMD32.................................................................................................................................................. 1495
CmdAppend
.................................................................................................................................................. 1496
CmdBgColor
.................................................................................................................................................. 1496
CmdButton
.................................................................................................................................................. 1497
CmdCalibrate
.................................................................................................................................................. 1498
CmdCalibratex
.................................................................................................................................................. 1499
CmdClock
.................................................................................................................................................. 1499
CmdColdStart
.................................................................................................................................................. 1502
CmdDial
.................................................................................................................................................. 1503
CmdDlStart
.................................................................................................................................................. 1504
CmdFgColor
.................................................................................................................................................. 1504
CMDFTSTACK
.................................................................................................................................................. 1505
CmdGauge
.................................................................................................................................................. 1506
CmdGetMatrix
.................................................................................................................................................. 1509
CmdGetPtr
.................................................................................................................................................. 1509
CmdGradColor
.................................................................................................................................................. 1510
CmdGradient
.................................................................................................................................................. 1511
CmdInflate
.................................................................................................................................................. 1512
CmdInterrupt
.................................................................................................................................................. 1513
CmdKeys
.................................................................................................................................................. 1513
CmdLoadIdentity
.................................................................................................................................................. 1515
CmdLoadImage
.................................................................................................................................................. 1516
CmdLogo
.................................................................................................................................................. 1516
CmdMemCpy
.................................................................................................................................................. 1517
CmdMemCrc
.................................................................................................................................................. 1517
CmdMemSet
.................................................................................................................................................. 1518
CmdMemWrite
.................................................................................................................................................. 1518
CmdMemZero
.................................................................................................................................................. 1519
CmdNumber
.................................................................................................................................................. 1519
CmdProgress
.................................................................................................................................................. 1521
CmdRegRead
.................................................................................................................................................. 1522
CmdRotate
.................................................................................................................................................. 1523
CmdRotateA
.................................................................................................................................................. 1524
CmdScale
.................................................................................................................................................. 1525
CmdScreenSaver
.................................................................................................................................................. 1526
CmdScrollBar
.................................................................................................................................................. 1526
CmdSetFont
.................................................................................................................................................. 1528
CmdSetMatrix
.................................................................................................................................................. 1528
CmdSketch
.................................................................................................................................................. 1528
CmdSlider
.................................................................................................................................................. 1529
CmdSnapShot
.................................................................................................................................................. 1531
CmdSpinner
.................................................................................................................................................. 1531
CmdStop
.................................................................................................................................................. 1534
CmdSwap
.................................................................................................................................................. 1534
CmdText
.................................................................................................................................................. 1534
CmdToggle
.................................................................................................................................................. 1536
CmdTrack
.................................................................................................................................................. 1538
CmdTranslate
.................................................................................................................................................. 1540
CmdTranslateP
.................................................................................................................................................. 1541
19 M128-1wire-PortF
................................................................................................................................... 1620
20 TVOUT................................................................................................................................... 1620
21 RAINBOWBSC
................................................................................................................................... 1628
22 LCD ................................................................................................................................... 1628
LCD4BUSY
......................................................................................................................................................... 1628
LCD4_anypin_oled_RS0010
......................................................................................................................................................... 1629
LCD_RX1602A5
......................................................................................................................................................... 1630
LCD4.LIB
......................................................................................................................................................... 1630
LCD4E2......................................................................................................................................................... 1631
GLCD ......................................................................................................................................................... 1632
GLCDSED
......................................................................................................................................................... 1632
PCF8533
......................................................................................................................................................... 1632
LCD-EPSON
......................................................................................................................................................... 1634
LCD_DOGS104a_I2C
......................................................................................................................................................... 1634
glcdR7565R
......................................................................................................................................................... 1638
glcdSSD1325_96x64
......................................................................................................................................................... 1639
GLCDEADOGMXL240-7-I2C
......................................................................................................................................................... 1640
GLCDdSSD1306-I2C
......................................................................................................................................................... 1642
LCD_I2C_PCF8574
......................................................................................................................................................... 1643
23 AVR-DOS
................................................................................................................................... 1647
AVR-DOS
.........................................................................................................................................................
File System 1647
MMCSD_HC.LIB
......................................................................................................................................................... 1668
24 CF Card
................................................................................................................................... 1668
Compact.........................................................................................................................................................
FlashCard Driver 1668
Elektor.........................................................................................................................................................
CF-Interface 1670
XRAM CF-Interface
.........................................................................................................................................................
for simulation 1671
New CF-Card
.........................................................................................................................................................
Drivers 1672
25 Floating
...................................................................................................................................
Point 1672
FP_TRIG
......................................................................................................................................................... 1672
DOUBLE......................................................................................................................................................... 1675
26 I2C SLAVE
................................................................................................................................... 1675
CONFIG.........................................................................................................................................................
I2CSLAVE 1675
I2C TWI.........................................................................................................................................................
Slave 1676
27 SPI ................................................................................................................................... 1676
SPISLAVE
......................................................................................................................................................... 1676
28 DATE TIME
................................................................................................................................... 1679
EUROTIMEDATE
......................................................................................................................................................... 1679
DATETIME
......................................................................................................................................................... 1680
29 PS2-AT...................................................................................................................................
Mouse and Keyboard Emulation 1681
AT_EMULATOR
......................................................................................................................................................... 1681
PS2MOUSE_EMULATOR
......................................................................................................................................................... 1681
30 BCCARD
................................................................................................................................... 1681
BCCARD
......................................................................................................................................................... 1681
BCDEF......................................................................................................................................................... 1682
BCCALL
......................................................................................................................................................... 1683
BCRESET
......................................................................................................................................................... 1689
31 USB ................................................................................................................................... 1690
USB Add
.........................................................................................................................................................
On 1690
32 MODBUS
...................................................................................................................................
Slave/Server 1703
2 BASCOMP
................................................................................................................................... 1708
Index 1711
I
Index 27
1 Index
All software provided with this product package is provided 'AS IS' without any
warranty expressed or implied.
MCS Electronics will not be liable for any damages, costs or loss of profits arising
from the usage of this product package.
CAN
CONFIG CANBUSMODE 792 , CONFIG CANMOB 796 , CANBAUD 744 , CANRESET 748 ,
CANCLEARMOB 747 , CANCLEARALLMOBS 746 , CANSEND 749 , CANRECEIVE 747 , CANID 746 ,
CANSELPAGE 748 , CANGETINTS 745
Conditional Compilation
#IF #ELSE #ELSEIF #ENDIF , VAREXIST 509
Configuration
Configuration commands initialize the hardware to the desired state.
CONFIG 757 , CONFIG ACI 764 , CONFIG ADC 767 , CONFIG ADCx 769 , CONFIG BCCARD
789 , CONFIG CLOCK 798 , CONFIG COM1 812 , CONFIG COM2 814 , CONFIG DAC 819 ,
CONFIG DATE 826 , CONFIG DMXSLAVE 848 , CONFIG EEPROM 851 ,CONFIG
EXTENDED_PORT 858 , CONFIG PS2EMU 923 , CONFIG ATEMU 786 , CONFIG I2CSLAVE 875
, CONFIG INPUT 880 , CONFIG GRAPHLCD 862 , CONFIG KEYBOARD 886 , CONFIG
TIMER0 991 , CONFIG TIMER1 994 , CONFIG LCDBUS 895 , CONFIG LCDMODE 898 ,
CONFIG 1WIRE 759 , CONFIG LCD 889 , CONFIG OSC 902 , CONFIG SERIALOUT 945 ,
CONFIG SERIALIN 939 , CONFIG SPI 948 , CONFIG SPIx 955 , CONFIG SYSCLOCK 964 ,
CONFIG LCDPIN 898 , CONFIG PRIORITY 918 , CONFIG SDA 934 , CONFIG SCL 936 ,
CONFIG DEBOUNCE 835 , CONFIG WATCHDOG 1029 , CONFIG PORT , 904 COUNTER0 AND
COUNTER1 1047 , CONFIG TCPIP 980 , CONFIG TWISLAVE 1005 , CONFIG SINGLE 947 ,
CONFIG X10 1032 , CONFIG XRAM 1036 , CONFIG USB 1014 , CONFIG DP 851 , CONFIG TCXX
977 , CONFIG VPORT 1025 CONFIG ERROR 852 , CONFIG POWER REDUCTION 916 , CONFIG
EVENT_SYSTEM 853 , CONFIG DMA 836 , CONFIG DMACHx 837 , CONFIG SUBMODE 962 ,
CONFIG POWERMODE 910 , CONFIG XPIN 1034 , CONFIG FT800 858 , CONFIG I2CBUS 871 ,
CONFIG EDMA 843 , CONFIG EDMAx 844 , CONFIG INPUTBIN 881 , CONFIG MODBUS 902 ,
CONFIG PORT_MUX 906 , CONFIG VREF 1027 , , CONFIG TCA 967 , CONFIG TCB 970 , CONFIG
TCD 972
Conversion
A conversion routine is a function that converts a number or string from one form to
another.
BCD 726 , GRAY2BIN 735 , BIN2GRAY 729 , BIN 728 , MAKEBCD 1237 , MAKEDEC 1237 ,
MAKEINT 1238 , FORMAT 732 , FUSING 734 , BINVAL 729 , CRC8 712 , CRC16 716 , CRC16UNI
719 , CRC32 720 , HIGH 1155 , HIGHW 1156 , LOW 1235 , AESENCRYPT 1157 , AESDECRYPT 1159 ,
FLIP 1129 , CRCMB 721 , CRC8UNI 714 , MANCHESTERDEC 738 , MANCHESTERENC 739 ,
DESENCRYPT 1161 , DESDECRYPT 1163
DateTime
Date Time routines can be used to calculate with date and/or times.
DATE 1068 , TIME 1083 , DATE$ 1066 , TIME$ 1083 , DAYOFWEEK 1055 , DAYOFYEAR 1065 ,
SECOFDAY 1077 , SECELAPSED 1077 , SYSDAY 1081 , SYSSEC 1079 , SYSSECELAPSED 1080
Delay
Delay routines delay the program for the specified time.
WAIT 1461 , WAITMS 1461 , WAITUS 1462 , DELAY 1098
Directives
Directives are special instructions for the compiler. They can override a setting from
the IDE.
$ASM 511 , $BAUD 512 , $BAUD1 513 , $BIGSTRINGS 516 , $BGF 514 , $BOOT 517 ,
$CRYSTAL 530 , $DATA 531 , $DBG 532 , $DEFAULT 534 , $EEPLEAVE 535 , $EEPROM 535 ,
$EEPROMHEX 537 , $EEPROMSIZE 537 , $EXTERNAL 538 , $HWSTACK 553 , $INC 558 ,
$INCLUDE 559 , $INITMICRO 561 , $LCD 562 , $LCDRS 567 , $LCDPUTCTRL 564 ,
$LCDPUTDATA 566 , $LCDVFO 569 , $LIB 570 , $LOADER 572 , $LOADERSIZE 588 , $MAP 589
, $NOCOMPILE 590 , $NOINIT 591 , $NORAMCLEAR 591 , $NORAMPZ 591 , $PROJECTTIME
593 , $PROG 594 , $PROGRAMMER 595 , $REGFILE 598 , $RESOURCE 599 , $ROMSTART 601
File
File commands can be used with AVR-DOS, the Disk Operating System for AVR.
BSAVE 678 , BLOAD 676 , GET 1132 , VER 1459 , DISKFREE 681 , DIR 680 , DriveReset 685 ,
DriveInit 685 , LINE INPUT 697 , INITFILESYSTEM 696 , EOF 688 , WRITE 705 , FLUSH 693 ,
FREEFILE 694 , FILEATTR 689 , FILEDATE 690 , FILETIME 692 , FILEDATETIME 691 , FILELEN
692 , SEEK 1300 , KILL 696 , DriveGetIdentity 684 , DriveWriteSector 687 , DriveReadSector
686 , LOC 698 , LOF 699 , PUT 1270 , OPEN 1254 , CLOSE 752 , CHDIR 679 , MKDIR 700 , RMDIR
701 , NAME 701 , GETATTR 695 , SETATTR 702 , CLEARATTR 679
Graphical LCD
Graphical LCD commands extend the normal text LCD commands.
GLCDCMD 1201 , GLCDDATA 1201 , SETFONT 1219 , LINE 1212 , PSET 1216 , SHOWPIC 1223 ,
SHOWPICE 1223 , CIRCLE 1187 , BOX 1185 , RGB8TO16 1219
I2C
I2C commands allow you to communicate with I2C chips with the TWI hardware or
with emulated I2C hardware.
I2CINIT 1168 , I2CRECEIVE 1172 , I2CSEND 1173 , I2CSTART, I2CREPSTART, I2CSTOP,
I2CRBYTE,I2CWBYTE 1174
IO
I/O commands are related to the I/O pins and ports of the processor chip.
ALIAS 639 , BITWAIT 706 , TOGGLE 1457 , RESET 1294 , SET 1305 , SHIFTIN 1315 , SHIFTOUT
1319 , DEBOUNCE 1087 , PULSEIN 1268 , PULSEOUT 1269
Micro
Micro statements are specific to the micro processor chip.
IDLE 1181 , POWER mode 1265 , POWERDOWN 1266 , POWERSAVE 1267 , ON INTERRUPT 1247 ,
ENABLE 1120 , DISABLE 1111 , START 1400 , END 1126 , VERSION 1460 , CLOCKDIVISION 751 ,
CRYSTAL 1051 , STOP 1406
Memory
Memory functions set or read RAM , EEPROM or flash memory.
ADR 635 , ADR2 635 , WRITEEEPROM 1464 , CPEEK 1048 , CPEEKH 1049 , PEEK 1263 , POKE 1264 ,
OUT 1262 , READEEPROM 1280 , DATA 1052 , INP 1183 , READ 1279 , RESTORE 1295 ,
LOOKDOWN 1231 , LOOKUP 1233 , LOOKUPSTR 1234 , LOADADR 1226 , LOADLABEL 1227 ,
LOADWORDADR 1227 , MEMCOPY 1240 , GETREG 1152 , SETREG 1307 , VARPTR 1459 , MEMFILL
1242
Remote Control
Remote control statements send or receive IR commands for remote control.
RC5SEND 1273 , RC6SEND 1276 , GETRC5 1148 , SONYSEND 1320
RS-232
RS-232 are serial routines that use the UART or emulate a UART.
BAUD 1354 , BAUD1 1355 , BUFSPACE 1357 , CLEAR 750 , ECHO 1117 , WAITKEY 1377 ,
ISCHARWAITING 1364 , INKEY 1358 , INPUTBIN 1363 , INPUTHEX 1362 , INPUT 1359 , PRINT 1367 ,
PRINTBIN 1370 , SERIN 1371 , SEROUT 1374 , SPC 1373 , MAKEMODBUS 1365
SPI
SPI routines communicate according to the SPI protocol with either hardware SPI or
software emulated SPI.
SPIIN 1379 , SPIINIT 1380 , SPIMOVE 1381 , SPIOUT 1384 , SPI1IN 1379 , SPI1INIT 1380 ,
SPI1MOVE 1381 , SPI1OUT 1384
String
String routines are used to manipulate strings.
ASC 722 , CHARPOS 1385 , UCASE 1399 , LCASE 1390 , TRIM 1398 , SPLIT 1396 , LTRIM 1392 , INSTR
1389 , SPACE 1395 , STRING 1397 , RTRIM 1394 , LEFT 1391 , LEN 1392 , MID 1393 , RIGHT 1393 , VAL
743 , STR 740 , CHR 731 , CHECKSUM 711 , CHECKSUMXOR 711 , HEX 737 , HEXVAL 736 ,
QUOTE 1394 , REPLACECHARS 1293 , STR2DIGITS 741 , DELCHAR 1386 , DELCHARS 1387 ,
INSERTCHAR 1388
TCP/IP
TCP/IP routines can be used with the W3100/IIM7000/IIM7010/W5100/W5200/
W5300 modules.
BASE64DEC 1408 , BASE64ENC 1410 , IP2STR 1417 , UDPREAD 1444 , UDPWRITE 1449 ,
UDPWRITESTR 1450 , TCPWRITE 1439 , TCPWRITESTR 1441 , TCPREAD 1438 , GETDSTIP 1412 ,
GETDSTPORT 1413 , SOCKETSTAT 1433 , SOCKETCONNECT 1429 , SOCKETLISTEN 1432 ,
GETSOCKET 1415 , SOCKETCLOSE 1425 , SETTCP 1420 , GETTCPREGS 1416 , SETTCPREGS 1422 ,
SETIPPROTOCOL 1418 , TCPCHECKSUM 1435 , SOCKETDISCONNECT 1432 , SNTP 1423 ,
TCPREADHEADER 1439 , UDPREADHEADER 1447 , URL2IP 1454
Text LCD
Text LCD routines work with normal text based LCD displays.
HOME 1202 , CURSOR 1193 , UPPERLINE 1225 , THIRDLINE 1225 , INITLCD 1202 , LOWERLINE 1215
, LCD 1204 , LCDAT 1207 , FOURTHLINE 1200 , DISPLAY 1197 , LCDCONTRAST 1210 , LOCATE 1215 ,
SHIFTCURSOR 1221 , DEFLCDCHAR 1196 , SHIFTLCD 1222 , CLS 1190 , LCDAUTODIM 1207 ,
LCDCMD 1209 , LCDDATA 1210 , LCDFONT 1211
Various
This section contains all statements that were hard to put into another group
CONST 1045 , DBG 1085 , DECLARE FUNCTION 1090 , DEBUG 1086 , DECLARE SUB 1093 , DEFXXX
1098 , DIM 1099 , DTMFOUT 1115 , EXIT 1127 , ENCODER 1124 , GETADC 1135 , GETKBD 1145 ,
GETATKBD 1140 , GETRC 1147 , GOSUB 1153 , GOTO 1154 , LOCAL 1228 ,ON VALUE 1251 , POPALL
1265 , PS2MOUSEXY 1267 , PUSHALL 1270 , RETURN 1296 , RND 1297 , ROTATE 1299 , SENDSCAN
1308 , SENDSCANKBD 1310 , SHIFT 1313 , SOUND 1326 , STCHECK 1402 , SUB 1407 , SWAP 1407 ,
VARPTR 1459 , X10DETECT 1467 , X10SEND 1468 , READMAGCARD 1286 , REM 1293 , BITS 707 ,
BYVAL 709 , CALL 709 , #IF 509 , #ELSE 509 , #ENDIF 509 , READHITAG 1283 , SORT 1325 ,
XTEADECODE 1167 , XTEAENCODE 1165 , BREAK 708 , COMPARE 755 , NOP 1246 , SIZEOF 1323
RAINBOW WS2812
Rainbow or WS2812 LED statements and functions.
CONFIG RAINBOW 925 , RB_ADDCOLOR 1334 , RB_ANDCOLOR 1334 , RB_ORCOLOR 1336 ,
RB_SUBCOLOR 1336 , RB_CLEARSTRIPE 1337 , RB_CLEARCOLORS 1338 , RB_FILL 1338 ,
RB_FILLCOLORS 1339 , RB_FILLSTRIPE 1341 , RB_SELECTCHANNEL 1328 , RB_SEND 1330 ,
RB_SETCOLOR 1329 , RB_SWAPCOLOR 1341 , RB_ROTATELEFT 1342 , RB_ROTATERIGHT 1343 ,
RB_SHIFTLEFT 1344 , RB_SHIFTRIGHT 1345 , RB_CHANGEPIN 1331 , RB_SETTABLECOLOR 1345 ,
RB_GETCOLOR 1349 , RB_LOOKUPCOLOR 1350 , RB_COLOR 1350 , RB_COPY 1352
FT800-FT801-FT810
CMD8 1494 , CMD16 1495 , CMD32 1495 , RD8 1548 , RD16 1548 , RD32 1549 , WR8 1559 , WR16 1560 ,
WR32 1560
XMEGA
READSIG 1290 , ATXMEGA 393
XTINY
XTINY 428
MEGAX
MEGAX 457
1.2 Changes
1.2.1 What is new in 2084
version 2084.001
Public release
- new option SAFE for variables. Dim 1099 b as bit SAFE , see help.
- added BOOTONLY option to $LOADER 572 directive. $loader bootaddress[,
BOOTONLY] this will write just the boot loader code to the BIN file. The HEX remains
as is.
- you can select the Options_Select_Settings_File 205 now. This setting is stored in the
registry.
- project files are stored with absolute files names inside the prj file. An absolute file
name is relative to the location.
- simulator bug fixed where SI file simulation data was not processed properly.
- MemFill 1242 added.
- using instr() with {xxx} for the search string does not work : pos=instr
(someAString,"{065}")
Please notice that this version has significant changes in order to support the Xtiny
platform.
While everything was extensively tested, it is still possible you encounter a bug.
When you encounter a problem you did not had with 2082 you best contact support.
FILE LOCATION
With DOS things were simple : all files could go in a folder and sub folder. To make a
backup all you had to do was using XCOPY.
With Windows things are not so simple : files are located all over the PC. Some
folders are write protected and to make a backup is not so simple.
A lot of customers are looking for the SAMPLE files. These are put in the documents
folder and can be accessed using the File, Open Sample option.
In 2082 the preferred folder for installation is C:\MCS\BASCAVR2082
But of course you are free to install in any other folder of your choice.
The samples are installed in a sub folder of the application folder too.
In the Environment Options of the IDE you can specify which folder you want to use
for the sample files.
About UPDI
The new UPDI processors have a total different architecture compared to normal AVR.
In fact the differences are similar to XMEGA. For this reason we refer to these
processors as XTINY since they are tiny Xmega processors.
Because of the work and support for XMEGA fresh in mind, the actual UPDI compiler/
DAT support will be available very soon in a next update as an add on.
The TINY816/817 will be the first processor to be supported.
- FM24C64_256 1600 -XMEGA.lib added for xmega. read the lib notes.
- tcpip-w5500.lbx has been updated to support usage from boot space. See $loader
572
- stk500 board. osc can be set from menu
- using spimove 1381 () inside a sub with a parameter for the count, would load the
wrong data.
- i2cwbyte 1174 would raise an error if a multi dim array was used.
- get/put/seek in AVR-DOS used in combination with $bigstrings would fail for
numeric data
- xmega i2cstop 1174 has two new optional mode. See help.
- CONFIG SPI 948 has a new option : EXTENDED=1 to have extended data size
reading/writing.
- support for rgbW 925 leds added (ws2812 with extra white led)
- CONFIG USI 1021 has a new option to support optional pins.
- Support for WS2812 RGB led : CONFIG RAINBOW 925 . This is the rainbow lib from
Galahat, see : http://bascom-forum.de/mediawiki/index.php/Rainbow_Lib
- SETATTR 702 and CLEARATTR 679 added to AVR-DOS, by Josef.
- shift & rotate left/right did not work for xmega port registers
- IDE : improved speed for showing deadcode/unused variables
- IDE : stacktrace speed up. big projects made the stacktrace slow.
- included FT801 support. See CONFIG FT800 858 . Notice that the INC files have been
renamed into FT80x
- fixed attiny261,461 and 861 interrupt entries. this chip has only 1 pcint.
- added check when $loadersize 588 and $boot 517 are combined.
- Dim 1099 supports a list ; dim a,b,c,d as byte. It also supports identifiers like %,#,&
and !
- Font Editor plugin is replaced by integrated Font Editor: Tools, Font Editor 133
- Sample added for USI Slave lib 1611
- fonts contributed by Adam Siwek included. You can find them in the
Samples\LCDgraph\Fonts folder.
- report 102 can be opened in IDE as text file.
- multi dim arrays can only be used to read/assign variables. Using them in functions
and statements will not work.
- str 740 () can have an optional parameter to specify the amount of digits. This works
for double, but now also for singles.
- MOD 1244 for singles changed in fp_trig.lib so it uses the same algorithm as excel/
VBA.
- FOR..NEXT with WORD data type and STEP with values other than 1 failed : for w=1
to 10 step 2
- when opening a single file in non-project mode, the code explorer does not get
updated until you set the cursor on the code.
This also resulted in not updating the pinout viewer.
- R0-R31 internal variables are now exposed as byte variables. This is simpler than
using getreg/setreg.
- added option to skip eeprom cell test. This allows to write all FF to the EEPROM
whithout erasing the chip.
- terminal emulator font color could not be selected from the font dialog.
- various programmers : added chip name to info panel when chip does not match. no
match will result in a red font, a match will show in green.
- added an error message when $hwstack,$swstack and $framesize are missing from
the source. Also put back compatibility to 2077 when these directives are not
specified.
- hovering the indention line will show the begin of the structure in the tool tip (just
try it).
- Terminal emulator 120 has 8 user definable buttons
- SEROUT 1374 defaults to CONST SEROUT_EXTPULL=1 to be in Hi-Z mode. In this
mode a pull up resistor is required. To use PORT output mode, set the constant to 0 :
CONST SEROUT_EXTPULL=0
- changing a bit on a passed array inside a sub/function gave a bit index error.
- while moving all single FP code to fp_trig.lib, some double (but WRONG) functions
were moved to the top. It causes various problems.
- clear buffer did not reset the RST pin in case CTS/RTS was used.
- val()/asc2float contained a bug for converting big values not fitting into the
mantissa. The exponent was not increased.
- asc 722 () can have an additional index parameter : byte=Asc(string|string constant[,
index]). Use this instead of asc(mid(
- user functions/subs can have a custom color
- added support for i2c lcd display RX1602A5. Use : config lcd = 16x2 , chipset =
st7032. See sample LCD-RX1602A5.bas
- using overlay pointing to a string array resulted in a wrong overlay address.
- additional XTEA2.LIB added. This lib complies with the original standard.
- mkII programmer would give a warning about chip mismatch when atmel chip ID
was the same.
- pulsein.lib was missing from distribution.
- documented beta switches $NOTYPECHECK 593 , $TYPECHECK 614 and $REDUCEIVR 596
- when using a serial boot loader compiled with an older version, and when calling it
from code (not after a reset) you need to reset the u2x flag in ucsrxA.
Or you can compile both the bootloader and main code with the new version. When
you want the old behaviour, you can remark the u2x constant in the dat file.
- xmega, config OSC : when using external osc, the oscillator ready test was not
working properly. enable the internal osc as a workaround in 2077. fixed in this
release.
- arduino leonardo can be programmed with myAVR MK2/AVR910. You need to give a
manual reset before pressing F4.
- attiny87 dat file contained an error : INTADR = 1 ; it was 2 but must be 1
- xmega spi length parameter supported globals only. now it supports locals and
parameters as well.
- syntax check gave errors when config submode=new was used in some cases.
- 1wirecount returned with ERR set, even when sensors were found.
- simulator 103 has trace log option to dump all executed lines to a file.
- error list content can be copied to clipboard with right mouse popup menu
- xmega uarts 5-8 serial buffered output enable the wrong uart.
- indention line colors can be customized.
- proper indent 82 will not indent comment
- getkbd 1145 () required change for xmega. (xmega does not use port register for pull
up)
- added dword support to lookup()
- config rnd 932 =16|32 added to support bigger random numbers.
- attiny441 stk500 settings changed. attiny441 and attiny841 verified with real chips.
some mods made to the dat files.
- increased internal constant string storage length to 1024. for cases like : s="some
very long constant". previously the max size was 256.
- xmegaE5 timers 4/5 support added.
- xmegaE timer4/5 OVF bit need a manual reset, writing a 1 to intflags register. it is
not cleared automatically.
- xm128a1U dat file added
- code folding added to editor. Press F11 to fold a sub/function
- all project files can be placed in an archive 74 (zip) file.
- AVR-DOS, GET and PUT support $bigstrings 516
- $boot 517 extended to support >64KB processors. $boot can be used together
with $inc to include a boot loader in your code.
- FM25C256 example with BMA.bas sample added which demons xmega ramtron lib
with shared bus.
- baudX=value added for Xmega. This will change the baud rate on an xmega at run
time.
- special multi bus i2c added for normal AVR processors. See config i2cbus 871 .
- Lookup 1233 supports a numeric variable too for the label : novar = LOOKUP( value,
label|address).
- soft spi supports DATA ORDER LSB and MSB
- str 740 () second optional parameter added to help. It specifies number of digits after
the DP. Only for doubles.
- m324/m164/m644/m1280 config timer0, disconnect option fixed.
- settings xml file can be passed as parameter to allow different settings files and
versions.
When the ATARI came with the 1040ST and an affordable PCB design tool, I bought
my first real computer. I bought the ATARI just for the purpose of PCB design. The
netlists had to be manually entered.
Only Dot matrix printers where available at that time. And the prints were not really
usable. That only changed when laser printers became available.
I found out that a nice BASIC interpreter, which was similar to GW-BASIC, was
included in the OS(TOS). For some reason, I liked this language. It was easy to
master and very intuitive.
I made some programs for the PTT(now KPN) that were revolutionary at that time.
For hobby purpose i used the 8052AH BASIC programmable processor from Intel. I
made a lot of interfaces using PIO, relay, etc. My home was automated in 1986.
Because of my work for the PTT i was also able to get caller info, something not
available as a service yet. I used the 8052AH to show the caller info on an LCD.
The 8052 was great but the UV eeproms had to be erased using UV light. It was slow.
I found out, that Atmel made the 89C2051, which was a 20 pin chip with flash
memory. I was excited to find out that there was a small micro processor that could
be erased/reprogrammed without the need to UV erase the EPROM.
In those days, electronic circuits consisted of numerous CMOS and TTL chips. I saw
the 89C2051 as an ideal replacement for a lot of CMOS/TTL chips. It would make PCB
design much simpler. So the 2051 became a replacement chip. Like a small black box
chip. Now one was able to design his own chips!
I initially wrote a complete tool for DOS. I rewrote the tool, when I was reasonably
satisfied that Windows 3.1 was stable. The tool was for my own usage. When I
discovered that it would be usable to others, I decided to add Help files and a
simulator and to sell it for a small fee to support my hobby. Today you can get
electronic devices for little money. But a resistor used to cost 5 cents !
In 1995, MCS started to sell BASCOM-LT, a BASIC compiler for Windows 3.1. It was
the first Windows application that offered a complete and affordable solution, editor,
compiler, simulator and programmer. BASCOM-LT was a 8051 BASIC compiler. The
reason it became popular was that it included a lot of functionality that was easy to
use from BASIC. Using an LCD display was simple, just a configuration line to define
the used pins and voila, a working application in minutes. When you needed a
different LCD display, you could simply change the CONFIG line.
When a different processor was needed, you only had to change the name of the
definition file. No need for a lot of .h files.
Another reason for its success, was that we hide much of the complexity for the user.
No ASM to deal with, simple statements. Of course free updates and support.
Small companies that used the BASIC Stamp also recognized another advantage :
There was no need for expensive modules and the code ran much quicker.
When Windows 95 became an industry standard, users also wanted a 32 bit version.
A big part of BASCOM-LT was rewritten with the additional support for arrays and
floating point (single).
With the many different 8051 variants, it was impossible to support all the chips.
Having device definition “DAT” files, made it easy for the user to configure the 8051
variants.
When Atmel launched the AVR chip, the 8051 compiler was rewritten, once again, to
support the powerful AVR chips. The result was BASCOM-AVR.
The AVR chip has a lot of internal memory. It uses simple linear memory addressing.
The best part, is that you can make the chip program itself. No wonder this chip
family became so popular.
Since the AVR chip is so powerful, we could extend the compiler as well. We could
add features, which are almost impossible to add to the 8051.
With more and more users, there was no way I could manage everything in my spare
time. So in order to guarantee the future of BASCOM, I decided to work full time for
MCS.
Today, MCS is still a small company, with only 3 employees and a few contract
workers.
We believe in free updates and support. With the number of (demo) users, it is
however not possible to support everybody. You need to realize that reading and
answering emails is time consuming.
Not to mention to duplicate used hardware. We are unique, in that we even support
hardware!
In order to migrate to a new version, it is important that you keep your software up
to date. This will make migration more simple.
· The environment. We reuse all usable packing material like foam, plastic bubbles,
when we ship your order.
· That everybody can use micro processors. They are like all other chips but you can
define their behaviour.
· Customer privacy: We keep your name, details and code confidential. We do not
sell or share any of your details.
· Free updates. They have been free since 1995 but there is no guarantee that they
will remain free for ever. The intention is to keep them free. In order to apply for
free updates you MUST register your software within 1 year.
· Free, but limited, support. Limited only, because we do not have the resources to
read/answer all emails. Professional users can get an SLA with guaranteed
response time. This is a paid option/service.
· Support for new chips. It is important to be able to support newly released chips.
· The customer : We simply add what is requested most. It does not matter what, as
long as it is requested a lot and it does makes sense and doesn't conflict with other
features.
· That you have fun with electronics, no matter where you live, no matter which
religion you have, no matter how old you are, if you are male or female, purple or
white.
· That you can use the demo for free. The DEMO has no nag screens. You should
purchase the full version if you use it commercial. Please do not use cracked
software. Only download from the www.mcselec.com domain. Copies from other
sites may contain spy ware, virus or other malware. When we detect a cracked
version the compiler generates tiny bugs at random which are hard to detect. We
ban all IP numbers of users with a cracked version.
Mark Alberts
Managing Dire
MCS Electronics
AN's are also welcome. When you developed a great AN you want to share with other
BASCOM users, just send it and we will make an AN out of it. It is important that the
comment in the source is in English.
You can also share your code at the MCS Electronics user forum.
Some topics show examples. Some examples are partial samples. Some examples
demonstrate a number of statements.
And some topics contain full examples.
When you want to use examples you can best load the examples that come with the
IDE.
By default they are installed in the SAMPLES folder.
The samples from the distribution are checked with each release since they are
intended to be compiled.
So they contain a $regfile directive, and default stack settings. And when print is
used, communication set up.
The samples from the help are only intended to demonstrate a statement or function
and are extremely simple. Often $regfile and stack is omitted.
When you want to use the sample from the help you can copy & paste it.
Do not forget to include $regfile, $hwstack, $swstack and $framesize when it is not
included in the sample. The sample will compile without this info too but for later
reference it is best to include this info.
Some examples from the help are from 1995 and the compiler has been extended.
When you encounter a sample from the help that does not work, send an email to
support so it can be corrected.
II
Installation 47
2 Installation
2.1 Installation of BASCOM
After you have downloaded the ZIP file you need to UNZIP the file.
On Windows XP, for the DEMO version, you may run the setupdemo.exe file from
within the Zipped file. For the full version you should unzip the ZIP file.
The commercial version comes with a license file in the form of a DLL. This file is
always on the disk where the file SETUP.EXE is located. When explorer does not show
this file, you must set the option in explorer to view system files (because a DLL is a
system file).
For the commercial version the setup file is named SETUP.EXE
Some resellers might distribute the DLL file in a zipped file. Or the file might have the
extension of a number like "123". In this case you must rename the extension to DLL.
Make sure the DLL is in the same directory as the SETUP.EXE file.
When you are using the DEMO version you don't need to worry about the license file.
When you are installing on a NT machine like NT4 , W2000, XP, Vista, Win7, Win8 or
Win10, you need to have Administrator rights.
After installing BASCOM you must reboot the computer before you run
BASCOM.
The installation example will describe how the FULL version installs. This is almost
identical to the installation of the DEMO version.
Before installing the software : make sure you downloaded from mcselec.com
domain. Or that you purchased from an authorized reseller.
When in doubt you can always check the executable on your PC using your browser at
virustotal.com. In fact it is good practice to check files before you install them.
virustotal.com will use 50 or more virus scanners.
This will give a good idea about the safety of a file.
Depending on the windows version and your user rights, windows might give the
following message :
Read the instructions , select 'I accept the agreement' and press the Next button.
Read the additional information and click the Next button to continue.
You can select the drive and path where you like BASCOM to be installed. You can
also accept the default value which is :
C:\MCS\BASCAVR2082
or you can install into a folder like :
C:\Program Files\MCS Electronics\BASCOM-AVR
Microsoft likes software to be installed into the Program Files folder. But this also
means that all sub folders must be stored elsewhere since all folders under Program
Files are write protected by Windows.
Using a user writable folder, all the files can be stored in one location.
It is a good idea to install each new version into its own folder. This way, you can use
multiple versions at the same time. As of version 2082, the settings file is stored in
the application folder too.
In case of this warning, select Yes. Or select NO and select a different folder.
You can select the folder where the sample files are installed. This can be :
c:\users<USER>Documents\samples
or c:\MCS\BASCAVR2082\Samples
We recommend to use the second option so all files are placed under the application
folder.
After you made your choice, click the Next button.
You are now presented with an optional component : parallel printer programming
support.
Nowadays there are plenty serial and USB programmers available. Only select this
option when you still use the LPT port for ISP programming.
You will now be presented a choice for the program group name and location.
You can choose to create into a new Program Group named 'BASCOM-AVR' , or you
can modify the name, or install into an existing Program Group. Press the Next-
button after you have made your choice.
After the main files are installed, some additional files will be installed. This depends
on the distribution.
These additional files can be PDF files when the program is distributed on a CD-ROM.
When the installation is ready you will see the last screen :
You have to reboot your computer when you want to make advantage of the
programmers that BASCOM supports. You can also do this at a later stage.
You can view the "Read me" and "License" files content and you can start BASCOM-
AVR.
BASCOM supports both HTML Help and old Win help(HLP). The HLP file is not
distributed in the setup. You need to use the Update Wiz to download it. But it is
advised to use the HTML-Help file.
When you used to use the HLP file, and find it missing now, turn on 'Use HTML Help'
in Options, Environment, IDE. 142
When the UpdateWiz is not installed, you can download it from the register 55 .
The option Help, Update 214 will also download the wiz.
Till version 2074 all sample files were placed under the MCS Electronics\BASCOM-AVR
folder.
Version 2075 places the sample files under the user Documents\MCS
Electronics\BASCOM-AVR\Samples folder.
While we prefer to keep all files at one location and sub folders, this is not allowed in
Windows 7 where the Program Files folder and all it's sub folders are write
protected.
In version 2082 you can decide where the samples must be installed
2.2 Updates
The update process is simple if you follow all steps.
· Go to the main MCS website at https://www.mcselec.com
· In the left pane under 'Main Menu' you will find a link named 'Registration/Updates'
· Optional you can enter the address yourself : https://register.mcselec.com
Notice that the website uses two different accounts : one for the forum/shop and
one for the registration/updates. You will see the following screen:
· When you don't have an account yet, Click the link and select 'Create new account'
You need to provide a username, password, email and full name. Company name is
optional.
When you filled in the information, click 'Submit Registration'.
· After you click submit, you can get various error messages. For example that a
username already exists. Press the Back-button in your browser, and correct the
problem, then try again
· If the registration is successful you will get a message that the registration
succeeded.
· Watch your mail : you will receive an email with a confirmation link. You need to
click this link in order to finalize your account
· Now you can login. You will see the following or similar screen :
It is important that you enter a valid serial number. Do not try to enter serial
numbers from cracked versions. When you enter invalid serial numbers, you will loose
support and the ability to update. We will also ban your IP number from our web. The
valid serial number is shown in the Help, About box.
When the product is selected, the serial number is entered and you press 'Register
product' you will see the following message :
At the top you can see which products are registered, and which status they have.
When you want to do a FULL SETUP, you need to download the full version.
You do not need to uninstall a previous version. You can install an update into the
same directory or a new directory.
When you uninstall a previous version, it will remove the license file which is not part
of the setup.exe
So in the event that you do run uninstall first, make a backup of the license dll
named bscavrL.DLL
For BASCOM, the ZIP file you download contains only one setup.exe. You need to run
this executable.
It is also important that you put the license DLL into the same directory as setup.exe
Setup will copy this file to the BASCOM application directory. You can also manual
copy this file.
The license file is on CD-ROM, diskette, or the media (email) you received it on. It is
only supplied once.
Without the file, BASCOM will not run.
Add on products can contain multiple files like lib, bas, pdf, etc.
Please note that LIC files are license files for the Update Wiz, but they are not the
BASCOM main licence file.
IMPORTANT
As of version 2080, the Update Wiz is phased out. This means that you need to
download and install the full setup.exe
The BASCOM-IDE has a new simplified update method. See also Help, UPDATE 214
1 - Run the installer with admin rights from CD-ROM on your new PC. The setup will
copy the license file automatically.
2 - Download the latest version of the setup.exe from https://register.mcselec.com ,
extract the setup.exe , and run setup.exe with admin rights
For the register link above, you need access(an account). This account is not the
same as for the shop/forum.
You need to create an account if you don't have one.
This procedure is explained in the help topic 'Updates 55 '
Then, after the installation, copy the license file bscavrL.DLL to the bascom-avr
application directory of the new PC.
Or let setup.exe do this for you. When you put the license file in the same directory
as setup.exe, setup will copy/install the file for you.
You may install BASCOM on multiple computers. For example on your laptop and your
desk PC. There is no limit to the number of PC's you install the software. But you may
only use one PC at the same time. Since you can only operate one PC at the same
time, this is not a real restriction.
When you install on multiple PC's and others work on these PC's at the same time as
you, you need multiple licenses!
We do not want to bother customers with anti piracy dongle and internet controlled
licenses.
2.5 Registration
The software must be registered in order to get updates. This is explained in the
Updates 55 topic.
We want to emphasize that it is important that you register soon as possible, at least
within 1 year after purchase.
When you do not register timely, the license will not be approved. This means that
you can no longer update the software.
Of course the software keeps working as is. It does not depend on the registration.
But when you need support, we check if you use an actual version.
III
BASCOM IDE 63
3 BASCOM IDE
3.1 Running BASCOM-AVR
After you have installed BASCOM, you will find a program entry under MCS
Electronics\BASCOM-AVR
The following window will appear. (If this is your first run, the edit window will be
empty.)
The most-recently opened file will be loaded automatically. Like most Windows
programs, there is a menu and a toolbar. The toolbar can be customized. To do this,
place the mouse cursor right beside the 'Help' menu.
Then right-click. You can turn on/off the toolbars or you can choose 'Customize'.
You have the option to create new Toolbars or the reset the toolbars to the default.
To place a new button on a menu bar, select the 'Commands' TAB.
In the example above, the Program Category has been selected and at the right pane,
all buttons that belong to the Program-category are shown.
You can now select a button and drag & drop it to the Toolbar. To remove a button
from the Toolbar, you drag it out of the Toolbar and release the left mouse button.
The Editor
The editor supports syntax highlighting. Code you enter can be reformatted
automatically.
When you press CTRL+J you can select a template. A template is a small piece of
code that can be inserted automatically.
When you press CTRL+J you can select a template or you can type the template
name and press CTRL+J. If there is only one template starting with that name, the
template will be inserted. Otherwise the options are shown.
When you press SHIFT and move the mouse cursor over a variable, constant or other
element you will get a tool tip with info.
In the sample above the variable 's' was selected and the tool tip shows that it is a
string with a length of 16 bytes in the modules crc8-16-32.bas
Intellisense
The editor has built in intellisense.
It is important that your code contains the $REGFILE directive like : $REGFILE =
"M88def.dat".
When you press CTRL+SPACE you get a list of statements, sub routines, functions,
labels, asm registers, etc. This list depends on the place of the cursor in the code.
- After CONFIG param (the = sign). Here you get a lost of parameter
values.
PLEASE NOTICE :
- intellisense is considered a beta function in 2079. It is subject to change.
- values for CONFIG might not be shown. This is because all these values need to be
present in the DAT files. And each processor has specific options.
Select Text
Selection of text can be done by double clicking the text, by holding SHIFT down and
moving the cursor or you can select a block of text by pressing the ALT key and
dragging the mouse cursor.
TABS
When you have loaded multiple files, each file will be shown in a TAB. The active TAB
can be closed or dragged to a new position. When a file is modified the TAB caption
will be shown in red.
SHIFT + MOUSE
When you move the mouse cursor to the TAB caption you will see the full path of the
loaded file.
When you press the SHIFT key and move the mouse cursor you can get information in
a tool tip.
For example when you hover over an indention line :
The tooltip shows info about the structure. So you know that the green line belongs
to While Unseen > 0
Custom Configuration
You can load a custom configuration file by specifying the filename as a parameter.
This allows you to run different versions of the software with different setting/option
files.
The configuration file has the XML extension. It can be found by clicking the XML data
folder link in the Help, About window.
By default bascom uses the file : \Users\<USER>\AppData\Roaming\MCS
Electronics\bascom-avrXXXX.xml
The XXXX is the version. For example 2082.
When you want to use a custom file we would recommend to store it in the bascom-
avr application folder. This way you can run multiple versions of bascom, all with their
own settings.
The name of the settings file must be provided as a parameter to BasCom. For
example to use a settings file named mysettings.xml :
bascavr.exe mysettings.xml
When BasCom is started it will check if the provided file exists and will load the
settings of that file.
If the files does not exist, the normal setting file ise used.
The reason for unique file names is that once in a while a menu option is added. That
is no problem when you update, but when you want to use the xml with an older file
you could get errors because of non existing menus.
BASCOM saves files in standard ASCII format. Therefore, if you want to load a file
that was made with another editor be sure that it is saved as an ASCII file. Most
programs allow you to export the file as a DOS or ASCII file.
Note that you can specify that BASCOM must reformat the file when it opens it with
the Options Environment 142 option. This should only be necessary when loading files
made with another editor.
The current editor window will be closed. When you have made changes to the
program, you will be asked to save the program first. You can then decide to save,
cancel, or not to save the changes you have made.
If the program was created with the File New 70 option, you will be asked to name
the file first. Use the File Save As 71 option to give the file another name.
In order to make working with a project more convenient, a number of Project options
have been added. The Project menu can be found under the File menu. The Project
menu has 4 sub menu items and a MRU list(most recent used projects).
When in project mode, the main project file will be compiled. In normal mode, the
active window is considered the project and will be compiled. The same is true for the
simulator and programmer.
A simple project explorer has been added that will list all project files. The active
project will be shown in blue. The relative path is shown.
You can add a new file to the active project. By default the INC extension will be
selected. It will be good practice to give included files the INC extension. The main
project should have the BAS extension. When you click the ADD button, a file
selection dialog will appear. You can select multiple files by using the SHIFT and/or
CTRL keys.
When you add a file to a project, it will be added to the project list. When you double
click the file in the list it will be selected. Or when it was not loaded before, it will be
loaded from disk.
That a file is part of a project collection does not mean that the file will be used or
included : you still need to $INCLUDE 559 a file that you want to use in your project.
You can also remove a file from the project. This will not remove or delete the file
from disk. The file will only be removed from the project collection.
Only one file can be the main project. This is the file that will be compiled. The main
file is colored in blue.
When you updated from a previous version, you need to reset the docking in
order to make the Project List window visible. This option you can find under Options,
Environment, IDE 142
Project New
This option will close all files and the current project and will query for a project file
name. The file will have the PRJ extension.
Project Open
This option will close all open files and let you select an existing project file. A project
file has the PRJ extension.
The PRJ file contains no code, it only contains data about the project files.
All files from the project will be loaded when they were loaded when you closed the
project.
The position and size will be set exactly as when you closed.
Project Save
This option will save all project files. It will also save other opened non-project files.
Project Close
This option will close the active project. This will end the project mode. The project
mode is started when you open a PRJ file either with OPEN or by clicking a PRJ file
from the MRU menu.
When you close bascom and you have the Option 'Auto Load All Files' checked, then
like usual, all open files will be saved and when you run bascom again, they will all be
opened. This might be confusing since you work in normal mode by default. It is
recommended to deactivate the 'Auto Load All Files' when working with projects.
In project mode, you can also drag and drop files to the IDE. If they have the BAS or
INC extension, they will be added to the project. In normal mode, the file will be
opened.
If a file is included in the code but can not be found you will get a warning.
#const a=1
#if a=2
$Include "FT800.inc"
$Include "FT800_Functions.inc"
#endif
The files ft800.inc and ft800_functions.inc are not included since the condition does
not match.
All of the files you have open, at the moment you choose exit, will be remembered.
The next time you run BASCOM, they will be opened automatically.
Option Description
Case Sensitive When selected, the case must match. Searching for PRINT will not
find pRint. With this option turned off, Print will find print, PRINT,
PRinT, etc.
Whole words only When selected, only whole words are considered. A whole word is
a word that is surrounded by spaces, or that is at the start of a
line. Looking for PRINT will find : "Print test" and "print" and
"print print". But not "printer"
Regular You can use a regular expression to find a match.
expressions
^ A circumflex at the start of the string matches the start of
a line.
$ A dollar sign at the end of the expression matches the end
of a line.
. A period matches any character.
* An asterisk after a string matches any number of
occurrences of that string followed by any characters, including
zero characters. For example, bo* matches bot, bo and boo but
not b.
+ A plus sign after a string matches any number of
occurrences of that string followed by any characters except zero
characters. For example, bo+ matches boo, and booo, but not bo
or be.
Entire scope Search from the current cursor position to the end, then search
till the start of the cursor position. This will search the entire text.
Find in Files
The Find in Files option can be used to search for text in files.
Option Description
Case Sensitive When selected, the case must match. Searching for PRINT will not
find pRint. With this option turned off, Print will find print, PRINT,
PRinT, etc.
Whole words When selected, only whole words are considered. A whole word is a
only word that is surrounded by spaces, or that is at the start of a line.
Looking for PRINT will find : "Print test" and "print" and "print
In BASCOM you can embed ASCII characters by using brackets embedded with the
ASCII code like : {065}
For example : Dim S As String : S="AB{067}"
This is the same as S="AAA"
The pop up lists shows all ASCII values and when you click the OK-button, the
brackets are added.
Both the Sub and For/Next can be folded but the Fold All Subs and Functions option,
will only fold the sub :
See Also
Edit Unfold All Code 81
See Also
Edit Fold All Subs and Functions 80
Because the encryption can not be undone, you will get this warning:
If you chose YES, the selected code will be encrypted and will result in lines like :
$CRYPT 6288E522B4A1429A6F16D639BFB7405B
$CRYPT 7ABCF89E7F817EB166E03AFF2EB64C4B
$CRYPT 645C88E996A87BF94D34726AA1B1BCCC
$CRYPT 9405555D91FA3B51DEEC4C2186F09ED1
$CRYPT 6D4790DA2ADFF09DE0DA97C594C1B074
Only the compiler can decrypt and process these lines. There is no way you can
change the $CRYPT lines back into source code !
So make a backup of your code before you use this option. Typically, it will only be
used on finished projects.
If the encrypted code contains errors, you will get error messages pointing to the
$CRYPT 529 lines.
This option is not available/enabled by default. You need to buy a license that
will unlock this option. Our sales requires your BASCOM serial number too.
This code :
For C = 0 To 100
B = A(c)
Print "Read " ; C ; ":" ; B ; "/" ; Hex(b)
Waitms 4
Next
For C = 0 To 100
B = A(c)
Print "Read " ; C ; ":" ; B ; "/" ; Hex(b)
Waitms 4
Next
Do
Input "Data to write ? (0-255)" , D
When indenting does not work you need to check your code for mistakes. For
example for endif instead of End If.
For example when using an XMEGA processor, the _XMEGA constant will be set to 1.
When the option is turned off, it will show normal like :
#if _xmega
print "XMEGA"
#else
print "NORMAL"
#endif
When then option is turned on, the editor will show it like :
#if _xmega
print "XMEGA"
#else
print "NORMAL"
#endif
When you have a lot of conditional code it is hard to see which code is executed.
When you turn the option on, it is much easier to see.
Check out this example:
In order for this option to work correct, your code should not contain syntax errors.
See Also
#IF, #ELSEIF . #ELSE 509 , Show Dead Code 84
Dead code is similar to Excluded code with the difference that excluded code is not
compiled while dead code is compiled.
Dead code is a new feature in 2080 and intended to show you which variables or code
are not used.
You can decide if the code is really dead, and need to be removed, or not.
Since this is a new feature, you should take care before deleting 'dead code'
See Also
Edit Show Excluded Code 83
When you move the mouse cursor over a pin, you will see that the pin will be colored
red. At the bottom of the window, a pin description is show. In the sample above you
will see that each line has a different color. This means that the pin has multiple
alternative functions.
The first blue colored function is as generic IO pin.
The second green colored function is RESET pin.
The third black colored function is PIN change interrupt.
A pin can have one or more functions. Some functions can be used together.
When you move the mouse cursor away, the pin will be colored blue to indicate that
you viewed this pin. For example, when you need to look at it again.
You can also search for a pin description. Enter some text and return.
Here is an example when you search the VCC pin :
When pins are found that have the search phrase in the description, the pin will be
colored blue.
By clicking 'Clear Pin HL' you can clear all colored pins.
Some chips might have multiple cases. You can select the case from the package list.
When you change from package, all pin colors will be cleared.
When you double click a pin, the pin will be colored green. Another double click will
color it red/blue.
When a pin is green, it will not be colored red/blue. The green color serves as a kind
of bookmark.
The only exception is the search function. It will make bookmarked green pins, blue
too.
Use the right mouse to access a popup menu. This menu allows you to zoom the
image to a bigger or smaller size.
When you want to search for a chip, click the 'Chip Search' button.
It will show the following window:
You can provide criteria such as 2 UARTS. All criteria are OR-ed together. This means
that when one of the criteria is met, the chip will be included in the list.
Only chips supported by BASCOM will be listed. When a chip has SRAM, and is
not supported yet, it will be in the near future since the goal is to support all chips.
When you find an error in the pin description, please send an email to support so it
can be corrected.
The viewer itself contains a tree with the topics and the actual PDF viewer.
The tree topics can be searched by right clicking on the tree. Choose 'Search' and
enter a search text.
When a topic has sub topics, the topic is bold.
When you have enabled 'Auto open Processor PDF' in Options, Environment, PDF, the
data sheet will be automatically loaded when you change the $REGFILE value.
It can be shown in a new sheet or it can replace the current PDF.
Open a PDF.
Copy selected text to the clipboard. You can not copy from protected PDF
documents.
First page.
Previous page.
Current page indicator. You can enter a page number to jump to a different
page.
Next page.
Last page.
Find text in PDF.
Zoom in.
Zoom out.
Rotate page to the left and right.
Print page(s).
When you right click in the PDF, a pop up menu with the most common options will
appear.
In Options, Environment, PDF 142 you can specify how data sheets must be
downloaded.
Data sheets can be downloaded automatic. When the $REGFILE is changed and the
PDF is not present, you will be asked if the PDF must be downloaded.
If you choose to download, it will be downloaded from the Atmel website.
When you click 'Do not show this message again' , you will not be asked anymore if
you want to download the Mega32.PDF. You will be asked to download other PDF
documents when they do not exist.
You can also download all newer PDF's from the Atmel website with the option :
Tools, PDF Update 130
When PDF's are downloaded with the UpdateWiz, they are downloaded from the MCS
Electronics website.
When there are no errors, the list will be empty. You will also be able to close the
window.
When there are errors :
You will not be able to close the window until the error is solved and the program is
checked/compiled.
The panel is dockable and by default docked to the bottom of the IDE.
When you right click the mouse inside the error panel, a menu will popup with one
option : Copy to Clipboard. All data from the error window will be copied to the
windows clipboard if you select this option.
You can click the Next-button to show another tip. Or you can close the window.
When you do not want to see the tips when BASCOM is started, you can unselect the
'Show tips at startup' option.
The project explorer window is intended to be used in project mode. Project mode is a
mode where all files belong to one project. Here you have a main file and optional
include files.
The project explorer is a dock able window. It lists all files assigned to the project.
When you double click a file, it will be opened in the editor.
- Use the ADD button to add files to the project
- Use the REMOVE button to remove files from the project. Files you remove are only
removed from the project, they are not removed from disk
- Use SET MAIN to set the main project file. The main project file is the file that is
compiled.
The code explorer shows code elements in a tree. By double clicking an element the
cursor will be set to the matching code in the editor.
You can also drag an element into the editor window.
By clicking the right mouse a pop up menu will allow you to filter out constants and
variables (registers) from the definition file.
- Constants. Both user defined constants (CONST 1045 ) and constants from the
definition file are shown.
- Declarations. Subs and Functions are both shown. Each with their own color.
- Functions. These are the user function implementations.
- Labels. When labels are used in subs and functions, the sub/functions name is listed
first.
- Macros. These are the user macro's created with MACRO 1236 .
- Subs. These are the user sub implementations.
- Variables. These are the variables from the user code and definition file. Each shown
with their own color. Locals are shown under a branch of the sub/function.
- CallStack. This is optional. Since it takes time to trace the call stack it is turned off
by default. Use right mouse click and the pop up menu to activate it.
The call stack shows a tree of the calls you make to user subs and functions. And
each sub/function also shows the user functions it calls.
When multiple calls are made, three dots are added for each additional call.
- Information. Processor, free ERAM and SRAM. Estimated $hwstack, $swstack
and $framesize.
The calculated stack settings are based on the program call tree and local
variables. This is just a tool to give you an idea about stack usage. Not taken into
account is the stack required by the assembler routines. This means that you need to
add a certain amount to the calculated values. When your code uses interrupts you
need to increase the calculated $HWSTACK by 32. Otherwise increase it by 16.
The $FRAMESIZE should have a minimum value of 24. Add a value of 16
to $SWSTACK.
Applications using AVR-DOS should use a minimum of 128 for all stacks.
A future version will also take the assembler code into account.
When the Code Explorer has the focus, pressing CTRL+F will search in the code
explorer and not in the editor.
The code explorer works in a separate thread. It will be updated a few seconds after
you have quit typing.
By making the Code Explorer window invisible, the explorer is deactivated.
Show Errors
This option deserves a warning. The option is turned off by default. It can be useful
to find errors but it can also point to errors which are not considered an error for the
compiler. The compiler has a separate parser. The parser from the IDE is a different
new parser. While in 2080 all DAT files are updated, you still can get errors which are
no real errors. You might want to report them to support. Please send a small as
possible program that will show the error.
Refresh
This option will parse the project and update the code explorer tree.
Find References
This option can find all references for an item. For example when you go to Variables,
and select a variable the option becomes enabled in the menu. After choosing this
option, the references will be added to the tree.
Now by clicking the item you will go to the point in your code where the item is
referenced/used.
Show References
This options shows a panel on the bottom of the code explorer tree. When you
activate the tooltip keeping SHIFT pressed and hovering an item in the editor, the
references panel will be updated with all references of that item. A single click on an
item in this list will set the cursor in the IDE to referred item.
When pressing SHIFT and hovering the mouse over the variable S , the tooltip will be
shown :
The references list will be updated as well. The item in bold points to the definition, in
this case the DIM S.
The following two items in the list point to the INPUT "s ", S and the Print S.
The panel can be shown or hidden using the right click menu from the explorer.
With the option Vertical Splitter, you switch between horizontal en vertical splitter.
The splitter is located near the code explorer window.
When you chose the vertical splitter option again the window will be split horizontal
again.
Notice that in order to show two different code windows you need to open the two
windows and use Tile Vertically 208 .
The following files will be created depending on the Option Compiler Settings. 135
File Description
xxx.BIN Binary file which can be programmed into the microprocessor.
xxx.DBG Debug file that is needed by the simulator.
xxx.OBJ Object file for simulating using AVR Studio. Also needed by
the internal simulator.
xxx.HEX Intel hexadecimal file, which is needed by some
programmers.
xxx.ERR Error file. Only created when errors are found.
xxx.RPT Report file.
xxx.EEP EEPROM image file
If a serious error occurs, you will receive an error message in a dialog box and the
compilation will end.
All other errors will be displayed at the bottom of the edit window, just above the
status bar.
When you click on the line with the error info, you will jump to the line that contains
At the next compilation, the error window will disappear or reappear if there are still
errors.
See also 'Syntax Check' 101 for further explanation of the Error window.
When there is an error, an error window will be made visible at the bottom of the
screen.
You can double click the error line to go to the place where the errors is found. Some
errors point to a line zero that does not exist. These errors are caused by references
Here the panel is undocked. Like most windows you can close it. But the error must
be resolved (corrected and syntax checked/recompiled) for this window can be
closed !
By double clicking the caption (top space where the name of the window is show) you
can dock it back to it's original position.
When you have closed the window and want to view it again, you can choose the
View, Error Panel option from the main menu.
See the Options Compiler Output 137 for specifying which files will be created.
Framesize The size of the frame. The frame is used for storing local
variables.
Framestart The location in memory where the frame starts.
LCD address The address that must be placed on the bus to enable the LCD
display E-line.
LCD RS The address that must be placed on the bus to enable the LCD
RS-line
LCD mode The mode the LCD display is used with. 4 bit mode or 8 bit mode.
LCD DB7-DB4 The port pins used for controlling the LCD in pin mode.
LCD E The port pin used to control the LCD enable line.
LCD RS The port pin used to control the LCD RS line.
Variable The variable name and address in memory
Constant Constants name and value
Warnings This is a list with variables that are dimensioned but not used.
Some of them
EEPROM binary This is a list of all ERAM variables with their value. It is only
image map shown when DATA 1052 lines are used to create the EEP file.
(EEPROM binary image).
When the option : Load Report in IDE, is set, the report will be shown as a text file in
the IDE.
You can simulate your programs with AVR Studio or any other Simulator available
such as ISIS or you can use the built in Simulator.
The simulator that will be used when you press F2, depends on the selection you
made in the Options Simulator TAB. The default is the built in Simulator.
To use the built in Simulator the files DBG and OBJ must be selected from the Options
Compiler Output 137 TAB.
The OBJ file is the same file that is used by the AVR Studio simulator.
The DBG file contains info about variables and many other info required to simulate a
program.
The yellow dot means that the line contains executable code. The blue arrow is visible
when you start simulating. It will point to the line that will be executed.
The Toolbar
The toolbar contains the buttons you can press to start an action.
This is the RUN button, it starts a simulation. You can also press F5. The
simulation will pause when you press the pause button. It is advised, that you step
through your code at the first debug session. When you press F8, you step through
the code line by line which is a clearer way to see what is happening.
This is the PAUSE button. Pressing this button will pause the simulation.
This is the STOP button. Pressing this button will stop the simulation. You can't
continue from this point, because all of the variables are reset. You need to press the
RUN button when you want to simulate your program again.
This is the STEP button. Pressing this button (or F8) will simulate one code line of
your BASIC program. The simulator will go to the RUN state. After the line is
executed the simulator will be in the PAUSE state. If you press F8 again, and it takes
a long time too simulate the code, press F8 again, and the simulator will go to the
pause state.
This is the STEP OVER button or SHIFT+F8). It has the same effect as the STEP
button, but sub programs are executed completely, and the simulator does not step
into the SUB program.
This is the RUN TO button. The simulator will RUN until it gets to the current line.
The line must contain executable code. Move the cursor to the desired line before
pressing the button.
The values are shown in hexadecimal format. To change a value, click the cell in the
VAL column, and type the new value. When you right click the mouse, you can choose
between the Decimal, Hexadecimal and Binary formats.
The register window will show the values by default in black. When a register value
has been changed, the color will change into red. Each time you step through the
code, all changed registers are marked blue. This way, the red colored value indicate
the registers that were changed since you last pressed F8(step code). A register that
has not been changed at all, will remain black.
This is the IO button and will show processor Input and Output registers.
The values can be changed the same way as in the Register window.
When you move from cell to cell you can view in the status bar which variable is
stored at that address.
The SRAM TAB will show internal memory and XRAM memory.
The EEPROM TAB will show the memory content of the EEPROM.
The colors work exactly the same as for the register and IO windows. Since internal
ram is cleared by the compiler at startup, you will see all values will be colored blue.
You can clear the colors by right clicking the mouse and choosing 'Clear Colors'.
The refresh variables button will refresh all variables during a run (F5). When
you use the hardware simulator, the LEDS will only update their state when you have
enabled this option. Note that using this option will slow down simulation. That is why
it is an option. When you use F8 to step through your code you do not need to turn
this option on as the variables are refreshed after each step.
When you want to simulate the processors internal timers you need to
turn this option on. Simulating the timers uses a lot of processor time, so you might
not want this option on in most cases. When you are debugging timer code it is
helpful to simulate the timers.
The simulator supports the basic timer modes. As there are many new chips with new
timer modes it is possible that the simulator does not support all modes. When you
need to simulate a timer the best option may be to use the latest version of AVR
Studio and load the BASCOM Object file.
Even AVR Studio may have some flaws, so the best option remains to test the code in
a real chip.
The TIMER simulation only simulates TIMER0 and 16 bit TIMER1. And only
counting/time modes are supported. PWM mode is not simulated.
This option allows you to use a real terminal emulator for the serial
communication simulation.
Normally the simulator send serial output to the blue window, and you can also enter
data that needs to be sent to the serial port.
When you enable the terminal option, the data is sent to the actual serial port, and
when serial data is received by the serial port, it will be shown.
This option turns on/off trace information. When enabled, a file with the
name of your project will be created with the .TRACELOG extension.
This file will contain the file, line number and source code that is executed. It is
intended to check which parts of your code execute.
VARIABLES
This section allows you to see the value of program variables. You can add variables
by double clicking in the Variable-column. A list will pop up from which you can select
the variable.
To watch an array variable, type the name of the variable with the index.
During simulation you can change the values of the variables in the Value-column,
Hex-column or Bin-column. You must press ENTER to store the changes.
To enter more variables, press the DOWN-key so a new row will become visible.
It is also possible to watch a variable by selecting it in the code window, and then
pressing enter. It will be added to the variable list automatically.
Notice that it takes time to refresh the variables. So remove variables that do not
need to be watched anymore for faster simulation speed.
LOCALS
The LOCALS window shows the variables found in a SUB or FUNCTION. Only local
variables are shown. You can not add variables in the LOCALS section.
Changing the value of local variables works the same as in the Variables TAB.
WATCH
The Watch-TAB can be used to enter an expression that will be evaluated during
simulation. When the expression is true the simulation is paused.
To enter a new expression, type the expression in the text-field below the Remove
button, and press the Add-button.
When you press the Modify-button, the current selected expression from the list will
be replaced with the current typed value in the text field.
To delete an expression, select the desired expression from the list, and press the
Remove-button.
During simulation when an expression becomes true, the expression that matches will
be selected and the Watch-TAB will be shown.
uP
This TAB shows the value of the microprocessor status register (SREG).
The software stack, hardware stack, and frame pointer values are shown. The
minimum or maximum value that occurred during simulation is also shown. When
one of these data areas enter or overlap another one, a stack or frame overflow
occurs.
This will be signaled with a pause and a check box.
Pressing the snapshot-button will save a snapshot of the current register values and
create a copy of the memory.
You will notice that the Snapshot-button will change to ‘Stop’
Now execute some code by pressing F8 and press the Snapshot-button again.
A window will pop up that will show all modified address locations.
This can help to determine which registers or memory a statement uses.
When you write an ISR (Interrupt Service Routine) with the NOSAVE option, you can
use this to determine which registers are used and then save only the modified
registers.
INTERRUPTS
This TAB shows the interrupt sources. When no ISR's are programmed all buttons will
be disabled.
When you have written an ISR (using ON INT...), the button for that interrupt will be
enabled. Only the interrupts that are used will be enabled.
The pulse generator can be used to supply pulses to the timer when it is used in
counter mode.
First select the desired pin from the pull down box. Depending on the chip one or
more pins are available. Most chips have 2 counters so there will usually be 2 input
pins.
Next, select the number of pulses and the desired delay time between the pulses,
then press the Pulse-button to generate the pulses.
The delay time is needed since other tasks must be processed as well.
The option ‘Sim timers’ must be selected when you want to simulate timers/counters.
TERMINAL Section
Under the window with the TABS you will find the terminal emulator window. It is the
dark blue area.
In your program when you use PRINT, the output will be shown in this window.
When you use INPUT in your program, you must set the focus to the terminal window
and type in the desired value.
You can also make the print output go directly to the COM port.
Check the Terminal option to enable this feature.
The terminal emulator settings will be used for the baud rate and COM port.
Any data received by the COM port will also be shown in the terminal emulator
window.
Notice that most microprocessors have only 1 UART. The UART0-TAB is used to
communicate with tis UART. The UART1-TAB need to be selected in order to view the
UART1 output, or to send data to UART1.
In version 2083, UART0-UART3 are simulated. Unavailable UARTS are not shown.
Software UARTS are not supported by the simulator. They can not be simulated.
UART0
UART0 has some specific options. When you right click the mouse you will get a
popup menu.
- Serial Input File.
This option selects a file with the SI extension. It must be named the same as your
main file but having the SI extension. The content will be used as serial data input.
Each time the processor checks UART0 it will read a byte fom the file as if it were
sent.
- Copy
This option copies data sent to the simulated terminal.
- Paste
This option sends data to the simulated terminal.
- Log to File
This option creates a file with the LOG extension. It will have the name of your main file with the
LOG extension. All data send to the simulated UART terminal will be send to the log file as well.
- Show in HEX
This option shows output in HEX format between brackets like [45] [6E] etc.
SOURCE Section
Under the Terminal section you find the Source Window.
It contains the source code of the program you are simulating. All lines that contain
executable code have a yellow point in the left margin.
You can set a breakpoint on these lines by selecting the line and pressing F9.
By holding the mouse cursor over a variable name, the value of the variable is shown
in the status bar.
If you select a variable, and press ENTER, it will be added to the Variable window.
In order to use the function keys (F8 for stepping for example), the focus must be set
to the Source Window.
In version 2083, the simulator source window will have the same fonts as the editor
window. The source window is read only. You an not change the source code in the
simulator!
A blue arrow will show the line that will be executed next.
When you right click a menu will be shown with the following options:
Option Description
Run (F5) Run code.
Step /Pause (F8) Step through code or pause running code
Step Over Step code but step over sub routines and functions..
(SHIFT+F8)
Run To (F10) Run to the current line. This line should have a yellow dot
(contains executable code)
Goto Line This option let you chose a line to jump to. Use this with care
(ALT+G). since it will jump right to the code. This means that some parts
of your code are not executed.
Clear All This option clears all breakpoints set with F9.
Breakpoints
Toggle breakpoint This option will toggle a break point. It will only work on a line
(F9) with executable code.
Find (CTRL+F) Option to find text, similar to the function in the source editor
Find Next (F3) Option to find next instance similar to the function in the source
editor.
Show Registers Option to show/hide internal registers R0-R31
Show IO Option to show/hide IO registers
Show Memory Option to show/hide memory content for SRAM and EEPROM
Log Terminal This option let you select a file name for the simulator output
output log file.
Clear EEPROM This option will reset the EEPROM content to empty(FF). This is
required sometimes since between sessions the EEPROM content
is saved in an EEP file when this option is checked in Options,
Simulator, Save EEPROM state.
And when you restart simulation the EEP content is read. This
option will clear the content.
By pressing the hardware simulation button the windows shown below will be
displayed.
The top section is a virtual LCD display. It works to display code in PIN mode, and bus
mode. For bus mode, only the 8-bit bus mode is supported by the simulator.
Below the LCD display area are LED bars which give a visual indication of the ports.
IA means PINA, IB means PINB etc. (Shows the value of the Input pins)
It depends on the kind of microprocessor you have selected, as to which ports will be
shown.
Right beside the PIN led's, there is a track bar. This bar can be used to simulate the
input voltage applied the ADC converter. Note that not all chips have an AD
converter. You can set a value for each channel by selecting the desired channel
below the track bar.
Next to the track bar is a numeric keypad. This keypad can be used to simulate the
GETKBD() function.
When you simulate the Keyboard, it is important that you press/click the keyboard
button before simulating the getkbd() line !!!
To simulate the Comparator, specify the comparator input voltage level using
Comparator IN0.
In order simulate real hardware you must compile the basmon.bas file.
Open the basmon.bas file and change the line $REGFILE = "xxx" to $REGFILE =
"2313def.dat"
Now compile the program and program the chip.
It is best to set the lock bits so the monitor does not get overwritten if you
accidentally press F4.
The real hardware simulation only works when the target micro system has a serial
port. Most have and so does the DT006.
Connect a cable between the COM port of your PC and the DT006. You probably
already have one connected. Normally it is used to send data to the terminal
emulator with the PRINT statement.
The monitor program is compiled for 19200 baud. The Options Communication
settings must be set to the same baud rate!
The same settings for the monitor program are used for the Terminal emulator, so
select the COM port, and the baud rate of 19200.
Power up or reset the DT006. It probably already is powered since you just previously
compiled the basmon.bas program and stored it in the 2313.
When you press the real hardware simulation button now the simulator will send and
receive data when a port, pin or DDR register is changed.
This allows you to simulate an attached hardware LCD display for example, or
something simpler, like an LED. In the SAMPLES dir, you will find the program DT006.
You can compile the program and press F2.
When you step through the program the LED's will change!
All statements can be simulated this way but they have to be able to use static
timing. Which means that 1-wire will not work because it depends on timing. I2C has
NOTE: It is important that when you finish your simulation sessions that you click the
button again to disable the Real hardware simulation.
When the program hangs it probably means that something went wrong with the
serial communication. The only way to escape is to press the Real hardware
The Real Hardware Simulation is a cost effective way to test attached hardware.
The refresh variables button will refresh all variables during a run(F5). When
you use the hardware simulator, the LEDS will only update their state when you have
enabled this option. Note that using this option will slow down the simulation.
Watchdog Simulation
Most AVR chips have an internal Watchdog. This Watchdog timer is clocked from an
internal oscillator. The frequency is approximately 1 MHz. Voltage and temperature
variations can have an impact on the WD timer. It is not a very precise timer. So
some tolerance is needed when you refresh/reset the WD-timer. The Simulator will
warn you when a WD overflow will occur. But only when you have enabled the WD
timer.
The status bar shows the PC (program counter) and the number of cycles. You can
reset the cycles by positioning the mouse cursor on the status bar and then right
click. You will then get a pop up menu with the option to reset the cycles. You can
also double click the cycles to reset it to 0.
You can use this to determine how much time a program statement takes.
Do not jump to a conclusion too quick, the time shown might also depend on the
value of a variable.
For example, with WAITMS var this might be obvious, but with the division of a value
the time might vary too.
Start Simulation
To start a simulation the program need to be compiled. So typically you press F7 to
compile your code. Make sure that the BIN, DBG and OBJ files are created (Options,
Compiler, Output).
When the code is compiled without errors, you can simulate your project. To do so
press F2.
By default the simulator is in STOP mode. The status bar will show PC = 0 (program
counter) and Cycles = 0. Some instructions use more cycles than other. A NOP for
example takes 1 cycle. When the processor has an oscillator running on 8 MHz, and
the 8 DIV fuse is set, it means the processor will have a clock of 1 MHz. Meaning that
each second, 1 million cycles can be executed. So you could execute a million NOP
instructions in 1 second.
The simulator however is not able to do so. The simulator reads the object data, and
decodes the data and simulates the instructions and the hardware. Also, the software
need to give time to windows otherwise the code will stall windows and your other
programs.
When the AVR is initialized, the RAM is cleared. This will takes time. So when you
press F8 the first time, you will notice that the blue arrow will be visible on the first
line of the main project. It depends on the used processor how long it will take till the
initialization is done. When done, the simulator will go into PAUSE mode.
Press F8 again to step through the code. You will notice that the blue arrow will jump
only to code with a yellow dot which indicates that the line contains executable code.
DIM statements for example are important for the compiler but do not create code.
So these statements will be skipped.
Using the BREAK instruction you can pause the simulator. This is a good way when
instead of F8, you use F5 to RUN the code. You can also set a break point using F9.
This will be visible with a red dot.
When your code uses INC modules, the simulator will show the name of the current
module.
When you access the programmer from the main menu, you will notice the submenu.
From the sub menu you can choose 'Program' or 'Manual Program'.
Program will erase and program the processor without any user intervention.
Manual Program will only show the programmer window. You can manually choose
the options to program the chip when the programmer supports it.
Auto Program also needs the option 'Auto Flash' to be set in the Programmer options
152 .
The following section applies to the Programmer window (program chip directly NOT
selected) otherwise this is not shown to the user.
“Buffer” below refers to the buffer memory that holds data to be programmed to, or
read from the chip.
By default the Flash ROM TAB is shown and the binary data is displayed.
When you have an EEPROM in your project, the EEPROM TAB will show this data too.
The most important TAB is in many cases the Lock & Fuse Bits TAB.
When you select it , the lock and fuse bits will be read.
These Lock and Fuse bits are different in almost every chip !
You can select new settings and write them to the chip. But be careful ! When you
select a wrong oscillator option , you can not program the chip anymore without
applying an external clock signal.
This is also the solution to communicate with the chip again : connect a clock pulse to
the oscillator input. You could use an output from a working micro, or a clock
generator or simple 555 chip circuit.
When you found the right settings, you can use $PROG 594 to write the proper
settings to new, un-programmed chips. To get this setting you press the 'Write PRG'
button.
After a new chip is programmed with $PROG, you should remark the line for safety
and quicker programming.
The 'Write PRG' will write the settings, read from the Microprocessor, it will NOT insert
the unsaved settings you have made manual. Thus, you must first use the 'Write XXX'
buttons to write the changed fuse bits settings to the chip, then you can use the
'Write PRG'.
Notice that the Write xxx buttons are disabled by default. Only after you have
changed a lock or fuse bit value, the corresponding button will be enabled. You must
click this button in order to apply the new Lock or Fuse bit settings.
Many new chips have an internal oscillator. The default value is in most cases 8 MHz.
But since in most cases the 'Divide by 8' option is also enabled, the oscillator value
will be 1 MHz. We suggest to change the 'Divide by 8' fuse bit so you will have a
speed of 8 MHz.
In your program you can use $crystal 530 = 8000000 then.
$crystal will only inform the compiler which oscillator speed you have selected.
This is needed for a number of statements. $crystal will NOT set the speed of the
oscillator itself.
Do not change the fuse bit that will change the RESET to a port pin. Some chips
have this option so you can use the reset pin as a normal port pin. While this is a
great option it also means you can not program the chip anymore using the ISP.
Information you type and information that the computer board sends are displayed in
the same window.
Note that you must use the same baud rate on both sides of the transmission. If you
compiled your program with the Compiler Settings at 4800 baud, you must also set
the Communication Settings to 4800 baud.
The setting for the baud rate is also reported in the report file.
NOTE: The focus MUST be on this window in order to see any data (text, etc)
sent from the processor. You will NOT see any data sent by the processor right after a
reset. You must use an external hardware reset AFTER the terminal Emulator window
is given focus in order to see the data. Using the Reset shortcut, you will not be
able to see any data because pressing the shortcut causes the Terminal emulator to
lose focus. This is different than “Hyper Terminal” which always receives data even
when the Hyper terminal window does not have focus. Use Hyper terminal if you need
to see the program output immediately after programming or reset. Or use the option
'Keep terminal emulator open' from the Options, Communication.
File Upload
Uploads the current program from the processor chip in HEX format. This option is
meant for loading the program into a monitor program for example. It will send the
File Escape
Aborts the upload to the monitor program.
File Exit
Closes terminal emulator.
Terminal Clear
Clears the terminal window.
Terminal Setting
This options will show the terminal settings so you can change them quickly.
It is the same as Options, Communication 141 .
There are 16 user definable buttons named CMD1-CMD16. When you hover the
mouse cursor above the button, the button data will be shown.
When you right click the mouse above the button, you can enter the data for the
button.
Example for CMD4:
In the sample above the data "test" will be sent. No carriage return(CR) or line feed
(LF) will be sent. If you want to send them as well you need to include them as
special characters.
Special characters are entered with their 3 digit ASCII value between brackets :
{xxx}
For example to send CR + LF you wend enter {013}{010}
See Also
Options, Communication 141
The LCD-matrix has 7x5 points. The bottom row is reserved for the cursor but can be
used.
You can select a point by clicking the left mouse button. If a cell was selected it will
be unselected.
When you are finished you can press the Ok button : a statement will be inserted in
your active program-editor window at the current cursor position. The statement
looks like this :
Deflcdchar ?,1,2,3,4,5,6,7,8
You must replace the ?-sign with a character number ranging from 0-7.
The eight bytes define how the character will appear. So they will be different
depending on the character you have drawn.
See Also
Font Editor 217
The Libraries are shown in the left pane. When you select a library, the routines that
are in the library will be shown in the right pane.
After selecting a routine in the left pane, you can DELETE it with the DELETE button..
Clicking the ADD button allows you to add an ASM routine to the library.
The COMPILE button will compile the lib into an LBX file. When an error occurs you
will get an error. By watching the content of the generated lbx file you can determine
the error.
A compiled LBX file does not contain comments and a huge amount of mnemonics are
compiled into object code. This object code is inserted at compile time of the main
BASIC program. This results in faster compilation time.
The DEMO version comes with the compiled MCS.LIB file which is named MCS.LBX.
The ASM source (MCS.LIB) is included only with the commercial edition.
With the ability to create LBX files you can create add on packages for BASCOM and
sell them. For example, the LBX files could be distributed for free, and the ASM
source could be sold.
· I2CSLAVE library
· BCCARD for communication with www.basiccard.com chipcards
See Also
$LIB 570 for writing your own libraries
You can use your favorite graphic tool to create the bitmaps and use the Graphic
converter to convert them into black and white images.
When you click the Save-button the picture will be converted into black and white.
Any non-white color will be converted into black.
The resulting file will have the BGF extension. (bascom graphics format)
You can also paste a picture from the clipboard by clicking the Paste button.
The picture can be shown with the ShowPic 1223 statement or the ShowpicE 1223
statement.
It is important that the font selection 6*8 or 8*8 match the font size in the
CONFIG GRAPHLCD. For example :
Config Graphlcd = 240x128 , Dataport = Porta , Controlport = Portc , Ce = 2 , Cd = 3
, Wr = 0 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 8
In this case you would use 8*8.
When you use your own drawing routine you can also save the pictures
uncompressed by setting the Uncompressed check box. The resulting BGF files can
not be shown with the showpic or showpicE statements anymore in that case!
Option Description
Height The height in pixels of the image.
Width The width in pixels of the image.
Font The T6963 supports 6x8 and 8x8 fonts. This is the font select that
must match the CONFIG statement. For other displays, use 8*8.
Type The size of the display. When the size is not listed, use one with the
same width.
SED Series If your display is a SEDxxxx chip, select this option.
Uncompresse Images are RLE encoded. Select this option when you do not want to
d compress the image.
Just select the plug in's you want to load/use by setting the check box.
The plug in's menu's will be loaded under the Tools Menu.
To add a button to the toolbar, right click the mouse on the menu bar, and choose
customize.
When you want to write your own plug in's, contact [email protected]
The Batch compile option was added for internal test usage. It is used by MCS to test
the provided test samples.
The following window is shown :
File Exit
Close window
Batch Compile
Compile the checked files. By default all files you added are checked. During
compilation all files that were compiled without errors are unchecked.
All results are shown in an error list at the bottom of the screen.
When you double click an item, the file will be opened by the editor.
See Also
$NOCOMP 590
There is only one option available : Check. When you click the Check-button, the MCS
server will be checked for newer versions of the PDF documents.
You need to make sure that BASCOM is allowed to contact the internet.
You also need to have port 211 open. This port is used in FTP mode to contact the
MCS server.
The MCS server is synchronizing all PDF files each day with the ATMEL server. This
means that the copy on the MCS server can be maximum 24 hours old.
The check will read all available DAT files and check if there is a reference to the PDF.
When an item is disabled(grayed) then it means there is no link to the PDF in the DAT
file.
All PDF's that are newer will have a check mark. These need an update.
You can manual unselect or select the PDF's.
In the log window at the bottom of the window you can view which files will be
downloaded.
When you want to download the selected files, press the Download-button.
This will close all PDF documents in the PDF viewer. A backup of each PDF file
downloaded will be made before it is downloaded. You need to restore it when
something goes wrong during the download(server drops the connection for
example).
When a document is downloaded, the check mark will be removed.
After all documents are downloaded, they documents are opened again in the PDF
viewer.
As of version 2077 the PDF documents are downloaded from the MCS Electronics
server.
Previously they were downloaded from Atmels webserver. When Atmel change the file
name the link is broken and you can not update the file.
To solve this all files are stored on the MCS server and each day all files are
synchronized with atmel so all files are maximum 1 day old.
As of version 2079 the PDF files are downloaded using FTP. This results in a better
performance. Just make sure port 411 is open in your firewall for outgoing
connections.
The simplest way to get the resources from your application is to create a BCS file
using the DUMP option.
Then import them with the resource editor.
The following options are available when you right click with the mouse in the
resource editor.
Option Description
Search Search for a string.
Find Next Find next occurrence.
Delete Row Delete the current row.
Add Row Add a new row for a new string.
Import This option will import the BCS file which you can create with
the $RESOURCE DUMP option.
Set Language Name Change the language name of the current language/column.
Add Language Add a new column for a new language.
Delete Language Delete the current column (language).
The resource editor is pretty simple. The only task is allow you to edit the various
strings. You can also use notepad or Excel to create the BCR file which is explained in
the $RESOURCE 599 topic.
When you choose this option the following window will appear:
When you select a new character, the current character is saved. The suggest button
will draw an image of the current selected character.
When you keep the left mouse button pressed, you can set the pixels in the grid.
When you keep the right mouse button pressed, you can clear the pixels in the grid.
When you choose the option to create a new Font, you must provide the name of the
font, the height of the font in pixels and the width of the font in pixels.
The Max ASCII is the last ASCII character value you want to use. Each character will
occupy space. So it is important that you do not choose a value that is too high and
will not be used.
When you display normal text, the maximum number is 127 so it does not make
sense to specify a value of 255.
Font8x8:
$asm
.db 1,8,8,0
.db 0,0,0,0,0,0,0,0 ;
.db 0,0,6,95,6,0,0,0 ; !
The first line contains the name of the font. With the SETFONT 1219 statement you can
select the font. Essential, this sets a data pointer to the location of the font data.
The second line ($ASM) is a directive for the internal assembler that asm code will
follow.
All other lines are data lines.
The third line contains 4 bytes: 1 (height in bytes of the font) , 8 (width in pixels of
the font), 8 (block size of the font) and a 0 which was not used before the 'truetype'
support, but used for aligning the data in memory. This because AVR object code is a
word long.
This last position is 0 by default. Except for 'TrueType' fonts. In BASCOM a TrueType
font is a font where every character can have it's own width. The letter 'i' for example
takes less space then the letter 'w'. The EADOG128 library demonstrates the
TrueType option.
In order to display TT, the code need to determine the space at the left and right of
the character. This space is then skipped and a fixed space is used between the
characters. You can replace the 0 by the width you want to use. The value 2 seems a
good one for small fonts.
Depending on the ASCII value of the character to show, the driver will located the
proper place in the table by multiplying the block size with the ASCII value. This will
be added to the start of the table address.
Now the driver will load and write a byte and thus will set 8 pixels.
The pixels are shown from top to bottom like this :
x
x
x
x
x
x
x
x
Then the next byte will be loaded and send to the lcd.
xy
xy
xy
xy
xy
xy
xy
xy
Then if the height is more than 1 byte, the next block will be loaded.
This also means that each font height must be a multiple of 8 pixels.
This restriction is only because writing a full byte is the fastest way to update an LCD.
When you nest 2 GOSUB’s you are using 4 bytes (2*2). Most
statements need HW stack too. An interrupt needs 32 bytes.
Soft Stack Specifies the size of the software stack.
Remove (or remark) the below lines from the file and save the file.
[$RootKey$\Languages\Language Services\Basic]
[$RootKey$\AutomationProperties\TextEditor\Basic]
Size warning Select to generate a warning when the code size exceeds the Flash
ROM size.
Swap words This option will swap the bytes of the object code words. Useful for
some programmers. Should be disabled for most programmers.
Some AVR chips have the option to specify different data bits and different stop bits
and parity.
Note that these settings must match the settings of the terminal emulator. In the
simulator the output is always shown correct since the baud rate is not taken in
consideration during simulation. With real hardware when you print data at 9600
baud, the terminal emulator will show weird characters when not set to the same
baud rate, in this example, to 9600 baud.
It is advised to use the various CONFIG 757 commands in your source code. It make
more clear in the source code which pins are used.
It is advised to use the CONFIG LCD command. This way the settings are stored in
your source code and not in the separate CFG file.
Item Description
Comport The communication port of your PC that you use for the terminal
emulator.
Baud rate The baud rate to use.
Parity Parity, default None.
Data bits Number of data bits, default 8.
Stop bits Number of stop bits, default 1.
Handshake The handshake used, default is none.
Emulation Emulation used, default TTY and VT100.
Font Font type and color used by the emulator.
Back color Background color of the terminal emulator.
Keep TE open This option will keep the terminal emulator COM port open when you
close the window or move the focus away. Some serial programmers
which close the COM port when they need to program, will not work
in this mode when they use the same COM port.
Use Existing When you select this option, you will get a list with the available COM
COM ports ports only at places you can select a COM port.
When you insert an USB virtual COM port, it will be added to list
automatically. Removing virtual COM ports will also update the
available COM port list.
When you do not select this option you get a list with COM1-COM255.
Note that the baud rate of the terminal emulator and the baud rate setting of the
compiler options 138 , must be the same in order to work correctly.
The reason why you can specify them both to be different is that you can use the
terminal emulator for other purposes too.
OPTION DESCRIPTION
Auto Indent When you press return, the cursor is set to the next line at
the current column position.
Don't change case When set, the reformat won't change the case of the line
after you have edited it.
Indention
When indention lines are drawn, you can select the color of each level. The default is
gray.
When you move the mouse over an indention line, the tooltip will show the start of
the structure.
The sample above shows the info for the green indention line.
Obvious when the code fits into the screen, it is simple to see that the green line
belongs to #IF _XMEGA. But when there is a lot of code in the editor, and you can not
see all of the code, it can be a big help.
Code Folding
This option activates so called Code Folding. Code Folding allows you to hide/fold
portions of your code.
When folding code, all child code (all levels under the node) will be folded/unfolded as
well.
A node is a point in your code that is part of a structure like sub/end sub , function/
end function, for/next, do/loop, while/wend
When you press F11, the current SUB or FUNCTION will be folded/unfolded. The
Editor menu also has options to fold/unfold all code.
Drawing indention lines may result in slower screen painting. Errors in your code
might result in wrong painting of the lines.
OPTION DESCRIPTION
Background The background color of the editor window. Choose a color that is the
color same as your background. In a white room, using white would be best
for your eyes.
Keyword The color of the reserved words. Default Navy.
color
The keywords can be displayed in bold too.
Comment The color of comment. Default green.
color
Comment can be shown in Italic too.
ASM color Color to use for ASM statements. Default purple.
HW registers The color to use for the hardware registers/ports. Default maroon.
color
String colorThe color to use for string constants : "test"
Variable color
The color to use for variables. Default is black.
User Function
The color to use for user SUBS and FUNCTIONS. The default is fuchsia
Color .
Editor font Click on this button to select another font for the editor window. A
good choice is Fixedsys.
Show Hidden This option will show special characters in the editor. Special
Characters characters are characters such as CR and LF. And all characters with
an ASCII value above 127. You can use this option to find odd
characters in your code which could result in compilation errors.
OPTION DESCRIPTION
Tool tips Show tool tips when hovering over form elements such as buttons.
File Click to select a directory where your program files are stored. By default
location Windows will use the My Documents path.
Sample Click to select the folder where the SAMPLE files are located. They are
Location either stored in a sub folder of the application, or in a folder under the
Documents\MCS Electronics\BASCOM-AVR\samples folder
Use HTML Chose between old help and CHM Help. CHM is the preferred help file.
Help Since HLP is not supported under Vista, it is advised to switch to CHM/
HTML Help. The HLP file is not distributed but using the UpdateWiz you
can still download the HLP file.
Code hints Select this option to enable code hints. You can get code hints after you
have typed a statement that is recognized as a valid statement or
function.
Hint Time The delay time in mS before a code hint will be shown.
Hint Color The background color of the hints.
Allow Select this option when you want to run multiple instances of BASCOM.
multiple When not enabled, running a second copy will terminate the first
Instances instance.
Auto save The code is always saved when you compile. When you select this
on compile option, the code is saved under the same name. When this option is not
selected, you will be prompted for a new filename.
Auto Check this option to make periodic backups. When checked you can
backup specify the backup time in minutes. The file will also be saved when you
press the compiler button.
History This option creates a history backup of the source file each time you save
Backup it. When you Compile code, the active source will be saved too before
compilation and hence it will create a history file as well.
The history file is a version of the code saved in the HISTORY folder. This
folder is located in the same folder as the main project.
The file will be named <FILE>~yymmdd hhnnss.hst
Where <FILE> is the original file name, and yymmdd is the date and
hhNNss is the time.
Auto load When enabled, this option will load the last file that was open into the
last file editor, when you start BASCOM.
Auto load When enabled, this option will load all files that were open when you
all files closed BASCOM.
Check for Select this option to check for updates when the IDE is started.
updates
Show This option will enable/disable the TAB for multiple windows. While the
TABS TAB is convenient to switch between windows, it will also consume
screen space. You can disable this option to get more screen space.
Reset This will reset the dockable windows to the default position.
docking
Search This option can enable/disable the auto completion in the Find dialog.
Find Auto When it is active and you type some text, based on historical input, the
Complete text will be completed. This is not always desired and can be disabled.
Language This will set the language in the main menu to the selected language.
Not all listed languages are supported/translated yet.
Clear Do Some messages have a 'do not ask again' option. To reset this and thus
not Ask show the messages, you can click this button.
Use New When compiling a project, the main file is searched for some settings like
Method $regfile, $hwstack, $swstack and $framesize. This information is passed
to the compiler DLL.
This search is fast but simple : it will not work correct when using
directives such as :
#IF someConditon
$regfile = "m88def.dat"
#ELSE
$regfile = "m2650def.dat"
#ENDIF
The parser used for the code explorer is capable to get the information
but requires more time because it will parse the entire project. So you
have the option to chose the old method(default) or the new method. It
is good practice to start your project with the required info :
$regfile = "yourmicro.dat"
$hwstack=32 '
$swstack=32
$framesize=32
Code The Code explorer will put all elements in one tree without file names.
Explorer Setting this option however will create a tree of elements with all file
with names under a branch named 'Inc Files'.
separate
INC files
Code explorer with separate inc files Code explorer without separate inc
files
OPTION DESCRIPTION
Auto open processor This option will automatic load the PDF of the selected micro
PDF processor in the PDF viewer. The $REGFILE value
determines which data sheet is loaded. The PDF must exist
otherwise it can not be loaded.
Open PDF in new sheet Every time you change the value of the $REGFILE the
processor PDF can be shown in the same sheet, or a new
sheet can be shown with the PDF. A good option in case
your project uses multiple processors.
Auto save/load project Load all PDF's when the project is opened that were loaded
PDF when the project was closed.
Custom ShortCuts
When you want to define your own short cuts you can create an ini file named
shortcuts.ini.
This ini file is just a text file you can create with notepad. Store this file in the
BASCOM application folder.
To enable the user shortcuts you need to make an option named : ENABLED with the
value -1.
EditPaste=CTRL+V
EditFind=CTRL+F
EditFindNext=F3
EditReplace=CTRL+R
EditGoto=CTRL+G
EditIndent=SHIFT+CTRL+I
EditUnIndent=SHIFT+CTRL+U
EditUnremarkBlock=CTRL+M
EditProperIndent=CTRL+ALT+P
Compile=F7
SyntaxCheck=CTRL+F7
ProgramShowResult=CTRL+W
ProgramSimulate=F2
ProgramSendToChip=F4
ProgramResetChip=SHIFT+F4
TerminalEmulator=CTRL+T
LCD_Designer=CTRL+L
LibManager=CTRL+I
BatchCompile=CTRL+B
ShowDevMng=CTRL+D
OPTION DESCRIPTION
Use integrated Set this option to use BASCOM’s simulator. You can also use
simulator AVR Studio by clearing this option.
Run simulator after Run the selected simulator after a successful compilation.
compilation
Program The path with the program name of the external simulator.
Parameter The parameter to pass to the program. {FILE}.OBJ will
supply the name of the current program with the extension .
OBJ to the simulator.
OPTION DESCRIPTION
Programmer Select one from the list.
Play sound Name of a WAV file to be played when programming is finished.
Set focus to When the chip is programmed, the terminal emulator will be shown
terminal
emulator
Then save the file. The file must reside in the bascom-avr
application folder. The file is loaded when you run bascom. It will
depend on your PC hardware if the baud you use will actually
work.
Other
Use HEX Select when a HEX file must be sent instead of the bin file.
Program The program to execute. This is your programmer software.
Parameter The optional parameter that the program might need.
Use {CHIP} to insert the official device name of the chip. The
See Also
Supported programmers 154
PROGGY 176
FLIP 177
USBASP 183
STK600 184
ARDUINO 187
For those who don't have this kit and the programmer the following schematic shows
how to make your own programmer:
The dongle has a chip with no identification but since the schematic is all over the
web, it is included. MCS also sells a STK200 compatible programmer.
If the parallel port is disconnected from the interface and left floating, the '244 latch
outputs will waver, causing your micro controller to randomly reset during operation.
The simple addition of a 100K pull-up resistor between pin 1 and 20 of the latch, and
another between pin 19 and 20, will eliminate this problem. You'll then have HIGH-Z
on the latch outputs when the cable is disconnected (as well as when it's connected
and you aren't programming), so you can use the MOSI etc. pins for I/O.
Select the programmer from The Option Programmer menu or right click on the
button to show the Option Programmer 152 menu
THIS PROGRAMMED IS MARKED FOR REMOVAL. Send a note to support if you use it.
They produce professional programmers too. This simple programmer you can make
yourself within 10 minutes.
What you need is a DB25 centronics male connector, a flat cable and a connector that
can be connected to the target MCU board.
DB25 pin Target MCU pin Target MCU Target MCU pin 8515 DT104
(AT90S8535) M103/M128
2, D0 MOSI, pin 6 PE.0, 2 MOSI, 6 J5, pin 4
4, D2 RESET, pin 9 RESET, 20 RESET, 9 J5, pin 8
5, D3 CLOCK, pin 8 PB.1,11 CLOCK, 8 J5, pin 6
11, BUSY MISO, pin 7 PE.1, 3 MISO, 7 J5, pin 5
18-25,GND GROUND GROUND GND,20 J5, pin 1
The MCU pin numbers are shown for an 8535! And 8515
Note that 18-25 means pins 18,19,20,21,22,23,24 and 25
You can use a small resistor of 100-220 ohm in series with the D0, D2 and D3 line in
order not to short circuit your LPT port in the event the MCU pins are high.
Tip : when testing programmers etc. on the LPT it is best to buy an I/O card for
your PC that has a LPT port. This way you don’t destroy your LPT port that is on the
motherboard in the event you make a mistake!
The following picture shows the connections to make. Both a setup for the DT104 and
stand-alone PCB are shown.
I have been having spurious success with the simple cable programmer from Sample
Electronics for the AVR series.
After resorting to hooking up the CRO I have figured it out (I think). When trying to
identify the chip, no response on the MISO pin indicates that the Programming Enable
command has not been correctly received by the target.
The SCK line Mark/Space times were okay but it looked a bit sad with a slow rise time
but a rapid fall time. So I initially tried to improve the rise
time with a pull-up. No change ie still could not identify chip. I was about to add some
buffers when I came across an Atmel app note for their serial programmer "During
this first phase of the programming cycle, keeping the SCK line free from pulses is
critical, as pulses will cause the target AVR to loose synchronization with the
programmer. When synchronization is lost, the only means of regaining
synchronization is to release the RESET line for more than 100ms."
I have added a 100pF cap from SCK to GND and works first time every time now. The
SCK rise time is still sad but there must have been enough noise to corrupt the initial
command despite using a 600mm shielded cable.
The programmer supports the most popular 20 and 40 pins AVR chips.
On the Programmer Options tab you must select this programmer and the COM port it
is connected to.
On the Monitor Options tab you must specify the upload speed of 9600, Monitor delay
of 1 and Prefix delay 1.
When you press the Program button the Terminal Emulator screen will pop up:
THIS PROGRAMMED IS MARKED FOR REMOVAL. Send a note to support if you use it.
The content :
; BASE= $hexaddress
; RESET=same as MOSI
; MISO=same as MOSI
; When 128 is specified for the bit, NOT 128 will be written(127)
[FUTURELEC]
;tested and ok
BASE=$378
MOSI=BASE+2,1,inverted
CLOCK=BASE,1
RESET=BASE,2
MISO=BASE+1,64
[sample]
;tested and ok
BASE=$378
MOSI=BASE,1
CLOCK=BASE,8
RESET=BASE,4
MISO=BASE+1,128,INVERTED
[stk200]
;tested and ok
BASE=$378
MOSI=BASE,32
CLOCK=BASE,16
RESET=BASE,128
MISO=BASE+1,64
[stk200]
The LPT base address must be specified. For LPT1 this is in most cases $378. $ means
hexadecimal.
The pins that are needed are MOSI, CLOCK, RESET and MISO.
Add the pin name MOSI =
After the pin name add the address of the register. For the STK200 the data lines are
used so BASE must be specified. After the address of the register, specify the bit
number value to set the pin high. Pin 0 will be 1, pin 1 would be 2, pin 2 would be 4
etc. D5 is used for the stk so we specify 32.
The following picture shows the LPT connector and the relation of the pins to the LPT
registers.
Always add your entry to the bottom of the file and email the settings to
[email protected] so it can be added to BASCOM.
That is why you have to specify the file location of the stk500.exe
The normal STK500 support will erase, and program the flash.
The STK500.EXE supports a number of Atmel programmers which all use the STK500
V1 or V2 protocol.
For the AVR ISP mkII, you need to supply the serial number of the USB programmer.
The USB port will be used then instead of the serial port.
You can also use the native driver which does not use/need the stk500.exe
If you select this programmer, you will see the following window when you launch the
programmer with F4(manual program)
When the source code is compiled and the BIN file exists, it is loaded automatic into
the buffer.
When an EEPROM image file exists (EEP), it is loaded too into the EEPROM buffer.
When it does not exist you will see a warning which you can ignore.
When the target device is not read yet, the CHIP will be unidentified which is marked
as ???.
In the status bar you can see the loaded file, and the size of the file. Notice that
16000 will be shown as 16 KB.
You can select the EEPROM-TAB to view the EEPROM image. Memory locations can be
altered. Select a cell, and type a new value. Then press ENTER to confirm. You can
immediately see the new value.
When you select the Lock and Fusebits-TAB the lock and fuse bits will be read.
As you can see that as soon as the target chip is determined, the chip name is shown
under the tool bar.
The FLASH size and EEPROM size are shown also.
As soon as you alter a lock or fuse bit, the corresponding Write-button will be
enabled. You need to click it to write the new value. The lock and fuse bits are read
again so you can see if it worked out. The lock and fuse bits shown will depend on the
used chip. Every chip has different fuse bits. Some fuse bits can not be altered via the
serial programming method. The native stk500 driver uses the serial programming
method. Some fuse bits require the parallel or high voltage programming method. For
example the fuse bit 'enable serial downloading' can not be changed with the serial
programming method.
Fuse bits of interest are : the clock divider and the oscillator fuse bits. When you
select a wrong oscillator fuse bit (for example you select an external oscillator) the
chip will not work anymore till you connect such an external oscillator! Of course a
simple 555 chip can generate a clock signal you can use to 'wake' a locked chip.
Once you have all settings right, you can press the 'Write PRG' button which will
insert some code into your program at the current cursor position. This is the $PROG
directive.
For example : $prog &HFF , &HED , &HD0 , &HFF
When you compile your program with the $PROG 594 directive it will generate a PRG
file with the lock and fuse bit settings.
If you then auto program(see later) a chip, it will use these settings.
$PROG is great to load the right lock and fuse bits into a new chip. But be careful : do
not enable $PROG till you are done with development. Otherwise programming will be
slow because of the extra reading and writing steps.
Option Description
File
Exit Close programmer.
Buffer
Clear Clear buffer. Will put a value of 255 (FF hex) into each memory
location. When the FLASH-TAB has the focus, the FLASH buffer
will be cleared. When the EEPROM-TAB has the focus, the
EEPROM buffer will be cleared. 255 is the value of an empty
memory location.
Load from File This will shown an open file dialog so you can select a binary
file (BIN)
The file is loaded into the buffer.
Save to File Will save the current buffer to a file.
Reload Reloads the buffer from the file image.
Chip
Identify Will attempt to read the signature of the chip. When the
signature is unknown(no DAT file available) or there is no chip
or other error, you will get an error. Otherwise the chip name
will be shown.
Write buffer to chip This will write the active buffer(FLASH or EEPROM) into the
chip.
Read chipcode When the chip lock bit is not set you can read the FLASH or
EEPROM into the buffer.
Blank check Check if the chip FLASH or EEPROM is empty.
Erase Erases the chip FLASH. It depends on the fusebits if the
EEPROM is erased too. Normally the EEPROM is erased too but
some chip have a fuse bit to preserve EEPROM when erasing
the chip.
A chip MUST be erased before it can be programmed.
Verify Checks if the buffer matches the chip FLASH or EEPROM.
Auto program This will eraser, and program the FLASH and EEPROM and
if $PROG is used, it will set the lock and fusebits too.
Under Options, you can find a setting to change the clock frequency.
The clock frequency should not be higher then a quarter of the oscillator
frequency.
This means that a chip with an internal 8 MHz oscillator which has the 8-divider fuse
enabled, will have a clock frequency of 1 Mhz.
The programming clock may not exceed 250 KHz in this case.
STK500 board
When using the STK500 board, you can change the target voltage and the reference
voltage. In 2081 you can also change the board oscillator frequency.
The BOARD menu has a sub menu named STK500. This sub menu has a few options :
- Read Settings : you should do this first
- Vtarget : this is the target voltage. Make sure the chip can handle the voltage you
enter
When you have selected the Lawicel Boot loader from the Options, Programmer, the
following window will appear when you press F4.
As the window suggests, press the reset button on the activity board or StAVeR, and
the chip will be programmed. This is visible by a second wind that will be shown
during programming.
When an error occurs, you will get an error message and you can clock the Cancel
button in order to return to the Editor.
THIS PROGRAMMED IS MARKED FOR REMOVAL. Send a note to support if you use it.
The old ICP910 does not support Mega chips. Only a modified version of the AVR910.
ASM supports Universal commands so all chips can be programmed.
The new AVRISP from Atmel that can be used with AVR Studio, is not compatible! You
need to select STK500 programmer 160 because the new AVRISP programmer from
Atmel, uses the STK500 protocol.
When you do not want to use the default baud rate that AVR910 is using, you can
edit the file bascavr.ini from the Windows directory.
Add the section [AVRISP]
Then add: COM=19200,n,8,1
This is the default. When you made your own dongle, you can increase the baud rate
You need to save the file and restart BASCOM before the settings will be in effect.
When you connect the programmer, Windows (98, ME, 2000, XP) will recognize the
new device automatically.
Select 'No, not this time' and click Next, as there is no driver at Microsoft's web.
You need to select 'Install from a list or specific location' and click Next.
You can specify the path of the USB driver. This is by default :
Use the Browse-button to select it, or a different location, depending on your installation.
As the driver is not certified by Micros ft, you will see the following window:
You need to select 'Continue Anyway'. A restore point will be made if your OS
supports this and the driver will be installed.
After installation you must see the following window :
After you press Finish you will see Windows can use the programmer :
In BASCOM , Options, Programmer you can select the new programmer now.
When you use other USB devices that use the FTDI drivers, there might occur a
problem. Manual install the drivers of these other devices, then install the USB-ISP
driver.
USB-ISP on VISTA
For Vista and Vista 64, please follow the this installation description.
When connection the ISP-PROG I to your PC the following window will show up. Here
I have to select the top selection: Locate and Install driver software (recommended)
Vista starts it search for the driver and will come finally with the question to Insert
the driver disk.
As we have no driver CD, you have to select: I don’t have the disc. Show me other options
Now we select the Browse selection and locate the driver folder.
As Vista 64 only allows certified drivers the following message will pop-up.
Just select Install this driver software anyway and Vista 64 will now start with installing the
driver. Be patient as it depends on your system configuration how long it will take.
Finally Vista 64 will tell you that the driver is installed. To check your configuration you can go to
your device manager to see if it is there.
BOOTSIZE
You can choose the boot size which is 1024 for the BASCOM $LOADER example.
Since this space is used from the normal flash memory, it means your application has
1024 less words for the main application. (A word is 2 byte, so 2KB less)
The XMEGA has a separate boot space so for Xmega you can set the value to 0.
RESET
The boot loader is started when the chip is reset. Thus you need to reset the chip
after you have pressed F4(program). But when you have connected the DTR line to
the chip reset (with a MAX232 buffer) you can reset the chip automatically. You do
need to set the 'Reset via DTR' option then. You can also chose to use the RTS line.
When your program does not use the boot vector or needs a special sequence to
activate the loader, you can chose the soft reset. To send ASCII characters you can
embed them between brackets {}. For example {065} will be sent as the character A
or byte with value 65.
CLOSE
By choosing 'Close programmer window when ready' the window will be closed when
the loader returns 0.
In all other cases it will remain opened so you can look at a possible cause.
EEP
If an EEP (EEPROM image file) exists, the loader can send this file instead of the flash
binary file. If you enable this option, you will be asked if you want to send the EEP
instead of the BIN file.
As you can see the loader sends a byte with value of 123.
You need to reset the chip, and then you will see that the loader returned 123 which
means it received the value.
It will start the upload and you see a progress bar. After the loader is ready, you see
a finish code of 0.
A finish code of 0 means that all wend well.
Other finish codes will not close the window even if this option is enabled.
You need to manual close the window then.
ERROR CODES
-6001 - Bad format in file name
-6002 - file not found
-6003 - file not found in folder
-6004 - folder not found
-6005 - canceled
-6006 - time out
-6007 - protocol error
-6008 - too many errors
-6009 - block sequence error
-6016 - session aborted
The most likely error is -6006 when the bootloader is not present or does not respond
timely after the initial handshake. Increase the $timeout in the boot loader in that
case.
3.59.1.11 PROGGY
PROGGY is a popular USB programmer written by Red_Mamba.
You need to install it and make sure that the registry key :
HKEY_CURRENT_USER\Software\Red_Mamba\Atmel programator exists with
the parameter : InstallPath
3.59.1.12 FLIP
FLIP is a free USB bootloader from Atmel. With FLIP you can program an AVR without
additional (ISP) programmer hardware.
Because it is a USB bootloader it only work with AVR with built in USB functionality.
FLIP is supported by the BASCOM-IDE so you can use it direct by pressing the
Program Chip (F4) button and download a HEX file.
As with other programmers, you press F4 to program the HEX file into the chip. A
small window will become visible.
In this case, you try to program a chip which is not supported by FLIP. The Mega88 is
not an USB chip so the error makes sense.
If you are using an USB AVR you could get following dialog box:
This dialog informs you about a missing DFU device and/or the device is not in boot
loader mode:
In this case, the boot loader is not found. You can run the boot loader by following
the sequence from the dialog box.
In order to make this work, the HWB (Hardware Bootloader Button) and RST (Reset
Button) input both need a small switch to ground.
When HWB is pressed(low) during a reset, the boot loader will be executed.
Abbreviations:
Just connect the USB Cable during pressing Switch0 SW0 on the XMEGA-A3BU
Xplained board
Hit OK button then the XMEGA will be programmed.
$regfile = "XM256A3BUDEF.DAT"
$crystal = 32000000 '32MHz
$hwstack = 64
$swstack = 40
$framesize = 80
Config P o r t e. 4 = Output
B a c k l i g h t A l i a s P o r t e. 4 'LCD Backlight
Config P o r t r. 0 = Output
Led0 A l i a s P o r t r. 0 'LED 0
Config P o r t r. 1 = Output
Led1 A l i a s P o r t r. 1 'LED 1
Do
Waitms 500
Reset Led0
S e t Led1
Waitms 500
S e t Led0
Reset Led1
Loop
End 'end program
You can also create a command file for that task like: flipDLLcopy.cmd to copy these
files.
The content of the command file :
The last line pauses so you can view the result. Notice the . (dot) that will copy the
file to the current directory, which is the reason that you need to run this file from the
BASCOM application directory.
You also need to adapt the version of FLIP in the command file.
In order to use BASCOM's FLIP support, you must have running FLIP successfully first
!
Here is a good tip from a user :
In the ...\Atmel\Flip 3.3.1\USB dir I have also detected the missing .inf File.
After installing this, Windows detects the AT90USB162 and Flip can connect the
device.
When programming XMEGA chips the interface for the fuse bits will be different. See
STK600 184 programmer for a description.
The default clock is 125 KHz. This because most/all chips ship with a clock frequency
of 1 MHz. And since the clock frequency maximum is a quarter of the oscillator
frequency, the default is 125 KHz, low enough to be able to program all chips. Once
your chip runs at say 8 MHz, you can select 2 MHz as the maximum.
You must have the LIBSUSB 195 drivers installed on your PC. Without it, it will not
work.
Options
In the Configuration options you can adjust the clock speed and the timeout of the
USB.
When you are using USB 1.1 and a lot of devices that generate a lot of USB traffic,
you might need to increase the default timeout of 100 (msec).
XMEGA
When used in PDI mode, take care about the following for some of the processors:
JTAG is activated by default which preventing from using the PDI because both interfaced
share the same pins. In this case :
1 - Disable the JTAG before using the PDI. > You need a JTAG programmer
2 - Use a 47Kohm resistor to Pull down the clock pin to ground which allow you to have
both JTAG and PDI working simultaneously.
BASCOM will use the KamProg software to either automatic or manual program the
chip.
The Kamprog programmer works on Vista32 and Vista64 and requires no special
drivers. It has also been tested with Win7 and Win8 and Win8.1
When you use Auto program, you will see a small progress window while the
processor is programmed.
When you chose manual program, you will see a familiar window, known from USB-
ISP.
When the source code is compiled and the BIN file exists, it is loaded automatic into
the buffer.
When an EEPROM image file exists (EEP), it is loaded too into the EEPROM buffer.
When it does not exist you will see a warning which you can ignore.
When the target device is not read yet, the CHIP will be unidentified which is marked
as ???.
In the status bar you can see the loaded file, and the size of the file. Notice that
16000 will be shown as 16 KB.
You can select the EEPROM-TAB to view the EEPROM image. Memory locations can be
altered. Select a cell, and type a new value. Then press ENTER to confirm. You can
immediately see the new value.
When you select the Lock and Fusebits-TAB the lock and fuse bits will be read.
As soon the target chip is determined, the chip name is shown under the tool bar.
The FLASH size and EEPROM size are shown too.
When you alter a lock or fuse bit, the corresponding Write-button will be enabled. You
need to click it to write the new value. The lock and fuse bits are read again so you
can see if it worked out.
The lock and fuse bits shown will depend on the used chip. Every chip has different
fuse bits. Some fuse bits can not be altered via the serial programming method. For
example the fuse bit 'enable serial downloading' can not be changed using the serial
programming method.
Fuse bits of interest are : the clock divider and the oscillator fuse bits. When you
select a wrong oscillator fuse bit (for example you select an external oscillator) the
chip can not programmed anymore until you connect such an external oscillator! Of
course a simple 555 chip can generate a clock signal you can use to 'wake' a locked
chip.
Once you have all settings right, you can press the 'Write PRG' button which will
insert some code into your program at the current cursor position. This is the $PROG
directive.
For example : $prog &HFF , &HED , &HD0 , &HFF
When you compile your program with the $PROG 594 directive it will generate a PRG
file with the lock and fuse bit settings.
If you then auto program(see later) a chip, it will use these settings.
$PROG is great to load the right lock and fuse bits into a new chip. But be careful : do
not enable $PROG till you are done with development. Otherwise programming will be
slow because of the extra reading and writing steps.
Option Description
File
Exit Close programmer.
Buffer
Clear Clear buffer. Will put a value of 255 (FF hex) into each memory
location. When the FLASH-TAB has the focus, the FLASH buffer
will be cleared. When the EEPROM-TAB has the focus, the
EEPROM buffer will be cleared. 255 is the value of an empty
memory location.
Load from File This will shown an open file dialog so you can select a binary
file (BIN)
The file is loaded into the buffer.
Save to File Will save the current buffer to a file.
Reload Reloads the buffer from the file image.
Chip
Identify Will attempt to read the signature of the chip. When the
signature is unknown(no DAT file available) or there is no chip
or other error, you will get an error. Otherwise the chip name
will be shown.
Write buffer to chip This will write the active buffer(FLASH or EEPROM) into the
chip.
Read chipcode When the chip lock bit is not set you can read the FLASH or
EEPROM into the buffer.
Blank check Check if the chip FLASH or EEPROM is empty.
Erase Erases the chip FLASH. It depends on the fusebits if the
EEPROM is erased too. Normally the EEPROM is erased too but
some chip have a fuse bit to preserve EEPROM when erasing
the chip.
A chip MUST be erased before it can be programmed.
Verify Checks if the buffer matches the chip FLASH or EEPROM.
Auto program This will eraser, and program the FLASH and EEPROM and
if $PROG is used, it will set the lock and fusebits too.
In the toolbar you can also alter the ISP clock frequency.
The clock frequency should not be higher then a quarter of the oscillator
frequency.
This means that a chip with an internal 8 MHz oscillator which has the 8-divider fuse
enabled, will have a clock frequency of 1 Mhz.
The programming clock may not exceed 250 KHz in that case.
3.59.1.15 USBASP
The USBASP is a popular USB programmer created by Thomas Fischl
The programmer uses a Mega8 or other AVR chip as an USB device.
You can find the programmer at Thomas website : http://www.fischl.de/usbasp
Make sure when programming the fuse and lock bits that the selected clock frequency
is not too high. The clock frequency of the ISP programmer should be less then one
quarter of the oscillator frequency. When your micro is running at 8 MHz, you can
3.59.1.16 STK600
The STK600 is a development board from Atmel. It uses a similar protocol as the
STK500 and has an integrated USB programmer on board.
The programmer can be connected with a cable to the STK600 board itself, but also
to an external board.
The STK600 replaces the STK500 and is advised for XMEGA development. For regular
AVR chips we would recommend the STK500.
The STK600 has actual 3 different programmers on board : ISP, PDI and JTAG. the
ISP/PDI protocols are combined and placed on one connector.
When programming XMEGA chips, the BASCOM programmers will automatic switch to
the PDI protocol. The ISP protocol can not be used with XMEGA chips.
For other chips, (non-xmega), the ISP protocol will be used.
There are affordable PDI programmers available.
The following description is also true for the AVRISP/mkII programmer which also
supports the PDI protocol.
In order to use the STK600 protocol you need to have LIBSUSB 195 installed.
Identification
The BASCOM programmers always try to identify the chip before an action is
performed. This is needed to check the size and to check if your program is intended
for the selected chip.
It would not be a good idea for example to program an attiny13 with xmega128a1
code.
When you chose manual programming, you will get the following window:
As you can see, the binary image is loaded and if an EEPROM EEP binary image was
available it would have been loaded too.
When you click the Identify button, the programmer will read the device id. The same
will happen for any other action you chose.
The Device ID is now read and you can see the ATXMEGA128A1 is detected.
The programmer has the same options as the STK500 programmer. Only the lock and
fuse byte differ for the Xmega.
When you select the Lock and Fuse bits, you will get a similar screen:
The XMEGA has one lock byte and 6 fuse byes named FUSE0-FUSE5.
Not all fuse bytes are used. The options depend on the XMEGA chip you use.
In the screen shot from above you can see that under the FUSE1 section, the
'Watchdog Window Configuration' is colored red.
When you change an option and move focus or enter, a change will result in the
option to be shown in red.
When you have selected all values you can select the WRITE button to write the lock
and fuse bytes.
After this the values will be read again and updated.
The WRITE PRG button will insert a $PROG directive into your code with all lock and
fuse bytes.
A description of the fuse bytes you can find in the PDF of the processor.
3.59.1.17 ARDUINO
The ARDUINO is a hardware platform based on AVR processors. ARDUINO boards/
chips are programmed with a bootloader. This bootloader is the old STK500 protocol,
not longer supported by Atmel in Studio. There are various programmers for
ARDUINO, AVRDUDE is probably the most versatile.
BASCOM also supports the ARDUINO/STK500 v1 protocol. the DTR/RTS lines are used
to reset the board.
You can program/read flash/EEPROM but you can not read/write fuse/lock bytes. The
STK500 bootloader for ARDUINO does not support this.
Under options you only need to select the programmer, and the COM port. Since an
FTDI chip is used on most ARDUINO boards, this is a virtual COM port. Only present
when the USB cable is connected to your PC.
Select 57600 baud for the baud rate. Older ARDUINO boards work with 19200 baud.
ARDUINO V2
The developers of the ARDUINO finally implemented the STK500V2 protocol. This
protocol is supported by Atmel and of course by BASCOM.
Select the ARDUINO STK500V2 programmer in BASCOM programmer options to use
this protocol.
A board like the MEGA2560 R3 uses this protocol and probably all newer AVR based
ARDUINO boards will support this protocol. The baud rate should be 115200 but could
be different for your board.
ARDUINO Leonardo
For some reason each arduino board seems to use a different bootloader method. The
leonardo implements a virtual COM port. When opened at 1200 baud, the board
resets into another virtual COM device with a different COM port number.
In BASCOM you need to chose the myAVR MK2 / AVR910 programmer since
Leonardo uses the AVR910 loader from Atmel.
You need to select the COM port that you get at Boot time. The baud is 115200.
To program, press the reset button, wait till the USB is enumerated and the Virtual
COM port is ready, then press F4 to program the processor.
Explanation of Parameter:
-C
c:\avrdude\avrdude.conf The config file tells avrdude about all the different ways it can talk to
the programmer.
-p
m328p This is just to tell it what microcontroller its programming. For example, if you are
programming an Atmega328p, use m328p as the partnumber
-P
com19 This is the communication port to use to talk to the programmer (COM19) in this case.
Change it to your COM port.
-c
arduino
Here is where we specify the programmer type, if you're using an STK500 use stk500, use
arduino for Optiboot
-b
115200
Set serial baudrate for programmer. Use 115200 baud for Optiboot.
-U
flash:w:{FILE}:i
You define here:
· the memory type: flash or eeprom (this could be also hfuse, lfuse or effuse if you want
to verfiy this)
· r (read), w (write) or v (verify)
· Use {FILE} to insert the filename {EEPROM} to insert the filename of the generated EEP
file.
· i = Intel Hex File
After clicking on the F4 (Program Chip) Button in Bascom-AVR you see the CMD window of
Windows 7 until AVRDUDE is ready flashing the Arduino.
The programmer is either shipped with the AVR911 protocol or the STK500V2
protocol.
The support in BASCOM is for the STK500V2 mode.
MyAVR has a simple utility that you can use to check and/or change the firmware.
Download it here
When you run the tool you get a window similar to this one:
The window above shows that the current firmware is STK500 which is OK.
When the version is AVR911, you can change it by selecting the STK500 1.11.xxxx in
the list and click 'BRENNEN' (burning)
The tool also allows to set the voltage of the programmer to 3V or 5V.
And you can turn on the power while burning (this will use internal USB power)
The usual options are available. Please read STK500 Programmer 160 for more info.
The MyAVR programmer has a special menu accessible from the Board menu.
Board, MyAVR, Voltage, 3V or 5V. This selects the output voltage of the programmer
Board, MyAVR, Power On Program. This option can be set and cleared. When set, the
programmer will route power to the target circuit during programming.
Board, MyAVR, Board Power, turn on/off. These options can be used to power the
target board while not programming.
When using the options to power the circuit, you should notice that this power is
taken from the USB bus. You should take care that your circuit does not draw too
much current.
The UPDI interface is very simple : all you need is a TX, RX and a resistor.
Connect TX from the PC UART to a 4K7 resistor. The other side of the resistor is
connected to the PC RX and to the UPDI pin of the processor.
We use DTR to switch the TX and RX from the PC to the processor. This allows to use
the PC COM port to be used for serial communication and as a UPDI programmer.
Note : some modules will not give proper signals. A 1K resistor will bring better
results.
Please notice that you need a MAX232 or other level converter between the PC
communication pins to create the proper voltage level! Like the circuit shown below.
The programmer works similar as the other supported programmers : you can
program the FLASH, EEPROM and the fuse/lock bytes
When you change the values of a fuse the WRITE-FUSES button will be enabled.
When you change the value of the LOCK fuse, the WRITE-LOCK bits button will be
enabled.
When you change the value of the user fuses, the WRITE USER ROW button will be
enabled.
When you write the fuses, the fuse values will be re-read (refreshed). And the same
for the other fuses.
you can also use an USB virtual com port chip such as the FT232 or CP2102.
Using a serial port just for programming is a bit of a waste. Often you also like to
have serial communications.
So a more practical programmer will switch the TX/RX lines between the UPDI pin
and the TX-RX USART pins of the processor.
Notice that the USB circuit shown is not complete, you should check it with the chip of
your choice like FT232RL, CP2102, etc. The main purpose of the USB part is to show
the TX/RX and DTR pins.
The TX pin and RX pins are connected to a 4053 switch. This is an analog switch. The
DTR line selects the XYZ-0 or XYZ-1 side of the switch.
The UPDI pin is also connected to a MUX switch. This simple circuit now switches
between the UPDI mode and the TX and RX pins of the processor.
The BASCOM-UPDI programmer will automatically switch the DTR line.
3.59.2 LIBUSB
Like every other USB device, an USB programmer requires a windows driver. Some
programmers use drivers that are provided (built into) by windows. For example the
KamProg uses the HID class and does not require an additional third party driver.
A programmer like the AVRISP mkII does need an additional driver. This device driver
is installed when you install AVR Studio.
Studio is using device drivers from JUNGO.
When you plug in the programmer and Windows informs you that it requires a driver
you know that you need to install a third party driver.
When Windows does not complain it will use a driver already available on your PC.
Most USB devices need software installed before you plug them in for the first time.
In many cases there is a warning sticker that you should first install the software.
BASCOM uses LIBUSB to access USB devices. LIBUSB is available as a device driver
or as a filter driver.
When your device is using a device driver you must access the device with a filter
driver.
Some devices do not have a vendor supplied driver (USBASP programmer) and those
require a device driver.
The next step is to plug your programmer, and see if it works with AVR Studio.
Windows will recognize it, and install the device driver.
When windows is ready, press the connect button in Studio.
If you open Studio, and press the CON(nection) button, the window shown above will
open.
Now select your programmer, in this sample AVRISP mkII and press Connect
You can select the device, the programming mode and ISP frequency. This frequency
should be 125 KHz (or better said, should not exceed a quarter of the chip oscillator
frequency).
When you do not get this window but you return to the connection window, it means
your programmer is not working.
You have to solve this first before you can continue.
The programmer will only work in BASCOM when it functions with the original
software!
In the windows device manager, you can find this info: (right click Computer, select
manage, and chose device manager)
The screen above shows the JUNGO usb driver which Atmel AVR Studio uses and the
AVRISP mkII driver for the AVRISP mkII.
If you install AVR Studio with the USB drivers, it will install JUNGO and the WinDriver.
The AVRISP mkII entry you only get when you plug the programmer.
To make it work with BASCOM, you need to install LIBUSB. LIBUSB is used by many
different programs. Atmels FLIP is using it too. So there is a big change that it is
available on your system already.
You can install LIBUSB as a FILTER driver or a DEVICE driver.
We install the FILTER driver, so we can use the programmer with Studio AND bascom.
When installing the USB driver, disconnect ALL USB devices. Obvious, you can
not install from an USB flash drive since this is an USB device as well.
Notice that this an executable you can install. You MUST have ADMIN rights when you
install this executable.
- Run the testlibusb-win.exe application. When LIBUSB is functional you will see a
screen with all USB devices.
When it does not work, try to install again with compatibility mode set to XP SP2.
Do this by selecting the the setup exe file properties, and select 'Compatibility'.
Once the testlibusb-win.exe works, you can continue to the next step.
Now the programmer will work in BASCOM. Just select the proper programmer, and
timeout of 100 ms. You can try lower time outs too to make it quicker. When you get
errors, increase the time out. 100 ms should do for all programmers.
As you can see, the USBASP was inserted in this sample. Select it (or your
programmer) and press Next.
Press Next again and select a folder to store the device driver files.
These files are required to install the device.
After you have saved the files, you have the option to install the driver. Press Install
Now.. button to do so.
When ready :
Final note
The USB-ISP programmer form EMBUD, uses drivers from FTDI. It does not require
LIBUSB.
The Kamprog programmer from KAMAMI uses a HID class and does not require
LIBUSB.
OPTION DESCRIPTION
Upload Selects the baud rate used for uploading
speed
Monitor String that will be send to the monitor before the upload starts
prefix
Monitor String that us sent to the monitor after the download is completed.
suffix
Monitor Time in milliseconds to wait after a line has been sent to the monitor.
delay
Prefix delay Time in milliseconds to wait after a prefix has been sent to the
monitor.
OPTION DESCRIPTION
Font Printer font to use when printing
Setup Click to change the printer setup
Color Will print in color. Use this only for color printers.
Wrap lines Wrap long lines. When not enabled, long lines will be partial shown.
Print Print a header with the filename.
header
Line Will be the line number before each line.
numbers
Syntax Enable this to use the same syntax highlighting as the editor
Left margin The left margin of the paper.
Right The right margin of the paper.
margin
Top margin The top margin of the paper.
Bottom The bottom margin of the paper.
margin
In order to make it possible to use different settings file, you can rename these files.
You can select the actual settings file using this menu option.
When you select this option, the status bar will show the current selected file.
This file will also be loaded when you run bascom.
A File Dialog will open and show all XML files. You need to select a bascom-avr xml
file.
You can use this option after you have performed an update. Each update will have
its own settings file. That way you can use multiple versions that each have their own
settings file.
Electronics\bascom-avr2082.xml
This location is also shown when you click the XML data folder link in the Help, About
window
You must give the file a different name. When the file is created, it will be shown in
the list.
When you use the SELECT button, you select the new option file. This is reflected at
the CURRENT OPTION FILE value in the top of the window.
The CUSTOM location can be used to store your option file at a custom location. You
can enter a file and location or use the button to browse to the file.
You need to click the SELECT CUSTOM button to select this file as the new custom
option file.
Your serial number is shown on the third line of the about box.
You will need this when you have questions about the product.
When you click the App data dir link, the folder which contains the BASCOM settings
will be opened:
It contains the bascom-avr.xml file with all settings and the bascavr.log file. When
you need support, you might be asked to email these files.
When you need support, also click the Copy-button. It will copy the following info to
the clipboard, which you can paste in your email :
Dont forget that Serial numbers should not be sent to the user list.
Make sure you sent your email to support and not a public list !
When you click the support link, your email client will be started and an email to
[email protected] will be created.
When you are in the editor window, the current word selected or by the cursor will be
used as a keyword.
Notice that when the help window is small, you might need to make the help window
bigger to show the whole content.
The help contains complete sample code and partial sample code.
In all cases the samples are shown to give you an idea of the operation. When trying
a program you should always use the samples from the SAMPLES directory. These are
updated and tested when new versions are published. The (partial) samples are not
all updates, only when they contain errors. So the samples from the help might need
some small adjustments while the samples form the SAMPLES dir will work at least on
the used chip.
This forum is hosted by MCS Electronics. There are various forums available. You can
post your questions there. Do not cross post your questions on multiple forums and to
support.
You can order items and pay with PayPal. PayPal will accept most credit cards.
Before you order, it is best to check the resellers 1710 page to find a reseller near you.
Resellers can help you in your own language, have all MCS items on stock, and are in
the same time zone.
http://www.mcselec.com/support-center/
It depends from your browser settings if a new window or TAB will be created.
At the support site you can browse articles. You can also search on keywords.
While it is impossible to thank everybody there are some people that deserve credits :
· Peter Maroudas. He wrote and tested the FT80x FTDI display support. FT800
support would not exist without him.
·
· Josef Franz Vögel. He wrote a significant part of the libraries in BASCOM-AVR.
He is also author of AVR-DOS.
· Dr.-Ing. Claus Kuehnel for his book 'AVR RISC' , that helped me a lot when I
began to study the AVR chips. Check his website at http://www.ckuehnel.ch
· Atmel, who gave permission to use the AVR picture in the start up screen. And
for the great tech support. Check their website at http://www.atmel.com
· Brian Dickens, who did most of the Beta testing. He also checked the
documentation on grammar and spelling errors. (he is not responsible for the
spelling errors i added later :-) )
· Jack Tidwell. I used his FP unit for singles. It is the best one available.
The DEMO version can not be updated. You can however install the full version into
the DEMO folder.
When you click Help, Update, the following window will be shown:
BasCom Update
You need to click the START button to start the actual update process.
When there are unsaved files, you will get an error message :
Your work/project must be saved since as soon the update download is finished, the
setup will be executed and BASCOM is closed.
When there are no unsaved files, the current version will be checked.
In this case, there is no newer file and nothing happens. You need to click the CLOSE
button to close the Update window. The IDE will not be closed in this case.
This setup is the same as you used when you installed the software. But of course the
latest version.
You can install into the same folder, but you may also install into a new folder.
When installing into a new folder you must manual install/copy the license file
bscavrl.dll into the new folder yourself.
The bscavrl.dll file you get when you purchase bascom. It is either on CD-ROM or in
the bascom-avr application folder.
Please notice that this license file is offered during purchase. We do not offer it again
in the event you lost it.
Add On Update
When you chose to update Add On, you can also specify that libraries will be copied
after the update. You do this by checking the 'Copy Libs After Update' check box.
The Add on update will check if you have an add on installed. It will then check if
there is an update available. Notice that not all add ons you purchased are supported
yet. So those you have to manual download/install.
The supported Add Ons :
- AVRDOS.
- I2CSLAVE
- XTINY
The add on is always ZIPPED and this ZIP file is downloaded to a new SUB folder
named ADDONS.
This ADDONS subfolder is created in the BasCom-AVR application folder.
Each Add On is installed into its own sub folder. So for AVRDOS it is installed into
ADDONS\AVRDOS
Older versions that might exist are overwritten.
When an Add-On contains a LIB or LBX file, the option 'Copy Libs after update' will be
copied to the BasCom-AVR Library folder. The original file will be renamed so you
always have a backup.
You do need write access in the BasCom-AVR application folder and sub folder.
When you want to contribute you need to create an account and send an email to
[email protected] to get the proper access rights.
Key Action
LEFT ARROW One character to the left
RIGHT ARROW One character to the right
UP ARROW One line up
DOWN ARROW One line down
HOME To the beginning of a line
END To the end of a line
PAGE UP Up one window
PAGE DOWN Down one window
CTRL+LEFT One word to the left
CTRL+RIGHT One word to the right
CTRL+HOME To the start of the text
CTRL+END To the end of the text
CTRL+ Y Delete current line
INS Toggles insert/over strike mode
F1 Help (context sensitive)
F2 Run simulator
F3 Find next text
F4 Send to chip (run flash programmer)
F5 Run
F7 Compile File
F8 Step
F9 Set breakpoint
F10 Run to
F11 Collapse Code Toggle Sub/Function
SHIFT+F11 or Collapse Code Toggle current block
CTRL+ENTER
CTRL+F7 Syntax Check
CTRL+F Find text
CTRL+G Go to line
CTRL+K+x Toggle bookmark. X can be 1-8
CTRL+L LCD Designer
CTRL+M File Simulation
CTRL+N New File
CTRL+O Load File
CTRL+P Print File
CTRL+Q+x Go to Bookmark. X can be 1-8
CTRL+R Replace text
3.80 PlugIns
3.80.1 Font Editor
In version 2079 the Font Editor plugin is replaced by the integrated Font Editor from
the Tools menu 133 . It has the same options.
The Font Editor is a Plug in that is intended to create Fonts that can be used with
Graphical display such as SED1521, KS108, color displays, etc.
When you have installed the Font Editor , a menu option becomes available under the
Tools menu : Font Editor.
When you choose this option the following window will appear:
When you select a new character, the current character is saved. The suggest button
will draw an image of the current selected character.
When you keep the left mouse button pressed, you can set the pixels in the grid.
When you keep the right mouse button pressed, you can clear the pixels in the grid.
When you choose the option to create a new Font, you must provide the name of the
font, the height of the font in pixels and the width of the font in pixels.
The Max ASCII is the last ASCII character value you want to use. Each character will
occupy space. So it is important that you do not choose a value that is too high and
will not be used.
When you display normal text, the maximum number is 127 so it does not make
sense to specify a value of 255.
Font8x8:
$asm
.db 1,8,8,0
.db 0,0,0,0,0,0,0,0 ;
.db 0,0,6,95,6,0,0,0 ; !
The first line contains the name of the font. With the SETFONT 1219 statement you can
select the font. Essential, this sets a data pointer to the location of the font data.
The second line ($ASM) is a directive for the internal assembler that asm code will
follow.
All other lines are data lines.
The third line contains 4 bytes: 1 (height in bytes of the font) , 8 (width in pixels of
the font), 8 (block size of the font) and a 0 which was not used before the 'truetype'
support, but used for aligning the data in memory. This because AVR object code is a
word long.
This last position is 0 by default. Except for 'TrueType' fonts. In BASCOM a TrueType
font is a font where every character can have it's own width. The letter 'i' for example
takes less space then the letter 'w'. The EADOG128 library demonstrates the
TrueType option.
In order to display TT, the code need to determine the space at the left and right of
the character. This space is then skipped and a fixed space is used between the
characters. You can replace the 0 by the width you want to use. The value 2 seems a
good one for small fonts.
IV
BASCOM HARDWARE 221
4 BASCOM HARDWARE
4.1 Additional Hardware
Of course just running a program on the chip is not enough. You will probably connect
many types of electronic devices to the processor ports.
BASCOM supports a lot of hardware and so it has lots of hardware related statements.
Before explaining about programming the additional hardware, it might be better to
talk about the chip.
I2CSEND 1173 and I2CRECEIVE 1172 and other I2C related statements.
CLS, 1190 LCD, 1204 DISPLAY 1197 and other related LCD-statements.
For this description of the hardware the 90S8515 was used. Newer chips like the
Mega8515 may differ and have more or less internal hardware.
You will need to read the manufacturers data sheet for the processor you are using to
learn about the special internal hardware available.
Timer / Counters
The AT90S8515 provides two general purpose Timer/Counters - one 8-bit T/C and
one 16-bit T/C. The Timer/Counters have individual pre-scaling selection from the
same 10-bit pre-scaling timer. Both Timer/Counters can either be used as a timer
with an internal clock time base or as a counter with an external pin connection which
triggers the counting.
Almost all AVR chips have the ports B and D. The 40 or more pin devices also have
ports A and C that also can be used for addressing an external RAM chip (XRAM 230 ).
Since all ports are similar except that PORT B and PORT D have alternative functions,
only these ports are described.
PORT B 227
PORT D 229
The internal registers for the AVR90S8515 are : (other processors are similar,
but vary)
Addr. Register
$3F SREG I T H S V N Z C
$3E SPH SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8
$3D SPL SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0
$3C Reserved
The registers and their addresses are defined in the xxx.DAT files which are placed in
the BASCOM-AVR application directory.
Note that internal registers are reserved words. This means that they can't be
dimensioned as BASCOM variables!
So you can't use the statement DIM SREG As Byte because SREG is an internal
register.
You can however manipulate the register with the SREG = value statement, or var =
SREG statement.
The 90S8515 was used for this example. Other chips might have a somewhat
different timer.
The 8-bit Timer/Counter0 can select its clock source from CK, pre-scaled CK, or an
external pin. In addition it can be stopped (no clock).
The overflow status flag is found in the Timer/Counter Interrupt Flag Register - TIFR.
Control signals are found in the Timer/Counter0 Control Register - TCCR0. The
interrupt enable/disable settings for Timer/Counter0 are found in the Timer/Counter
Interrupt Mask Register - TIMSK.
The 8-bit Timer/Counter0 features both a high resolution and a high accuracy mode
with lower pre-scaling values. Similarly, high pre-scaling values make the Timer/
Counter0 useful for lower speed functions or exact timing functions with infrequent
actions.
The 90S8515 was used for the documentation. Other chips might have a
somewhat different timer.
The 16-bit Timer/Counter1 can select its clock source from CK, pre-scaled CK, or an
external pin. In addition it can be stopped (no clock).
The different status flags (overflow, compare match and capture event) and control
signals are found in the Timer/Counter1 Control Registers - TCCR1A and TCCR1B.
The interrupt enable/disable settings for Timer/Counter1 are found in the Timer/
Counter Interrupt Mask Register - TIMSK.
The external clock signal is sampled on the rising edge of the internal CPU clock.
The 16-bit Timer/Counter1 features both a high resolution and a high accuracy usage
with lower pre-scaling values.
Similarly, high pre-scaling values make the Timer/Counter1 useful for lower speed
functions or exact timing functions with infrequent actions.
The Timer/Counter1 supports two Output Compare functions using the Output
Compare Register 1 A and B -OCR1A and OCR1B as the data values to be compared
to the Timer/Counter1 contents.
The Output Compare functions include optional clearing of the counter on compareA
match, and can change the logic levels on the Output Compare pins on both compare
matches.
By controlling the Watchdog Timer pre-scaler, the Watchdog reset interval can be
adjusted from 16K to 2,048K cycles (nominally 16 - 2048 ms). The BASCOM RESET
WATCHDOG - instruction resets the Watchdog Timer.
Eight different clock cycle periods can be selected to determine the reset period.
If the reset period expires without another Watchdog reset, the AT90Sxxxx resets and
program execution starts at the reset vector address.
Direction Register - DDRB, $17($37) and the Port B Input Pins - PINB, $16($36). The
Port B Input Pins address is read only, while the Data Register and the Data Direction
Register are read/write.
All port pins have individually selectable pull-up resistors. The Port B output buffers
can sink 20mA and thus drive LED displays directly. When pins PB0 to PB7 are used
as inputs and are externally pulled low, they will source current if the internal pull-up
resistors are activated.
The Port B pins with alternate functions are shown in the following table:
When the pins are used for the alternate function the DDRB and PORTB register has
to be set according to the alternate function description.
The Port B Input Pins address - PINB - is not a register, and this address enables
access to the physical value on each Port B pin. When reading PORTB, the PORTB
Data Latch is read, and when reading PINB, the logical values present on the pins are
read.
To switch the pull up resistor off, the PORTBn has to be cleared (zero) or the pin has
to be configured as an output pin.
By default, the DDR and PORT registers are 0. CONFIG PORTx=OUTPUT will set the
entire DDR register. CONFIG PINX.Y will also set the DDR register for a single bit/pin.
When you need the pull up to be activated, you have to write to the PORT register.
RD - PORTD, Bit 7
RD is the external data memory read control strobe.
WR - PORTD, Bit 6
WR is the external data memory write control strobe.
The PD5 pin has to be configured as an out-put (DDD5 set (one)) to serve this f
unction. See the Timer/Counter1 description for further details, and how to enable the
output. The OC1 pin is also the output pin for the PWM mode timer function.
source to the MCU. See the interrupt description for further details, and how to enable
the source.
When pins TXD and RXD are not used for RS-232 they can be used as an input or
output pin.
The UCR register will by default not set bits 3 and 4 that enable the TXD and RXD
pins for RS-232 communication. It is however reported that this not works for all
chips. In this case you must clear the bits in the UCR register with the following
statements:
RESET UCR.3
RESET UCR.4
or as an alernative : UCR=0
For ATXMEGA devices see App Note: AVR1312: Using the XMEGA External Bus
Interface for details.
For example for an ATMEGA1280 the external memory interface consist of PORTA
(multiplexed data and address low byte), PORTC (address high byte), and
PORTG[2:0] (RD, WR and ALE).
http://www.nxp.com/documents/data_sheet/74HC_HCT573.pdf
Schematics for connecting the ATMEGA with octal latch and sram can be found in:
· Atmel AVR Studio Help File (AVR tools user guide) search for: "external memory
interface" and scroll down to APPENDIX. There you also find a list of 3.3 or 5V
compatible SRAM's that can be used with ATMEGA's and there is a link to
STK503.pdf which is part of the help file.
· The list of compatible SRAM devices can be also found here:
http://www.atmel.com/images/stk503_ug.pdf (page 16)
· The datasheet of for example ATMEGA1280 also include a picture which show the
connections between AVR, Octal Latch external SRAM device.
XRAM will use an area in the remaining address locations in the 64K address space
(&HFFFF). This starts at the address following the internal SRAM.
Internal SRAM use the lowest 4,608/8,704 bytes, so when using 64KB (65,536 bytes)
of XRAM, 60,478/56,832 Bytes of XRAM are available.
See datasheet of ATMEGA device for a way to use the complete 64KByte.
XRAM will be enabled by CONFIG XRAM 1036 (config XRAM is setting SRE bit of the
atmega 1280 XMCRA Register)
The Pins of Port A, Port C and Port G from ATMEGA1280 are automatically enabled for
XRAM and can not be used for other tasks by default if XRAM is enabled. The external
memory address space can be divided in two sectors (upper and lower sector) with
different wait-state bits. You can also release some Port C pins for other tasks (in the
XMCRB Register) . See atmega 1280 datasheet for details.
With XRAM, you should dim all your global variables with XRAM. Example: Dim Var As
Xram Byte
This will leave the internal memory for the stacks and local created variables.
You can also use $ d e f a u l t Xram when you do not want to add the XRAM to each DIM.
Example 1:
A real Example for using SRAM and another Bus-mode device is WIZ200WEB from
Wiznet.
Here an ATMEGA128L, an external 32K SRAM and a W5300 Ethernet Chip is used. See
also CONFIG TCPIP 980
$xramstart = &H1100
$xramsize = &H8000
Config Xram = Enabled
The W5300 Chip from Wiznet is setup to use Base Address &H8000.
See also CONFIG TCPIP 980 for further details on W5300 Chip from Wiznet.
Example 2:
We use now an WIZ830mj module (which uses a W5300 Chip from Wiznet) on a board with
an 64/128KByte SRAM in combination with ATMEGA1280:
Hex-Address:
&H00 .... &H1F 32 Registers
&H20 .... &H5F 64 I/O Registers
&H60 .... &H1FF 416 external I/O Registers
&H200 .... &H21FF Internal SRAM (8K in this case)
&H2200 .... &HFBFF External SRAM (XRAM) upper and lower
&HFC00 Base Address of W5300 Chip over memory address selector
The datasheet of W5300 say: "In the case of using an 8bit data bus width, ADDR[9:0] is used
" so we have Address 0.......Address 9 but the SRAM need Address 0.....15.
Here an example of additional circuit between ATMEGA and W5300 and SRAM to solve the
difference of address (A0...A15) for SRAM and (A0...A9) for W5300:
For older 90S8515 chips for example the maximum size of XRAM can be 64 Kbytes.
Example: The STK200 has a 62256 ram chip (32K x 8 bit).
You can also program an extra wait state, to use slower memory.
Here you will find a pdf file showing the STK200 schematics:
See Stk200_schematic.pdf for more information.
If you use a 32 KB SRAM, then connect the /CS signal to A15 which give to the range
of &H0000 to &H7FFF, if you use a 64 KB SRAM, then
tie /CS to GND, so the RAM is selected all the time.
Config Xram = 3port , Ale = Ale12 , Sdbus = 8 , Modesel0 = Sram , Adrsize0 = 256b ,
Modesel1 = Sram , Adrsize1 = 128k , Waitstate1 = 1 , Baseadr1 = &H20
The EBI allows to use an SRAM in 4-port non multiplexed mode. This means that you
need little parts but you loose 4 ports.
Example
$regfile = "xm128a1def.dat"
$crystal = 32000000
$hwstack = &H32
$swstack = &H32
$framesize = &H32
$xramstart = &H100000
$xramsize = &H080000
'------------------
' CPU:
' ATXMEGA128A1U-AU : 2,23/100 Mouser Muss -->A1U-AU<--
sein !!!
' ATXMEGA64A1U-AU
'------------------
' SRam:
' 512 KB AS6C4008-55PCN : SRAM 4MB 2.7V-5.5V, 512KX8, PDIP32
'----------------------------------------------------------------
---------------
'----------generate a 32 MHz system clock by use of the PLL (2MHz
* 23 = 46MHz)
'enable PLL
Set Osc_ctrl.4 'PLL
enable
'----------------------------------------------------------------
---------------
'----------------------------------------------------------------
---------------
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None ,
Stopbits = 1 , Databits = 8
attributes off(normal)
Printbin #1 , &H1B ; &H5B ; &H32 ; &H4A '
Bildschirm löschen
Printbin #1 , &H1B ; &H5B ; &H48 ; '
Cursor Home
Printbin #1 , &H1B ; &H5B ; &H3F ; &H32 ; &H35 ; &H68 ; '
Cursor an
'----------------------------------------------------------------
---------------
' Einstellungen externer Speicher
' Alle EBI-Ports müssen auf OUTPUT
' ALLE Ports, die ATKIV-LOW sind müssen auf 1 gesetzt werden
!!!
' ALLE Ports, die ATKIV-HIGH sind müssen auf 0 gesetzt werden
!!!
Portk_pin4ctrl = &B0_0_001_000
'Totem (PushPull) + Buskeeper
Portk_pin5ctrl = &B0_0_001_000
'Totem (PushPull) + Buskeeper
Portk_pin6ctrl = &B0_0_001_000
'Totem (PushPull) + Buskeeper
Portk_pin7ctrl = &B0_0_001_000
'Totem (PushPull) + Buskeeper
Portf_pin4ctrl = &B0_0_001_000
'Totem (PushPull) + Buskeeper
Portf_pin5ctrl = &B0_0_001_000
'Totem (PushPull) + Buskeeper
Portf_pin6ctrl = &B0_0_001_000
'Totem (PushPull) + Buskeeper
Portf_pin7ctrl = &B0_0_001_000
'Totem (PushPull) + Buskeeper
'----------------------------------------------------------------
---------------
'----------------------------------------------------------------
---------------
'----------------------------------------------------------------
---------------
'----------------------------------------------------------------
---------------
'ChipSelect0 für 512 KByte SRam
'----------------------------------------------------------------
---------------
' Nun kann das externe SRam genauso wie das interne SRam
angesprochen werden.
' Vorteil: erheblich schneller im Zugriff, wie DRam !!!
' So kann auch Hardware "memory-mapped" eingebunden werden
' oder ein ISA-Bus realisiert werden.
' Now you can use the external SRAM just like the internal SRAM.
' This is much faster like DRAM
' This way you can also map hardware and access registers as you
would do for SRAM
$xramstart = &H100000
$xramsize = &H080000
· By wiring the LCD-pins to the processor port pins. This is the pin mode. The
advantage is that you can choose the pins and that they don't have to be on the
same port. This can make your PCB design simple. The disadvantage is that more
code is needed.
· By attaching the LCD-data pins to the data bus. This is convenient when you have
an external RAM chip and will add only a little extra code.
This leaves PORTB.1 and PORTB.0 and PORTD for other purposes.
You can change these pin settings from the Options LCD 140 menu.
For those who want to have more control of the example below shows how to use the
internal BASCOM routines.
$ASM
Ldi _temp1, 5 'load register R24 with value
Rcall _Lcd_control 'it is a control value to control the display
Ldi _temp1,65 'load register with new value (letter A)
Rcall _Write_lcd 'write it to the LCD-display
$END ASM
Note that _lcd_control and _write_lcd are assembler subroutines which can be called
from BASCOM.
See the manufacturer's details from your LCD display for the correct pin assignment.
The available memory depends on the chip. When you double click on the chip pinout,
you can view the parameters of the used chip.
A special kind of memory are the registers in the AVR. Registers 0-31 have addresses
0-31.
Almost all registers are used by the compiler or might be used in the future.
Which registers are used depends on the program statements you use.
For example, CONFIG CLOCK 798 in user mode requires variables to hold the time.
Variables like _sec , _min , _hour, _day , _month , _year.
Each 8 bits used occupy one byte. When you dimension 1 bit, you will also use 1
byte.
Each byte variable occupies one byte.
Each integer/word variable occupies two bytes.
Each Long, Dword or Single variable occupies four bytes.
Each double variable occupies 8 bytes.
Each string variable occupies at least 2 bytes.
A string with a length of 10 occupies 11 bytes.
Strings need an additional byte (Null termination) to indicate the end of the
string. That's why a string of 10 bytes occupies 11 bytes.
Use bits or byte variables wherever you can to save memory. (not allowed for
negative values)
The software stack is used to store the addresses of LOCAL variables and for variables
that are passed to SUB routines.
Each LOCAL variable and passed variable to a SUB/FUNCTION, requires two bytes to
store the address (because it is a 16-Bit address = 2 bytes).
So when you have a SUB routine in your program that passes 10 variables, you need
10 * 2 = 20 bytes.
When you use 2 LOCAL variables in the SUB program that receives the 10 variables,
you need additional 2 * 2 = 4 bytes.
The software stack ($SWSTACK 609 ) size can be calculated by taking the maximum
number of parameters in a SUB routine, adding the number of LOCAL variables and
multiplying the result by 2. To be safe, add 4 more bytes for internally used LOCAL
variables.
LOCAL variables are stored in a place that is named the Frame ($FRAMESIZE 545 )
When you have a LOCAL STRING with a size of 40 bytes, and a LOCAL LONG, you
need 41 + 4 bytes = 45 bytes of frame space.
When you use conversion routines such as STR 740 , VAL 743 , HEX 737 , INPUT 1359 etc. that
convert from numeric to string and vice versa, you also need a frame. Note that the
use of the INPUT 1359 statement with a numeric variable, or the use of the PRINT 1367 or
LCD 562 statement with a numeric variable, will also force you to reserve 24 bytes of
frame space. This because these routines use the internal numeric<>string
conversion routines.
In fact, the compiler creates a buffer of 24 bytes that serves as scratchpad for
temporary variables, and conversion buffer space. So the frame space should be 24
at minimum ($FRAMESIZE 545 = 24). This 24 Byte start at the beginning of the
Frame which act as the conversion buffer within the frame
For an ATXMEGA or ATMEGA you have usually enough SRAM so you can start with
higher values of Stack and Frame.
With an ATTINY13 and 64Byte SRAM it is a challenge but also start with all stack
defined and lower the Stack Values when your application program grows.
· Avoid to use SUB or FUNCTIONS (If you want to save SRAM space)
· If you use Functions like PRINT, LCD, INPUT and the FP num <> FORMAT(), String
conversion you need to define the 24 Byte conversion buffer (at least 24Byte for
Software Stack + FRAME together).
XRAM
Some processors have an external memory interface. For example the ATMEGA128
has such an interface.
The additional memory is named XRAM memory (extended or external memory).
When you add 32 KB RAM, the first address will be 0.
But because the XRAM can only start after the internal SRAM, the lower memory
locations of the XRAM will not be available for use. The processor will automatically
use the SRAM if an address is accessed that is in range of the SRAM memory.
Thus adding 32KB of XRAM, will result in a total of 32 KB RAM.
With ATXMEGA you can add XRAM with the EBI (External Bus Interface). There is no
problem to add for example
16 MByte of external SDRAM.
See CONFIG XRAM 1036
ERAM
Most AVR chips have internal EEPROM on board.
This EEPROM can be used to store and retrieve data.
In BASCOM, this data space is called ERAM.
For example:
P r i n t "ABCD"
P r i n t "ABCD"
In this example, two constants will be stored because the strings differ.
Stack
The Stack is a part of SRAM (Static RAM). In SRAM the compiler stores user
dimensioned variables, as well as internal variables, but SRAM holds also Hardware
Stack, Software Stack and Frame. The Variables always start at the lowest SRAM
Address. After Reset all SRAM Bytes are 0 (and strings are "") so the SRAM memory is
cleared after reset. With the $noramclear option you can turn this behavior off which
means the SRAM is not cleared after reset.
With ATTINY13 for example you have 64Byte of SRAM and you will find this
information beside the user manual in the *.DAT file. You can also double click the
chip in Chip Pinout to view the chip parameters.
Global Variables start with the lowest SRAM Address and the Hardware Stack start
with the highest SRAM Address.
Do
!NOP
Loop
End 'end program
p i n _ c h a n g e _ i s r:
B = 7
Return
With an ATTINY13 the SRAM is just 64Byte and it is easy to see which SRAM Bytes
will be overwritten with Bascom AVR Simulator Memory Window.
Picture: SRAM of ATTINY13 when executing the above ATTINY13 example in Bascom
Simulator
You can see the Hardware Stack (32 Byte) , Frame (24 Byte) and the Variable B.
For this example you do not really need a Frame so it could be also $framesize = 0 for
this example.
With ATXMEGA128A1 there is 8K Byte of SRAM available and you can find in the DAT
file (SRAM = 8192 ; SRAM size )
Example:
$hwstack = 32 ' default use 32 for the
hardware stack
$swstack = 32 ' default use 32 for the SW
stack
$framesize = 40 ' default use 40 for the frame
space
As we know now Software Stack and FRAME together must be as absolute minimum
24 Byte (for the conversion buffer) so we force the overwriting of Hardware Stack
which causes malfunction.
(Reminder: Don’t start with the lowest values for Stack and Frame)
Picture: Simulator Memory Windows for example with $hwstack = 64, $swstack = 0,
$framesize = 8
Because it is easier with the memory window of Bascom Simulator I choose multiple
of 16 for Stack and Framesize.
We have here 2 Addresses stored in Software Stack. One address for the Array and
one address for the variable B.
So passing an Array to a SUB just need 2 Bytes for the address in Stack which is the
same size as for one Byte variable (here variable B).
With this example you also see that especially with ATTINY and smaller ATMEGA it is
not that complicated to see if other SRAM bytes will be overwritten by something and
causes malfunction.
You have with the Simulator window the “big picture” of SRAM and STACK together.
Picture: How to see which Variables are stored on which SRAM Byte
You can also find this information in the Compiler output report:
In this case under VARIABLES
Picture: How to see which Variables are stored on which SRAM Address
The following small example is good for examining the Bascom-AVR internal variables
like _sec, _min or _hour in Bascom-AVR Simulator Memory Window.
Config Clock = User for example create the internal variables for seconds (_sec),
minutes (_min) ,hour (_hour) etc…. You can see this variables by clicking on the
SRAM Byte and watch the footer of that Bascom-AVR Simulator Memory Window
footer.
$regfile = "m88def.dat"
$hwstack = 48
$swstack = 80
$framesize = 80
USART0
$BAUD, BAUD
USART1
$BAUD1 , BAUD1,
USARTx
BUFSPACE, CLEAR, ECHO, WAITKEY, ISCHARWAITING, INKEY, INPUTBIN, INPUTHEX,
INPUT, PRINT, PRINTBIN
TIMER0
DCF77 , READHITAG , GETRC5 , CONFIG SERVOS , TIME$, DATE$
TIMER1
DTMFOUT , RC5SEND, RC6SEND , SONYSEND.
TIMER2
TIME$, DATE$
ADC
GETADC
EEPROM
READEEPROM, WRITEEPROM
TWI
I2CINIT, I2CRECEIVE, I2CSEND, I2START I2CSTOP I2CRBYTE I2CWBYTE
SPI
SPIIN, SPIINIT, SPIMOVE, SPIOUT - SPI
CAN
CONFIG CANBUS, CONFIG CANMOB, CANBAUD, CANRESET, CANCLEARMOB,
CANCLEARALLMOBS, CANSEND, CANRECEIVE, CANID, CANSELPAGE, CANGETINTS
If you wish to connect to a PC you need to use RS232 protocol specifications. This
means that the hardware communication is done with specific voltage levels. (+15V
and -15V) This can be achieved by using a MAX232 level shifter.
The DB-9 connector has 9 pins but you only need to use 3 of them. Notice that the
drawing above shows the FRONT VIEW thus remember that you are soldering on the
other side. On most connectors the pin outs can also be found on the connector itself.
If your controller has no UART you can use a software UART see below. If your
controller has one UART you connect controller pins TxD and RxD to TxD and RxD in
the schematic above. If your controller has more than one UART you connect
controller pins TxD0 and RxD0 to TxD and RxD in the schematic above.
You now need to initialize the program in your micro controller, open a new .bas file
and add the following code in the beginning of your program.
Make sure to define your micro controller after $regfile for example if you use the ATMega32
$ r e g f i l e = "m32def.dat"
Some new chips can use an internal oscillator, also some chips are configured to use
the internal oscillator by default. Using an internal oscillator means you do not need
an external crystal.
· Select the “Lock and Fuse Bits” tab and maximize the programmer window.
· Check if you see the following in the “Fusebit” section:
"1:Divide Clock by 8 Disabled"
and
"Int. RC Osc. 8 MHz; Start-up time: X CK + X ms; [CKSEL=XXXX SUT=XX]"
These options are not available for all AVR’s, if you don’t have the option do not
change any fuse bits.
If these options are available, but in a wrong setting. Change the setting in the drop
down box and click another Fuse section. Finally click the "Program FS" button. Click
"Refresh" to see the actual setting.
Now connect a straight cable between the DB-9 connector, micro controller side and
the PC side.
Program a test program into your micro controller, it should look like this:
Do
Print "Hello World"
Waitms 25
Loop
End
Now open the BASCOM-AVR Terminal and set your connection settings by clicking
“Terminal” -> “Settings” Select your computers COM port and select baud 19200,
Parity none, Data bits 8, Stop bits 1, Handshake none, emulation none.
If you see the Hello World displayed in the BASCOM-AVR Terminal emulator window,
your configuration is OK. Congratulations.
Example
You can also try this example with the BASCOM Terminal emulator, it shows you how to send and
receive with various commands.
$regfile = "m88def.dat"
$crystal = 8000000
$baud = 19200
Print
Print "Hello, hit any alphanumerical key..."
Akey = Waitkey() 'Waitkey waits untill a char is received from the UART
Print Akey
Wait 1
Print
Print "Thanks!, as you could see the controller prints a number"
Print "but not the key you pressed."
Wait 1
Print
Print "Now try the enter key..."
Akey = Waitkey()
Akey = Waitkey()
Print Akey
Print
Print "The number you see is the ASCII value of the key you pressed."
Wait 1
Print
Print "For a lot of functions, just one key is not enough..."
Print "Now type your name and hit enter to confirm"
Do
Akey = Waitkey()
If Akey = 13 Then Goto Thanks 'On enter key goto thanks
Inputstring = Inputstring + Chr(akey) 'Assign the string
Loop
Thanks:
Print "Thank you " ; Inputstring ; " !" 'Notice what ; does
Wait 1
Print
Print "Take a look at the program code and try to understand"
Print "how this program works. Also press F1 at the statements"
Print
Print "If you understand everything continue to the next experiment"
End
ASCII
As you could have seen in the previous example we use the PRINT statement to send
something to the UART. Actually we do not send just text. We send ASCII characters.
ASCII means American Standard Code for Information Interchange. Basically ASCII is
a list of 127 characters.
Basically if we state:
Print “ABC”
We send 65 66 67 13 10 to the UART. (In binary format)
The carriage return character (13) returns the cursor back to column position 0 of the
current line. The line feed (10) moves the cursor to the next line.
Print “ABC” ;
When we type a semicolon ( ; ) at the end of the line...
Bascom does not send a carriage return/line feed, so you can print another text after
the ABC on the same line.
OVERVIEW
Here are some other commands that you can use for UART communications:
Waitkey( )
Waitkey will until a character is received in the serial buffer.
I s c h a r w a i t i n g( )
Returns 1 when a character is waiting in the hardware UART buffer.
I n k e y( )
Inkey returns the ASCII value of the first character in the serial input buffer.
Print
Sends a variable or non-variable string to the UART
ANOTHER EXAMPLE
This example shows how to use Ischarwaiting to test if there is a key pressed. And if there is, read
to a variable.
Goto Main
Myroutine:
'Statements
Main:
'Statements
End
serial output buffers. This buffering is implemented in BASCOM-AVR and can only be
used for hardware UART’s.
To configure a UART to use buffers, you need to use the Config statement.
More information can be found in BASCOM-Help. Search topic = "config serialin" 939 .
There is also a sample program “RS232BUFFER.BAS” in the samples folder if you wish
a demonstration of the buffering.
SOFTWARE UART
The previous examples used the hardware UART. That means the compiler uses the
internal UART registers and internal hardware (RxD(0) and TxD(0)) of the AVR. If you
don’t have a hardware UART you can also use a software UART.
The Bascom compiler makes it easy to “create” additional UART’s. Bascom creates
software UART’s on virtually every port pin.
Remember that a software UART is not as robust as a hardware UART, thus you can
get timing problems if you have lots of interrupts in your program.
For this example we use micro controller pins portc.1 and portc.2.
Connect portc.1 to TxD and portc.2 to RxD see the schematic above.
$regfile = "m88def.dat"
$crystal = 8000000
$baud = 19200
Dim B As Byte
Waitms 100
End
After you have programmed the controller and you connected the serial cable, open
the terminal emulator by clicking on in Bascom.
You should see the program asking for an alphanumerical input, and it should print
the input back to the terminal.
The sample above uses a MEGA161 or MEGA162 which has 2 UARTS. This way you
can have both a RS232 and RS485 interface.
The RS232 is used for debugging.
In order to test you need 2 or more similar circuits. One circuit would be the master.
The other(s) would be a slave.
The same hardware is used to test the MODBUS protocol. The bus need to be
terminated at both ends with a resistor. 100 ohm is a typical used value.
The GND of both circuits may not be connected ! Only connect point A and B from
both circuits. For industrial usage it is best to use an optical isolated level shifter.
$lib "modbus.lbx"
Config Print1 = Portb.1 , Mode = Set ' use portb.1 for the direction
Rs485dir Alias Portb.1
Config Rs485dir = Output
Rs485dir = 0 ' go to receive mode
Portc.0 = 1 ' a switch is connected to pinc.0 so activate pull up resistor
' TX RX
' COM0 PD.1 PD.0 monitor
' COM1 PB.3 PB.2 rs485
' PB.1 data direction rs485
A slave would simply listen to data, and once enough data received, send it back.
There is also SMBus. The I²C bus and the SMBus™ are essentially compatible with
each other. Normally devices, both masters and slaves, are freely interchangeable
between both buses. Both buses feature addressable slaves (although specific
address allocations can vary between the two).
The buses operate at the same speed, up to 100kHz, but the I²C bus has both
400kHz and 2MHz
versions. Complete compatibility between I2C and SMBus is ensured only below
100kHz.
I²C is a serial and synchronous bus protocol. In standard applications hardware and
timing are often the same. The way data is treated on the I²C bus is to be defined by
the manufacturer of the I²C master and slave chips.
In a simple I²C system there can only be one master, but multiple slaves. The
difference between master and slave is that the master generates the clock pulse.
The master also defines when communication should occur. For bus timing it is
important that the slowest slave should still be able to follow the master’s clock.
In other words the bus should be as fast as the slowest slave.
Note that more slave chips can be connected to the SDA and SCL lines, normally Rp
has a value of 1kOHM.
The clock generated by the master is called Serial Clock (SCL) and the data is called
Serial Data (SDA).
In most applications the micro controller is the I²C Master. Slave chips can be Real
Time Clocks and Temperature sensors. For example the DS1307 and the DS1624
from http://www.maximintegrated.com .
Of course you can also create your own I2C slaves by programming an ATTINY or
ATMEGA . See CONFIG I2CSLAVE 875
In that case there is AVR Master to AVR Slave communication.
Data can only occur after the master generates a start condition. A start condition is
a high-to-low transition of
the SDA line while SCL remains high. After each data transfer a stop condition is generated. A
stop condition is a low-to-high transition of the SDA line while SCL remains high.
As said a data transfer can occur after a start condition of the master. The length of
data sent over I²C is always 8 bit this includes a read/write direction bit, so you can
effectively send 7 bits every time.
The most significant bit MSB is always passed first on the bus.
If the master writes to the bus the R/W bit = 0 and if the master reads the R/W bit = 1.
After the R/W bit the master should generate one clock period for an acknowledgement ACK.
Each receiving chip that is addressed is obliged to generate an acknowledge after the
reception of each byte. A chip that acknowledges must pull down the SDA line during
the acknowledge clock pulse in such a way that the SDA line is stable LOW during the
HIGH period of the acknowledge related clock pulse.
After an acknowledge there can be a stop condition, if the master wishes to leave the
bus idle. Or a repeated start condition. A repeated start is the same as a start
condition.
When the master reads from a slave it should acknowledge after each byte received.
There are two reasons for the master not to acknowledge. The master sends a not
acknowledge if data was not received correctly or if the master wishes the stop
receiving.
The master can stop any communication on the bus at any time by sending a stop
condition.
BUS ADRESSING
Let’s say we have a slave chip with the address &B1101000 and that the master wishes
to write to that slave, the slave would then be in receiver mode, like this:
You can see here that the master always generates the start condition, then the
master sends the address of the slave and a “0” for R/W. After that the master sends
a command or word address. The function of that command or word address can be
found in the data sheet of the slave addressed.
After that the master can send the data desired and stop the transfer with a stop
condition.
Again the start condition and the slave address, only this time the master sends “1”
for the R/W bit. The slave can then begin to send after the acknowledge. If the
master wishes to stop receiving it should send a not acknowledge.
OVERVIEW of Routines
Config Sda = P o r t x . x
Configures a port pin for use as serial data SDA.
Config Scl = P o r t x . x
Configures a port pin for use as serial clock SCL.
I2cinit
Initializes the SCL and SDA pins.
I2cstart
Sends the start condition.
I2cstop
Sends the stop condition.
I2cwbyte
Writes one byte to an I²Cslave.
I2crbyte
Reads one byte from an I²Cslave.
I2csend
Writes a number of bytes to an I²Cslave.
I2creceive
Reads a number of bytes from an I²Cslave.
I2cstart
I2cwbyte I2c_address_of_slave
I2cwbyte Byte_to_send
I2cstop
(I 2 c s t a r t generates the start condition on the I2C bus were all devices are listen to.
After this we send the Slave address of the device we want to send a byte to. The I2C
slave with this address will send out a Ack where all other do nothing. Now you can
start to send a byte (or more bytes) to this Slave address. After this an I 2 c s t o p
release the bus.)
A typical I2C read to read one byte of data looks like this:
I2cstart
I2cwbyte I2c_address_of_slave
I2crbyte Databyte_to_read , Nack
I2cstop
(Nack indicates that the master do not want to read more bytes)
A typical I2C read to read one byte of data looks like this:
I2cstart
I2cwbyte I2c_address_of_slave
I2crbyte Databyte_to_read , Ack
I2crbyte Databyte_to_read , Nack
I2cstop
(Ack indicates that the master want to read more bytes from the slave and with the
last byte to read the master indicate this with Nack)
So BASCOM allows you to use I2C on every AVR chip. Most newer AVR chips have
build in hardware support for I2C. With the I2C_TWI lib you can use the TWI which
has advantages as it require less code.
To force BASCOM to use the TWI, you need to insert the following statement into your
code:
$LIB "I2C_TWI.LBX"
You also need to choose the correct SCL and SDA pins with the CONFIG SCL and
CONFIG SDA statements.
The TWI will save code but the disadvantage is that you can only use the fixed SCL
and SDA pins.
When using XMEGA, there is a difference : here you are supposed to use the
hardware TWI. So that is a default. To force to the software solution, use
$FORCESOFTI2C 540
See also:
Using USI (Universal Serial Interface) 289 , Config TWI 999 , CONFIG TWISLAVE 1005 ,
I2C_TWI 1607 , $FORCESOFTI2C 540
I2CSEND 1173 , I2CSTART 1174 , I2CSTOP 1174 , I2CRBYTE 1174 , I2CWBYTE 1174 , I2C_TWI
Library for using TWI 1607
Then program this sample into your micro controller and connect your micro
controller to the serial port of your PC.
$ r e g f i l e = "m88def.dat" 'Define the chip you use
$ c r y s t a l = 8000000 'Define speed
$hwstack = 40
$swstack = 30
$framesize = 40
Do
Waitms 25
Loop
End
There are many I2C slave chips available. The example shows the PCF8574. With the
additional TWI slave library you can make your own slave chips.
See example where Portc.4 and Portc.5 is SDA and SCL (the pull-up needs to be set
after i2cinit):
i2cinit
P o r t c. 4 = 1
P o r t c. 5 = 1
P82B96
· Isolates capacitance allowing 400 pF on Sx/Sy side and 4000 pF on Tx/Ty side
· 400 kHz operation over at least 20 meters of wire (see AN10148)
· Create Multi-drop configurations
· Supply voltage range of 2 V to 15 V with I2C-bus logic levels on Sx/Sy side
independent of supply voltage
· Splits I2C-bus signal into pairs of forward/reverse Tx/Rx, Ty/Ry signals for interface
with opto-electrical isolators and similar devices that need unidirectional input and
output signal paths.
P82B715
· Increase the total connected capacitance of an I2C-bus system to around 3000 pF
and drive signals over long cables to approximately 50m
· Multi-drop distribution of I2C-bus signals using low cost twisted-pair cables
- Is the system you are connecting the I2C to using a 7 Bit address or 8 Bit
address (8-bit addresses include the read/write bit) ?
Then you can try with shift left:
' you can simply do this; &HC4 is an example address
const someI2caddress= &H4C * 2
' this would shift the address to the left.
- It is important that you specify the proper crystal frequency. Otherwise it will
result in a wrong TWI clock frequency
- With following lib you do not use the software emulated TWI (I2C). You use the
hardware I2C (for the AVR's that have an hardware I2C)
$lib "i2c_twi.lbx" ' we do not use software
emulated I2C but the TWI
- By default BASCOM will use software routines for I2C.
- Do you have the right I2C read address ?
Here an example I2C write address which Bascom expects:
&B01000000 = &H40
Read address would be for this example:
&b01000001 = &h41
- In case of using TWI (I2C) Slave: Are you using the right library for your used
chip ?
With the I2C TWI Slave add-on library you get both libraries:
• i2cslave.lib and i2cslave.lbx : This library is used for AVR‘s which have no
'------------------------------------------------------------------
' (c) 1995-2021 MCS
' i2cscan.bas
'purpose : scan all i2c addresses to find slave chips
'use this sample in combination with twi-slave.bas
'Micro: Mega88
'------------------------------------------------------------------
$ r e g f i l e = "M88def.dat" ' the used chip
$ c r y s t a l = 8000000 ' frequency used
$baud = 19200 ' baud rate
$hwstack = 40
$swstack = 30
$framesize = 40
Dim B As Byte
P r i n t "Scan start"
For B = 0 To 254 Step 2 'for all odd addresses
I2cstart 'send start
I2cwbyte B 'send address
I f E r r = 0 Then 'we got an ack
P r i n t "Slave at : " ; B ; " hex : " ; Hex( b) ; " bin : " ; Bin( b)
End I f
I2cstop 'free bus
Next
P r i n t "End Scan"
End
When you want to receive/send multiple bytes, you need to keep track of them.
You can do this with a byte counter. this counter you would need to reset when
the slave is addressed.
To do this the lib need to be altered:
I2c_master_addressed:
Br = 0 'clear the byte counter
Bw = 0
return
in your code where the bytes are passed you can increase them.
The BR you increase when a byte is read, the BW you increase when a byte is
passed.
for example:
I2c_master_has_data:
I n c r Bw
Myarray( bw) = _a1
Return
Following the ATXMEGA Master and below the ATMEGA328P I2C Slave which was tested with the
ATXMEGA Master in I2C Software Mode:
Master
' Using ATXMEGA with software I2C routines to use also pins which are no hardware SDA/SCL
pins
' Needed Library: $lib "i2c.lbx"
' The $forcesofti2c directive force the ATXMEGA to use software I2c/TWI Library
' The hardware for this example is XMEGA-A3BU XPlained board from Atmel
' Don't forget the pull-ups on SDA/SCL pin !
' Bascom Version 2.0.7.6 or higher needed
$regfile = "XM256A3BUDEF.DAT"
$crystal = 32000000 '32MHz
$hwstack = 64
$swstack = 40
$framesize = 80
Config P o r t r. 0 = Output
Led0 A l i a s P o r t r. 0 'LED 0 (XMEGA-A3BU XPlained
board from Atmel )
Config P o r t r. 1 = Output
Led1 A l i a s P o r t r. 1 'LED 1 (XMEGA-A3BU XPlained
board from Atmel )
Dim B As Byte
'We use here Virtual port 0
Config Vport0 = B ' 'map portB to virtual port0
Do
Waitms 500
S e t Led1
Reset Led0
Waitms 500
Reset Led1
S e t Led0
Incr B
I2cstart
I2cwbyte &H24 ' address of I2C Slave
I2cwbyte B ' databyte to send to slave
I2cstop
Loop
' (
' )
$ r e g f i l e = "m328pdef.dat"
$ c r y s t a l = 12e6 '16MHz
$hwstack = 80
$swstack = 80
$framesize = 160
Enable I n t e r r u p t s
Return
Return
'this label is called when the master sends data and the slave has received the byte
'the variable TWI holds the received value
'Twi_btw is the BYTE NUMBER
T w i _ g o t d a t a:
Receive = Twi 'lesen
P r i n t ">>> " ; Twi 'Print what we have received
(ONLY FOR TESTING)
Return
'this label is called when the master receives data and needs a byte
'the variable twi_btr is a byte variable that holds the index of the needed byte
'so when sending multiple bytes from an array, twi_btr can be used for the index
'twi_btr is the BYTE NUMBER
Twi_master_needs_byte:
Return
'when the mast has all bytes received this label will be called
Twi_master_need_nomore_byte:
Return
'-------------------------------------------------------------------------------
This topic is written by Göte Haluza. He tested the new 1-wire search routines and is
building a weather station.
Dallas Semiconductor (DS) 1-wire. This is a brief description of DS 1-wire bus when
used in combination with BASCOM. For more detailed explanations about the 1-wire
bus, please go to http://www.maxim-ic.com. Using BASCOM makes the world a lot
easier. This paper will approach the subject from a "BASCOM-user-point-of-view".
With 2 wires, then DQ and ground is used on the device. Power is supplied on the DQ
line, which is +5V, and used to charge a capacitor in the DS device. This power is
used by the device for its internal needs during communication, which makes DQ go
low for short periods of time. This bus is called the 1-wire bus.
With 3 wires, when +5V is supplied to the VDD line of the device, and DQ + ground
as above. This bus is called the 2-wire bus.
So, the ground line is "not counted" by DS. But hereafter we use DS naming
conventions.
When the host (your micro controller (uC)) wants something to happen with the 1-
wire bus, it issues a reset-command. That is a very simple electric function that
happens then; the DQ goes active low for a time (480uS on original DS 1-wire bus).
This put the DS-devices in reset mode; then (they) send a presence pulse, and then
(they) listen to the host.
The presence pulse is simply an active low, this time issued by the device(s).
Now, the host cannot know what is on the bus, it is only aware of that at least 1 DS
device is attached on the bus.
All communication on the 1-wire bus is initialized by the host, and issued by time-
slots of active-low on a normally high line (DQ), issued by the device, which is
sending at the moment. The devices(s) internal capacitor supplies its power needs
during the low-time.
When you made a 1-wire-reset, all devices of the bus are listening. If you chose to
address only one of them, the rest of them will not listen again before you have made
a new 1-wire-reset on the bus.
I do not describe BASCOM commands in this text - they are pretty much self-
explanatory. But the uC has to write the commands to the bus - and thereafter read
the answer. What you have to write as a command depends on devices you are using
- and what you want to do with it. Every DS chip has a data sheet, which you can find
at http://www.dalsemi.com/datasheets/pdfindex.html. There you can find out all
about the actual devices command structure.
There are some things to have in mind when deciding which of the bus-types to use.
The commands, from BASCOM, are the same in both cases. So this is not a problem.
The +5V power-supply on the VDD when using a 2-wire bus has to be from a
separate power supply, according to DS. But it still works with taking the power from
the same source as for the processor, directly on the stabilizing transistor. I have not
got it to work taking power directly from the processor pin.
Some devices consume some more power during special operations. The DS1820
consumes a lot of power during the operation "Convert Temperature". Because the
sensors knows how they are powered (it is also possible to get this information from
the devices) some operations, as "Convert T" takes different amount of time for the
sensor to execute. The command "Convert T" as example, takes ~200mS on 2-wire,
but ~700mS on 1-wire. This has to be considered during programming.
If you use 2-wire, you don't have to read further in this part. You can do
simultaneously "Convert T" on all the devices you attach on the bus. And save time.
This command is the most power-consuming command, possible to execute on
several devices, I am aware of.
If you use 1-wire, there are things to think about. It is about not consuming more
power than you feed. And how to feed power? That depends on the devices (their
consumption) and what you are doing with them (their consumption in a specific
operation).
Only the processor pin as power supplier, will work < 5 sensors. (AVR, 1-wire-
functions use an internal pull-up. 8051 not yet tested). Don't even think of
simultaneous commands on multiple sensors.
With +5V through a 4K7 resistor, to the DQ-line, 70 sensors are tested. But, take
care, cause issuing "Convert T" simultaneously, would cause that to give false
readings. About ~15 sensors is the maximum amount of usable devices, which
simultaneously performs some action. This approach DS refers to as "pull-up
resistor".
With this in mind, a bus with up to 70 devices has been successfully powered this
way.
The resistor mentioned, 4K7, could be of smaller value. DS says minimum 1K5, I
have tested down to 500 ohm - below that the bus is not usable any more. (AVR).
Lowering the resistor feeds more power - and makes the bus more noise resistant.
But, the resistor minimum value is naturally also depending on the uC-pin electric
capabilities. Stay at 4K7 - which is standard recommendation.
DS recommends yet another approach, called "strong pull-up" which (short) works via
a MOS-FET transistor, feeding the DQ lines with enough power, still on 1-wire, during
power-consuming tasks. This is not tested, but should naturally work. Because this
functionality is really a limited one; BASCOM has no special support for that. But
anyway, we tell you about it, just in case you wonder. Strong pull-up has to use one
uC pin extra - to drive the MOS-FET.
DS standard examples show 100 meters cable lengths, so they say, that's no
problem. They also show examples with 300m cabling, and I think I have seen
something with 600-meter bus (but I cant find it again).
Transfer speed
On the original 1-wire bus, DS says the transfer speed is about 14Kbits /second. And,
if that was not enough, some devices has an overdrive option. That multiplies the
speed by 10. This is issued by making the communication-time-slots smaller (from 60
uS to 6uS ) which naturally will make the devices more sensitive, and CRC-error will
probably occur more often. But, if that is not an issue, ~140Kbit is a reachable speed
to the devices. So, whatever you thought before, it is FAST.
The BASCOM scanning of the bus is finds about 50 devices / second , and reading a
specific sensors value to a uC should be about 13 devices / second.
Topology
Of the 1w-net - that is an issue we will not cover so much. Star-net, bus-net? It
seems like you can mix that. It is a bus-net, but not so sensitive about that.
Naturally, if lot of cables are unwanted, this is a big benefit. And you only occupy 1
processor pin.
DS supplies with different types of devices, which all are made for interfacing an uC -
directly. No extra hardware. There are sensors, so you can get knowledge about the
real world, and there are also potentiometers and relays, so you can do something
about it. On the very same bus.
And the Ibutton approach from DS (ever heard of it?) is based on 1wire technology.
Maybe something to pick up.
BASCOM let you use an uC with 1wire-devices so easy, that (since now) that also has
to count as a benefit - maybe one of the largest. ;-)
Göte Haluza
System engineer
The interconnection between two SPI devices always happens between a master
device and a slave device. Compared to some peripheral devices like sensors which
can only run in slave mode, the SPI of the AVR can be configured for both master and
slave mode.
The mode the AVR is running in is specified by the settings of the master bit (MSTR)
in the SPI control register (SPCR).
Special considerations about the /SS pin have to be taken into account. This will be
described later in the section "Multi Slave Systems - /SS pin Functionality".
The master is the active part in this system and has to provide the clock signal a
serial data transmission is based on. The slave is not capable of generating the clock
signal and thus can not get active on its own.
The slave just sends and receives data if the master generates the necessary clock
signal. The master however generates the clock signal only while sending data. That
means that the master has to send data to the slave to read data from the slave.
configured as slave. The MISO, MOSI and SCK lines are connected with the
corresponding lines of the other part.
The mode in which a part is running determines if they are input or output signal
lines. Because a bit is shifted from the master to the slave and from the slave to the
master simultaneously in one clock cycle both 8-bit shift registers can be considered
as one 16-bit circular shift register. This means that after eight SCK clock pulses the
data between master and slave will be exchanged.
The system is single buffered in the transmit direction and double buffered in the
receive direction. This influences the data handling in the following ways:
1. New bytes to be sent can not be written to the data register (SPDR) / shift register
before the entire shift cycle is completed.
2. Received bytes are written to the Receive Buffer immediately after the
transmission is completed.
3. The Receive Buffer has to be read before the next transmission is completed or
data will be lost.
4. Reading the SPDR will return the data of the Receive Buffer.
After a transfer is completed the SPI Interrupt Flag (SPIF) will be set in the SPI Status
Register (SPSR). This will cause the corresponding interrupt to be executed if this
interrupt and the global interrupts are enabled. Setting the SPI Interrupt Enable
(SPIE) bit in the SPCR enables the interrupt of the SPI while setting the I bit in the
SREG enables the global interrupts.