Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
BASCOM AVR, help reference (2007).PDF
Скачиваний:
305
Добавлен:
12.08.2013
Размер:
17.02 Mб
Скачать

© 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-