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

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

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

Добавлен: 12.06.2025

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

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

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

© MCS Electronics, 1995-2007

'We start with receiving a file. The PC must send this binary file

'some constants used in serial com Const Nak = &H15

Const Ack = &H06

Const Can = &H18

'we use some leds as indication in this sample , you might want to remove it

Config Portb = Output

'the stk200 has

Portb = 255

inverted logic for the leds

'$timeout = 1000000

'we use a timeout

$timeout = 1000000

'we use a timeout

'Do

'wait for the

Bstatus = Waitkey()

loader to send a byte

Print Chr(bstatus);

'did we received

If Bstatus = 123 Then

value 123 ?

Goto Loader

End If

'Loop

For J = 1 To 10

'this is a simple

indication that we start the normal reset vector

Toggle Portb : Waitms 100

Next

Goto _reset

'goto the normal

reset vector at address 0

'this is the loader routine. It is a Xmodem-checksum reception routine

Loader:

'this is a simple

For J = 1 To 3

indication that we start the normal reset vector

Toggle Portb : Waitms 500

Next

Spmcrval = 3 : Gosub Do_spm

' erase the first

page

' re-enable page

Spmcrval = 17 : Gosub Do_spm

Bretries = 10

'number of retries

Do

'checksum is 0

Csum = 0

when we start

' firt time send a

Print Chr(nak);

nack

Do

'wait for statuse

Bstatus = Waitkey()

byte

Select Case Bstatus

' start of

Case 1:

heading, PC is ready to send

'increase local

Incr Bblocklocal

block count

'checksum is 1

Csum = 1

Bblock = Waitkey() : Csum = Csum + Bblock

'get block

Bcsum1 = Waitkey() : Csum = Csum + Bcsum1

'get checksum

first byte

'get 128 bytes

For J = 1 To 128

page -233-


© MCS Electronics, 1995-2007

Buf(j) = Waitkey() : Csum = Csum + Buf(j)

Next

'get second

Bcsum2 = Waitkey()

checksum byte

'are the blocks

If Bblocklocal = Bblock Then

the same?

'is the checksum

If Bcsum2 = Csum Then

the same?

'yes go write the

Gosub Writepage

page

'acknowledge

Print Chr(ack);

Else

'no match so send

nak

Print Chr(nak);

End If

Else

'blocks do not

Print Chr(nak);

match

End If

' end of

Case 4:

transmission , file is transmitted

' send ack and

Print Chr(ack);

ready

Portb.3 = 0

' simple

indication that we are finished and ok

' start new

Goto _reset

program

' PC aborts

Case &H18:

transmission

' ready

Goto _reset

Case Else

' no valid data

Exit Do

End Select

Loop

'attempte left?

If Bretries > 0 Then

Waitms 1000

'decrease attempts

Decr Bretries

Else

'reset chip

Goto _reset

End If

Loop

'write one or more pages

Writepage:

'we write 2 bytes

For J = 1 To 128 Step 2

into a page

'get Low and High

Vl = Buf(j) : Vh = Buf(j + 1)

bytes

'store them into

lds r0, {vl}

r0 and r1 registers

lds r1, {vh}

'write value into

Spmcrval = 1 : Gosub Do_spm

page at word address

' word address

Wrd = Wrd + 2

increases with 2 because LS bit of Z is not used

' page is full

If Wrd = Maxword Then

Wrd = 0

'Z pointer needs

wrd to be 0

'write page

Spmcrval = 5 : Gosub Do_spm

Page = Page + 1

'next page

Spmcrval = 3 : Gosub Do_spm

' erase next page

page -234-


© MCS Electronics, 1995-2007

Spmcrval = 17 : Gosub Do_spm

' re-enable page

End If

Next

'indication that

Toggle Portb.2 : Waitms 10 : Toggle Portb.2

we write

Return

Do_spm:

' check for

Bitwait Spmcsr.selfprgen , Reset

previous SPM complete

'wait for eeprom

Bitwait Eecr.eepe , Reset

Z = Page

'make equal to

page

'shift to proper

Shift Z , Left , Maxwordshift

place

'add word

Z = Z + Wrd

lds r30,{Z}

lds r31,{Z+1}

Spmcsr = Spmcrval

'assign register

spm

'this is an asm

instruction

nop

nop

Return

'How you need to use this program: '1- compile this program

'2- program into chip with sample elctronics programmer '3- select MCS Bootloader from programmers

'4- compile a new program for example M88.bas '5- press F4 and reset your micro

'the program will now be uploaded into the chip with Xmodem Checksum

'you can write your own loader. And we will release a command line loader in the future

$LOADERSIZE

Action

Instruct the compiler that a boot loader is used so it will not overwrite the boot space.

Syntax

$LOADERSIZE = size

Remarks

size

The amount of space that is used by the boot loader.

When you use a boot loader it will use space from the available flash memory. The compiler does not know if you use a boot loader or not. When your programexceeds the available space and runs into the boot sector space, it will overwrite the boot loader.

The $loadersize directive will take the boot loader size into account so you will get an error when the target file gets too big.

When you select the MCS bootloader as programmer the IDE also will take into account the specified boot loader size.

page -235-


© MCS Electronics, 1995-2007

The directive can be used when you have a different programmer selected. For example an external programmer that does not know about the boot size.

See also

$LOADER

ASM

NONE

Example

NONE

$MAP

Action

Will generate label info in the report.

Syntax

$MAP

Remarks

The $MAP directive will put an entry for each line number with the address into the report file. This info can be used for debugging purposes with other tools.

See also

NONE

ASM

NONE

Example

$MAP

The report file will not contain the following section :

Code map

--------------------------------------------------------------------------------

Line Address(hex)

--------------------------------------------------------------------------------

1

0

9

36

26

39

30

3B

31

3E

32

48

page -236-

© MCS Electronics, 1995-2007

33

4B

36

50

37

56

42

5B

43

6C

44

7D

45

80

46

81

$NOCOMP

Action

Instruct the compiler not to compile the file.

Syntax

$NOCOMP

Remarks

This looks like an odd directive. Since you can split your program in multiple files, and you can create configuration files, you might open a file and try to compile it. Only normal project files can be compiled and you will get a number of errors and also unwanted files like error, report, etc.

To prevent that you compile a file that is intended to be included, you can insert the $NOCOMP directive.

Then the file will only be compiled when it is called from your main file, or other include file.

A file that is opened as thus the main file, and which includes the $NOCOMP directive, can not be compiled.

The IDE will see it as a successful compilation. This is important for the Batch Compiler.

See also

Batch Compiler

Example

$NOCOMP

$NOINIT

Action

Instruct the compiler to generate code without initialization code.

Syntax

$NOINIT

page -237-