ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 12.06.2025

Просмотров: 8267

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

© MCS Electronics, 1995-2007

BASCOM Language Reference

$ASM

Action

Start of inline assembly code block.

Syntax

$ASM

Remarks

Use $ASM together with $END ASM to insert a block of assembler code in your BASIC code. You can also precede each line with the ! sign.

Most ASM mnemonics can be used without the preceding ! too.

See also the chapter Mixing BASIC and Assembly and assembler mnemonics

Example

Dim C As Byte

Loadadr C , X 'load address of variable C into register X

$asm

Ldi R24,1 ; load register R24 with the constant 1 St X,R24 ; store 1 into variable c

$end Asm

Print C

End

$BAUD

Action

Instruct the compiler to override the baud rate setting from the options menu.

Syntax

$BAUD = var

Remarks

Var The baud rate that you want to use. This must be a numeric constant.

The baud rate is selectable from the Compiler Settings. It is stored in a configuration file. The $BAUD directive overrides the setting from the Compiler Settings.

page -202-

© MCS Electronics, 1995-2007

In the generated report, you can view which baud rate is actually generated. The generated baud rate does depend on the used micro and crystal.

When you simulate a program you will not notice any problems when the baud rate is not set to the value you expected. In real hardware a wrong baud rate can give weird results on the terminal emulator screen. For best results use a crystal that is a multiple of the baud rate.

See also

$CRYSTAL , BAUD

Example

$regfile = "m48def.dat" $crystal = 4000000 $baud = 19200

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

Print "Hello"

'Now change the baud rate in a program Baud = 9600

Print "Did you change the terminal emulator baud rate too?"

End

$BAUD1

Action

Instruct the compiler to set the baud rate for the second hardware UART.

Syntax

$BAUD1 = var

Remarks

Var

The baud rate that you want to use. This must be a

numeric constant.

In the generated report, you can view which baud rate is actually generated.

When you simulate a program you will not notice any problems when the baud rate is not set to the value you expected. In real hardware a wrong baud rate can give weird results on the terminal emulator screen. For best results use a crystal that is a multiple of the baud rate.

Some AVR chips have 2 UARTS. For example the Mega161, Mega162, Mega103 and Mega128. There are several other's and some new chips even have 4 UARTS.

See also

$CRYSTAL , BAUD , $BAUD

page -203-


© MCS Electronics, 1995-2007

Example

'-----------------------------------------------------------------------------

--

: (c) 1995-2005, MCS Electronics

'copyright

'micro

: Mega162

'suited for demo

: yes

'commercial addon needed

: no

'purpose

: demonstrates BAUD1 directive and BAUD1 statement

'-----------------------------------------------------------------------------

--

$regfile = "M162def.dat" $baud1 = 2400

$crystal= 14000000 ' 14 MHz crystal

Open "COM2:" For BINARY As #1

Print #1 , "Hello"

'Now change the baud rate in a program

Baud1 = 9600 ' Print #1 , "Did you change the terminal emulator baud rate too?"

Close #1

End

$BGF

Action

Includes a BASCOM Graphic File.

Syntax

$BGF "file"

Remarks

file

The file name of the BGF file to include.

Use SHOWPIC to display the BGF file. $BGF only task is to store the picture into the compressed BASCOM Graphics Format(BGF).

See also

SHOWPIC , PSET , CONFIG GRAPHLCD

Example

'-----------------------------------------------------------------

(c) 1995-2005 MCS Electronics

'

'

T6963C graphic display support demo

'-----------------------------------------------------------------

'The connections of the LCD used in this demo

'LCD pin

GND

connected to

' 1

GND

'2

GND

GND

'3

+5V

+5V

page -204-


© MCS Electronics, 1995-2007

'4

-9V

-9V potmeter

'5

/WR

PORTC.0

'6

/RD

PORTC.1

'7

/CE

PORTC.2

'8

C/D

PORTC.3

'9

NC

not conneted

'10

RESET

PORTC.4

'11-18

D0-D7

PA

'19

FS

PORTC.5

'20

NC

not connected

$crystal = 8000000

