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

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

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

Добавлен: 12.06.2025

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

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

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

© MCS Electronics, 1995-2007

Cls

'clear the LCD

display

'display this at

Lcd "Hello world."

the top line

Wait 1

'select the lower

Lowerline

line

Wait 1

'display this at

Lcd "Shift this."

the lower line

Wait 1

For A = 1 To 10

'shift the text to

Shiftlcd Right

the right

'wait a moment

Wait 1

Next

For A = 1 To 10

'shift the text to

Shiftlcd Left

the left

'wait a moment

Wait 1

Next

Locate 2 , 1

'set cursor

position

'display this

Lcd "*"

Wait 1

'wait a moment

Shiftcursor Right

'shift the cursor

Lcd "@"

'display this

Wait 1

'wait a moment

Home Upper

'select line 1 and

return home

'replace the text

Lcd "Replaced."

Wait 1

'wait a moment

Cursor Off Noblink

'hide cursor

Wait 1

'wait a moment

Cursor On Blink

'show cursor

Wait 1

'wait a moment

Display Off

'turn display off

Wait 1

'wait a moment

Display On

'turn display on

'-----------------NEW support for 4-line LCD------

Thirdline

Lcd "Line 3"

Fourthline

Lcd "Line 4"

'goto home on line

Home Third

three

Home Fourth

'first letteer

Home F

also works

Locate 4 , 1 : Lcd "Line 4"

Wait 1

'Now lets build a special character

'the first number is the characternumber (0-7)

'The other numbers are the rowvalues

'Use the LCD tool to insert this line

Deflcdchar 1 , 225 , 227 , 226 , 226 , 226 , 242 , 234 , 228

' replace ?

with number (0-7)

' replace ?

Deflcdchar 0 , 240 , 224 , 224 , 255 , 254 , 252 , 248 , 240

page -226-


© MCS Electronics, 1995-2007

with number (0-7)

'select data RAM

Cls

Rem it is important that a CLS is following the deflcdchar statements because it will set the controller back in datamode

Lcd Chr(0) ; Chr(1)

'print the special

character

'----------------- Now use an internal routine ------------

'value into ACC

_temp1 = 1

!rCall _write_lcd

'put it on LCD

End

$LCDVFO

Action

Instruct the compiler to generate very short Enable pulse for VFO displays.

Syntax

$LCDVFO

Remarks

VFO based displays need a very short Enable pulse. Normal LCD displays need a longer pulse. To support VFO displays this compiler directive has been added.

The display need to be instruction compatible with normal HD44780 based text displays. Noritake is the biggest manufactor of VFO displays.

The $LCDVFO directive is intended to be used in combination with the LCDroutines.

ASM

NONE

See also

NONE

Example

NONE

$LIB

Action

Informs the compiler about the used libraries.

Syntax

$LIB "libname1" [, "libname2"]

page -227-

© MCS Electronics, 1995-2007

Remarks

Libname1 is the name of the library that holds ASM routines that are used by your program. More filenames can be specified by separating the names by a comma.

The specified libraries will be searched when you specify the routines to use with the $EXTERNAL directive.

The search order is the same as the order you specify the library names.

The MCS.LBX will be searched last and is always included so you don't need to specify ti with the $LIB directive.

Because the MCS.LBX is searched last you can include duplicate routines in your own library. These routines will be used instead of the ones from the default MCS.LBX library. This is a good way when you want to enhance the MCS.LBX routines. Just copy the MCS.LIB to a new file and make the changes in this new file. When we make changes to the library your changes will be preserved.

Creating your own LIB file

A library file is a simple ASCII file. It can be created with the BASCOM editor, notepad or any other ASCII editor.

When you use BASCOM, make sure that the LIB extension is added to the Options, Environment, Editor, "No reformat extension".

This will prevent the editor to reformat the LIB file when you open it.

The file must include the following header information. It is not used yet but will be later. copyright = Your name

www = optional location where people can find the latest source email = your email address

comment = AVR compiler library

libversion = the version of the library in the format : 1.00 date = date of last modification

statement = A statement with copyright and usage information

The routine must start with the name in brackets and must end with the [END].

The following ASM routine example is from the MYLIB.LIB library.

[test]

Test:

ldd r26,y+2 ; load address of X

ldd r27,y+3

ld r24,x ; get value into r24

Inc r24 ; value + 1

St x,r24 ; put back

ldd r26,y+0 ; address pf Y

page -228-


© MCS Electronics, 1995-2007

ldd r27,y+1

st x,r24 ; store

ret ; ready

[END]

After you have saved your library in the LIB subdirectory you must compile it with the LIB Manager. Or you can include it with the LIB extension in which case you don’t have to compile it.

About the assembler.

When you reference constants that are declared in your basic programyou need to put a star(*) before the line.

'basic program

CONST myconst = 7

'asm lib

* sbi portb, myconst

By adding the *, the line will be compiled when the basic program is compiled. It will not be changed into object code in the LBX file.

When you use constants you need to use valid BASIC constants:

Ldi r24,12

Ldi r24, 1+1

Ldi r24, &B001

Ldi r24,0b001

Ldi r24,&HFF

Ldi r24,$FF

Ldi r24,0xFF

Other syntax is NOT supported.

