move DP[0], #0010h ; Location of variable in data memory
move Acc, @DP[0] ; Read variable
add #1 ; Increment variable value by 1
move @DP[0], Acc ; Store variable back in data memory
#define VarA #0020h
#define VarB #0021h
#define VarC #0022h
move DP[0], VarA ; Point to VarA variable
move Acc, @DP[0] ; Read value of variable
move DP[0], VarB ; Point to VarB variable
move @DP[0], Acc ; Copy VarA to VarB
move DP[0], VarC ; Point to VarC variable
move @DP[0], #1234h ; Set VarC = 1234h
segment code
move DP[0], #VarA ; Point to VarA
move Acc, @DP[0] ; Get current value of VarA
add #1 ; Increment it
move @DP[0], Acc ; Store value back in VarA
segment data
VarA:
dw 0394h ; Initial value for VarA
$include(maxQ2000.inc)
;; Code memory (flash) : 0000h-7FFFh (word addr)
;; Data memory (RAM) : 0000h-03FFh (word addr)
org 0000h
ljump start ; Skip over password area
org 0020h
start:
move DPC, #1Ch ; Set all pointers to word mode
move DP[0], #0F000h ; Check first variable value (flag)
lcall UROM_moveDP0 ; 'move GR, @DP[0]' executed by Utility ROM
move Acc, GR
cmp #1234h
jump NE, copyToFlash
;; This is the "free-running" code, executed on subsequent power-ups, that copies
;; values from the flash back into their proper data segment locations.
move DP[0], #0F000h ; Source: Flash location 7000h
move BP, #0 ; Dest: Start of RAM
move Offs, #0
move LC[0], #100h ; Copy 256 words
lcall UROM_copyBuffer
jump main
;; This is the first-pass code. A bit of a trick here; because MAX-IDE enters
;; and exits the loader separately when loading the code and data segment files,
;; the application is allowed to execute briefly before the data segment file
;; has been loaded. The first four lines under copyFlash ensure that the
;; application waits for MAX-IDE to load the data segment file before continuing.
copyToFlash:
move DP[0], #0h ; Wait for flag variable to be loaded by MAX-IDE.
move Acc, @DP[0] ; Note that this will reset the application; the
cmp #1234h ; data segment is not loaded while the application
jump NE, copyToFlash ; is still running.
move DP[0], #0 ; Start of RAM variable area
move A[4], #7000h ; Location in flash to write to
move LC[0], #100h ; Store 256 words in flash 7000h-70FFh
copyToFlash_loop:
move DP[0], DP[0] ; Refresh the data pointer to read values correctly,
; because calling UROM_flashWrite changes memory
; contexts and affects the cached @DP[0] value
move A[0], A[4] ; Location to write
move A[1], @DP[0]++ ; Value to write (taken from RAM)
lcall UROM_flashWrite
move Acc, A[4]
add #1
move A[4], Acc
djnz LC[0], copyToFlash_loop
main:
move PD0, #0FFh ; Set all port 0 pins to output
move PO0, #000h ; Drive all port 0 pins low (LEDs off)
move DPC, #1Ch ; Set pointers to word mode
move DP[0], #varA
move Acc, @DP[0]
cmp #1234h ; Verify that the variable is set correctly
jump NE, fail
pass:
move PO0, #55h
sjump $
fail:
sjump $
segment data
org 0000h
varA:
dw 1234h
org 00FFh
varB:
dw 5678h
end