'First we define that we use a graphic LCD

Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 2 , Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 8

'The dataport is the portname that is connected to the data lines of the LCD 'The controlport is the portname which pins are used to control the lcd 'CE, CD etc. are the pin number of the CONTROLPORT.

' For example CE =2 because it is connected to PORTC.2

'mode 8 gives 240 / 8 = 30 columns , mode=6 gives 240 / 6 = 40 columns

'Dim variables (y not used)

Dim X As Byte , Y As Byte

'Clear the screen will both clear text and graph display

Cls

'Other options are :

' CLS TEXT to clear only the text display ' CLS GRAPH to clear only the graphical part

Cursor Off

Wait 1

'locate works like the normal LCD locate statement ' LOCATE LINE,COLUMN LINE can be 1-8 and column 0-30

Locate 1 , 1

'Show some text

Lcd "MCS Electronics"

'And some othe text on line 2 Locate 2 , 1 : Lcd "T6963c support"

Locate 3 , 1 : Lcd "1234567890123456789012345678901234567890"

Wait 2

Cls Text

'draw a line using PSET X,Y, ON/OFF

'PSET on.off param is 0 to clear a pixel and any other value to turn it on For X = 0 To 140

Pset X , 20 , 255

' set the pixel

Next

Wait

2

'Now it is time to show a picture 'SHOWPIC X,Y,label

'The label points to a label that holds the image data Showpic 0 , 0 , Plaatje

page -205-


© MCS Electronics, 1995-2007

Wait 2

Cls Text ' clear the text

End

'This label holds the mage data Plaatje:

'$BGF will put the bitmap into the program at this location $bgf "mcs.bgf"

'You could insert other picture data here

$BOOT

Action

Instruct the compiler to include boot loader support.

Syntax

$BOOT = address

Remarks

address The boot loader address.

Some new AVR chips have a special boot section in the upper memory of the flash. By setting some fuse bits you can select the code size of the boot section.

The code size also determines the address of the boot loader.

With the boot loader you can reprogram the chip when a certain condition occurs. The sample checks a pin to see if a new program must be loaded.

When the pin is low there is a jump to the boot address.

The boot code must always be located at the end of your program.

It must be written in ASM since the boot loader may not access the application flash rom. This because otherwise you could overwrite your running code!

The example is written for the M163. You can use the Upload file option of the terminal emulator to upload a new hex file. The terminal emulator must have the same baud rate as the chip. Under Options, Monitor, set the right upload speed and set a monitor delay of 20. Writing the flash take time so after every line a delay must be added while uploading a new file.

The $BOOT directive is replaced by $LOADER. $LOADER works much simpler. $BOOT is however still supported.

See also

$LOADER

Example

See BOOT.BAS from the samples dir. But better look at the $LOADERdirective.

page -206-

© MCS Electronics, 1995-2007

$CRYSTAL

Action

Instruct the compiler to override the crystal frequency options setting.

Syntax

$CRYSTAL = var

Remarks

var

A numeric constant with the Frequency of the crystal.

The frequency is selectable from the Compiler Settings. It is stored in a configuration file. The $CRYSTAL directive overrides this setting.

It is best to use the $CRYSTAL directive as the used crystal frequency is visible in your program that way.

The $CRYSTAL directive only informs the compiler about the used frequency. It does not set any fuse bit. The frequency must be know by the compiler for a number of reasons. First when you use serial communications, and you specify $BAUD, the compiler can calculate the proper settings for the UBR register. And second there are a number of routines like WAITMS, that use the execution time of a loop to generate a delay. When you specify $CRYSTAL = 1000000 (1 MHz) but in reality, connect a 4 MHz XTAL, you will see that everything will work 4 times as quick.

Most new AVR chips have an internal oscillator that is enabled by default. Checkthe data sheet for the default value.

See also

$BAUD , BAUD , CONFIG CLOCKDIV

Example

$regfile = "m48def.dat" $crystal = 4000000 $baud = 19200

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

Print "Hello world"

End

$DATA

Action

Instruct the compiler to store the data in the DATA lines following the $DATA directive, in code memory.

page -207-