See also

$EXTERNAL

Example

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

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

'In order to let this work you must put the mylib.lib file in the LIB dir 'And compile it to a LBX '-------------------------------------------------------------------------

page -229-

© MCS Electronics, 1995-2007

'define the used library $lib"mylib.lbx"

'you can also use the original ASM : '$LIB "mylib.LIB"

'also define the used routines $external Test

'this is needed so the parameters will be placed correct on the stack Declare Sub Test(byval X Asbyte , Y Asbyte)

'reserve some space

Dim Z As Byte

'call our own sub routine Call Test(1 , Z)

'z will be 2 in the used example

End

$LOADER

Action

Instruct the compiler to create a bootloader at the specified address.

Syntax

$LOADER = address

Remarks

address

The address where the bootloader is located. You can find this address in

the datasheet.

Most AVR chips have a so called boot section. Normally a chip will start at address 0 when it resets. This is also called the reset vector.

Chips that have a bootsection, split the flash memory in two parts. The bootsection is a small part of the normal flash and by setting a fusebit you select that the chip runs code at the bootsector when it resets instead of the normal reset vector.

Some chips also have fusebits to select the size of the bootloader.

The MCS bootloader sample is a serial bootloader that uses the serial port. It uses the X-modem checksum protocol to receive the data. Most terminal emulators can send X-modem checksum.

The sample is written so it supports all chips with a bootsection. You need to do the following :

indentify the $regfile directive for your chip

un-remark the line and the line with the CONST that is used for conditional compilation

remark all other $regfile lines and CONST lines.

compile the file

program the chip

set the fusebit so reset is pointed to the bootloader

set the fusebit so the bootsize is 1024 words

select the MCS Bootloader programmer.

page -230-


© MCS Electronics, 1995-2007

The bootloader is written to work at a baudrate of 57600. This works for most chips that use the internal oscillator. But it is best to check it first with a simple program. When you use a crystal you might even use a higher speed.

Do not forget that the MCS bootloader must be set to the same baud rate as the bootloader program.

Now make a new test program and compile it. Press F4 to start the MCS bootloader. You now need to reset the chip so that it will start the bootloader section. The bootloader will send a byte with value of 123 and the bascom bootloader receives this and thus starts the loader process.

There will be a stand alone bootloader available too. And the sample will be extended to support other AVR chips with bootsection too.

There is a $BOOT directive too. It is advised to use $LOADER as it allows you to write the bootloader in BASIC.

You can not use interrupts in your bootloader program as the interrupts will point to the reset vector which is located in the lower section of the flash. When you start to writing pages, you overwrite this part.

See also

$BOOT , $LOADERSIZE

Example

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

(c) 1995-2005, MCS

'

'

Bootloader.bas

'This sample demonstrates how you can write your own bootloader

'in BASCOM BASIC

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

'This sample will be extended to support other chips with bootloader 'The loader is supported from the IDE

'$regfile = "m88def.dat" 'Const Loader = 88

'$regfile = "m32def.dat" 'Const Loaderchip = 32

'$regfile = "m88def.dat" 'Const Loaderchip = 88

$regfile = "m162def.dat" Const Loaderchip = 162

#if Loaderchip = 88

'Mega88

$loader = $c00

'this address you

can find in the datasheet

'the loader address is the same as the boot vector address Const Maxwordbit = 5

page -231-

© MCS Electronics, 1995-2007

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 ,

Databits = 8 , Clockpol = 0

#endif

' Mega32

#if Loaderchip = 32

$loader = $3c00

' 1024

words

Const Maxwordbit = 6

'Z6 is

maximum bit

'

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 ,

Databits = 8 , Clockpol = 0

#endif

' Mega8

#if Loaderchip = 8

$loader = $c00

' 1024 words

Const Maxwordbit = 5

'Z5 is maximum bit

'

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 ,

Databits = 8 , Clockpol = 0

#endif

' Mega161

#if Loaderchip = 161

$loader = $1e00

' 1024 words

Const Maxwordbit = 6

'Z5 is maximum bit

#endif

'

' Mega162

#if Loaderchip = 162

$loader = $1c00

' 1024 words

Const Maxwordbit = 6

'Z5 is maximum bit

'

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

#endif

Const

Maxword =(2 ^ Maxwordbit) *

2

'128

Const

Maxwordshift = Maxwordbit +

1

$crystal = 8000000 '$crystal = 14745600

$baud = 57600 'this loader uses serial com

'It is VERY IMPORTANT that the baud rate matches the one of the boot loader

'do not try to use buffered com as we can not use interrupts

'Dim the used variables

Dim Bstatus As Byte , Bretries As Byte , Bblock As Byte , Bblocklocal As Byte Dim Bcsum1 As Byte , Bcsum2 As Byte , Buf(128) As Byte , Csum As Byte

Dim J As Byte , Spmcrval As Byte

' self program

command byte value

Dim Z As Word

'this is the Z

pointer word

' these bytes are

Dim Vl As Byte , Vh As Byte

used for the data values

'these vars

Dim Wrd As Byte , Page As Byte

contain the page and word address

'Mega 88 : 32 words, 128 pages

Disable Interrupts

'we do not use

ints

Waitms 1000

'wait 1 sec

page -232-