- •Table of Contents
- •Index
- •Keyword Reference
- •Installation
- •Installation of BASCOM
- •BASCOM IDE
- •Running BASCOM-AVR
- •File New
- •File Close
- •File Save
- •File Save As
- •File Print Preview
- •File Print
- •File Exit
- •View PinOut
- •View PDF viewer
- •View Error Panel
- •Edit Undo
- •Edit Redo
- •Edit Cut
- •Edit Copy
- •Edit Paste
- •Edit Find
- •Edit Find Next
- •Edit Replace
- •Edit Goto
- •Edit Toggle Bookmark
- •Edit Goto Bookmark
- •Edit Indent Block
- •Edit Unindent Block
- •Edit Remark Block
- •Program Compile
- •Program Syntax Check
- •Program Show Result
- •Program Simulate
- •Program Send to Chip
- •Tools Terminal Emulator
- •Tools LCD Designer
- •Tools LIB Manager
- •Tools Graphic Converter
- •Tools Stack Analyzer
- •Tools Plugin Manager
- •Tools Batch Compile
- •Options Compiler
- •Options Compiler Chip
- •Options Compiler Output
- •Options Compiler Communication
- •Options Compiler I2C, SPI, 1WIRE
- •Options Compiler LCD
- •Options Communication
- •Options Environment
- •Options Simulator
- •Options Programmer
- •Supported Programmers
- •ISP programmer
- •PG302 programmer
- •Sample Electronics cable programmer
- •KITSRUS Programmer
- •MCS Universal Interface Programmer
- •STK500 Programmer
- •Lawicel BootLoader
- •AVR ISP Programmer
- •USB-ISP Programmer
- •MCS Bootloader
- •Options Monitor
- •Options Printer
- •Window Cascade
- •Window Tile
- •Window Arrange Icons
- •Window Minimize All
- •Help About
- •Help Index
- •Help MCS Forum
- •Help MCS Shop
- •Help Support
- •Help Knowledge Base
- •Help Credits
- •BASCOM Editor Keys
- •Program Development Order
- •PlugIns
- •Font Editor
- •PinOut
- •BASCOM HARDWARE
- •Additional Hardware
- •AVR Internal Hardware
- •AVR Internal Registers
- •AVR Internal Hardware TIMER0
- •AVR Internal Hardware TIMER1
- •AVR Internal Hardware Watchdog timer
- •AVR Internal Hardware Port B
- •AVR Internal Hardware Port D
- •Adding XRAM
- •Attaching an LCD Display
- •Memory usage
- •Using the 1 WIRE protocol
- •Using the SPI protocol
- •Power Up
- •Chips
- •ATtiny22
- •ATtiny13
- •ATtiny15
- •ATtiny25
- •ATtiny45
- •ATtiny85
- •ATtiny26
- •ATtiny2313
- •ATMEGA8
- •ATMEGA16
- •ATMEGA32
- •ATMEGA48
- •ATMEGA88
- •ATMEGA168
- •ATMEGA64
- •ATMEGA103
- •ATMEGA128
- •ATMEGA161
- •ATMEGA162
- •ATMEGA163
- •ATMEGA165
- •ATMEGA169
- •ATMEGA323
- •ATMEGA603
- •ATMEGA8515
- •ATMEGA8535
- •BASCOM Language Fundamentals
- •Changes compared to BASCOM-8051
- •Language Fundamentals
- •Mixing ASM and BASIC
- •Assembler mnemonics
- •Reserved Words
- •Error Codes
- •Newbie problems
- •Tips and tricks
- •ASCII chart
- •BASCOM Language Reference
- •$BAUD
- •$BAUD1
- •$BOOT
- •$CRYSTAL
- •$DATA
- •$DEFAULT
- •$EEPLEAVE
- •$EEPROM
- •$EEPROMHEX
- •$EXTERNAL
- •$FRAMESIZE
- •$HWSTACK
- •$INCLUDE
- •$INITMICRO
- •$LCDPUTCTRL
- •$LCDPUTDATA
- •$LCDRS
- •$LCDVFO
- •$LOADER
- •$LOADERSIZE
- •$NOCOMP
- •$NOINIT
- •$NORAMCLEAR
- •$PROG
- •$PROGRAMMER
- •$REGFILE
- •$ROMSTART
- •$SERIALINPUT
- •$SERIALINPUT1
- •$SERIALINPUT2LCD
- •$SERIALOUTPUT
- •$SERIALOUTPUT1
- •$SWSTACK
- •$TIMEOUT
- •$TINY
- •$WAITSTATE
- •$XRAMSIZE
- •$XRAMSTART
- •1WIRECOUNT
- •1WRESET
- •1WREAD
- •1WSEARCHFIRST
- •1WSEARCHNEXT
- •1WVERIFY
- •1WWRITE
- •ACOS
- •ALIAS
- •ASIN
- •BASE64DEC
- •BASE64ENC
- •BAUD
- •BAUD1
- •BINVAL
- •BIN2GRAY
- •BITWAIT
- •BITS
- •BLOAD
- •BSAVE
- •BUFSPACE
- •BYVAL
- •CALL
- •CHECKSUM
- •CIRCLE
- •CLEAR
- •CLOCKDIVISION
- •CLOSE
- •CLOSESOCKET
- •CONFIG
- •CONFIG 1WIRE
- •CONFIG ACI
- •CONFIG ADC
- •CONFIG ATEMU
- •CONFIG BCCARD
- •CONFIG CLOCK
- •CONFIG CLOCKDIV
- •CONFIG COM1
- •CONFIG COM2
- •CONFIG COMx
- •CONFIG DATE
- •CONFIG DCF77
- •CONFIG DEBOUNCE
- •CONFIG I2CDELAY
- •CONFIG I2CSLAVE
- •CONFIG INPUT
- •CONFIG INTx
- •CONFIG GRAPHLCD
- •CONFIG KBD
- •CONFIG KEYBOARD
- •CONFIG LCD
- •CONFIG LCDBUS
- •CONFIG LCDMODE
- •CONFIG LCDPIN
- •CONFIG PORT
- •CONFIG PRINT
- •CONFIG PRINTBIN
- •CONFIG PS2EMU
- •CONFIG RC5
- •CONFIG SDA
- •CONFIG SCL
- •CONFIG SERIALIN
- •CONFIG SERIALIN1
- •CONFIG SERIALOUT
- •CONFIG SERIALOUT1
- •CONFIG SINGLE
- •CONFIG SPI
- •CONFIG SERVOS
- •CONFIG TCPIP
- •CONFIG TIMER0
- •CONFIG TIMER1
- •CONFIG TIMER2
- •CONFIG TWI
- •CONFIG TWISLAVE
- •CONFIG WAITSUART
- •CONFIG WATCHDOG
- •CONFIG X10
- •CONFIG XRAM
- •CONST
- •COSH
- •COUNTER0 and COUNTER1
- •CPEEK
- •CPEEKH
- •CRYSTAL
- •CURSOR
- •DATA
- •DAYOFWEEK
- •DAYOFYEAR
- •DATE$
- •DATE
- •DEBUG
- •DEBOUNCE
- •DECR
- •DECLARE FUNCTION
- •DECLARE SUB
- •DEFxxx
- •DEFLCDCHAR
- •DELAY
- •DISABLE
- •DISKFREE
- •DISKSIZE
- •DISPLAY
- •DO-LOOP
- •DriveCheck
- •DriveGetIdentity
- •DriveInit
- •DriveReset
- •DriveReadSector
- •DriveWriteSector
- •DTMFOUT
- •ECHO
- •ELSE
- •ENABLE
- •ENCODER
- •EXIT
- •FILEATTR
- •FILEDATE
- •FILEDATETIME
- •FILELEN
- •FILETIME
- •FLUSH
- •FORMAT
- •FOR-NEXT
- •FOURTHLINE
- •FRAC
- •FREEFILE
- •FUSING
- •GETADC
- •GETATKBD
- •GETATKBDRAW
- •GETDSTIP
- •GETDSTPORT
- •GETKBD
- •GETRC
- •GETRC5
- •GETTCPREGS
- •GETSOCKET
- •GLCDCMD
- •GLCDDATA
- •GOSUB
- •GOTO
- •GRAY2BIN
- •HEXVAL
- •HIGH
- •HIGHW
- •HOME
- •I2CINIT
- •I2CRECEIVE
- •I2CSEND
- •I2START,I2CSTOP, I2CRBYTE, I2CWBYTE
- •IDLE
- •IF-THEN-ELSE-END IF
- •INCR
- •INITFILESYSTEM
- •INITLCD
- •INKEY
- •INPUTBIN
- •INPUTHEX
- •INPUT
- •INSTR
- •ISCHARWAITING
- •KILL
- •LCASE
- •LCDAT
- •LCDCONTRAST
- •LEFT
- •LINE
- •LINE INPUT
- •LTRIM
- •LOAD
- •LOADADR
- •LOADLABEL
- •LOADWORDADR
- •LOCAL
- •LOCATE
- •LOOKDOWN
- •LOOKUP
- •LOOKUPSTR
- •LOWERLINE
- •MAKEBCD
- •MAKEINT
- •MAKEDEC
- •MAKETCP
- •MEMCOPY
- •NBITS
- •ON INTERRUPT
- •ON VALUE
- •OPEN
- •PEEK
- •POKE
- •POPALL
- •POWER
- •POWERDOWN
- •POWERSAVE
- •PRINTBIN
- •PSET
- •PS2MOUSEXY
- •PULSEIN
- •PULSEOUT
- •PUSHALL
- •RC5SEND
- •RC5SENDEXT
- •RC6SEND
- •READ
- •READEEPROM
- •READMAGCARD
- •RESET
- •RESTORE
- •RETURN
- •RIGHT
- •ROTATE
- •ROUND
- •RTRIM
- •SECELAPSED
- •SECOFDAY
- •SEEK
- •SELECT-CASE-END SELECT
- •SETFONT
- •SETTCP
- •SETTCPREGS
- •SENDSCAN
- •SENDSCANKBD
- •SERIN
- •SEROUT
- •SETIPPROTOCOL
- •SHIFT
- •SHIFTCURSOR
- •SHIFTIN
- •SHIFTOUT
- •SHIFTLCD
- •SHOWPIC
- •SHOWPICE
- •SINH
- •SOCKETCONNECT
- •SOCKETLISTEN
- •SOCKETSTAT
- •SONYSEND
- •SOUND
- •SPACE
- •SPIIN
- •SPIINIT
- •SPIMOVE
- •SPIOUT
- •SPLIT
- •START
- •STCHECK
- •STOP
- •STRING
- •SYSSEC
- •SYSSECELAPSED
- •SYSDAY
- •SWAP
- •TCPCHECKSUM
- •TCPREAD
- •TCPWRITE
- •TCPWRITESTR
- •TANH
- •THIRDLINE
- •TIME$
- •TIME
- •TOGGLE
- •TRIM
- •UCASE
- •UDPREAD
- •UDPWRITE
- •UDPWRITESTR
- •UPPERLINE
- •VARPTR
- •VERSION
- •WAIT
- •WAITKEY
- •WAITMS
- •WAITUS
- •WHILE-WEND
- •WRITE
- •WRITEEEPROM
- •X10DETECT
- •X10SEND
- •#IF ELSE ENDIF
- •International Resellers
- •International Resellers
- •ASM Libraries
- •EXTENDED I2C
- •MCSBYTE
- •MCSBYTEINT
- •TCPIP
- •LCD4BUSY
- •GLCD
- •GLCDSED
- •LCD-EPSON
- •AVR-DOS File System
- •CF Card
- •Compact FlashCard Driver
- •Elektor CF-Interface
- •XRAM CF-Interface for simulation
- •New CF-Card Drivers
- •Floating Point
- •FP_TRIG
- •DOUBLE
- •I2C SLAVE
- •I2CSLAVE
- •I2C TWI Slave
- •SPISLAVE
- •DATE TIME
- •EUROTIMEDATE
- •DATETIME
- •PS2-AT Mouse and Keyboard Emulation
- •AT_EMULATOR
- •PS2MOUSE_EMULATOR
- •BCCARD
- •BCCARD
- •BCDEF
- •BCCALL
- •BCRESET
- •Tools
- •LCD RGB-8 Converter
|
© 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-
© 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-
