📄 assembly.lis
字号:
.text
;*********************************************************
; Place a 1 for the processor you want use
;*********************************************************
0001 MEGATYPE8 = 1
0000 MEGATYPE16 = 0
0000 MEGATYPE32 = 0
0000 MEGATYPE64 = 0
0000 MEGATYPE128 = 0
0000 MEGATYPE162 = 0
0000 MEGATYPE169 = 0
0000 MEGATYPE8515 = 0
0000 MEGATYPE8535 = 0
0000 MEGATYPE2313 = 0
0000
.if MEGATYPE64 | MEGATYPE128
SPMCR = 0x68
.else
0057 SPMCR = 0x57
.endif
;-----------------------------------------
; void write_page (unsigned int adr, unsigned char function);
; bits 8:15 adr addresses the page...(must setup RAMPZ beforehand!!!)
0000 _write_page::
0000 20D0 XCALL __WAIT_SPMEN__
0002 F801 movw r30, r16 ;move address to z pointer (R31 = ZH, R30 = ZL)
0004 20935700 STS SPMCR, R18 ;argument 2 decides function
0008 E895 SPM ;perform pagewrite
000A 0895 RET
000C
000C ;-----------------------------------------
000C
000C ; void fill_temp_buffer (unsigned int data, unsigned int adr);
000C ; bits 7:1 in adr addresses the word in the page... (2=first word, 4=second word etc..)
000C _fill_temp_buffer::
000C 1AD0 XCALL __WAIT_SPMEN__
000E F901 movw r30, r18 ;move adress to z pointer (R31=ZH R30=ZL)
0010 0801 movw r0, r16 ;move data to reg 0 and 1
0012 31E0 LDI R19, 0x01
0014 30935700 STS SPMCR, R19
0018 E895 SPM ;Store program memory,(r31,r30)<--(r1,r0);
001A 0895 RET
001C
001C ;-----------------------------------------
001C
001C ;unsigned int read_program_memory (unsigned int adr ,unsigned char cmd);
001C _read_program_memory::
001C F801 movw r30, r16 ;move adress to z pointer
001E 20FD SBRC R18, 0 ;read lockbits? (second argument = 0x09)
0020 20935700 STS SPMCR, R18 ;if so, place second argument in SPMEN register
0024
0024 0591 LPM r16, Z+
0026 1491 LPM r17, Z
0028
0028 0895 RET
002A
002A ;-----------------------------------------
002A
002A ;void write_lock_bits (unsigned char val);
002A _write_lock_bits::
002A 002E MOV R0, R16
002C 19E0 LDI R17, 0x09
002E 10935700 STS SPMCR, R17
0032 E895 SPM ;write lockbits
0034 0895 RET
0036
0036 ;-----------------------------------------
0036
0036 _enableRWW::
0036 05D0 XCALL __WAIT_SPMEN__
0038 B1E1 LDI R27,0x11
003A B0935700 STS SPMCR,R27
003E E895 SPM
0040 0895 RET
0042
0042 ;-----------------------------------------
0042
0042 __WAIT_SPMEN__:
0042 B0915700 LDS R27,SPMCR ; load SPMCR to R27
0046 B0FD SBRC R27,0 ; check SPMEN flag
0048 FCCF RJMP __WAIT_SPMEN__ ; wait for SPMEN flag cleared
004A 0895 RET
004C
004C ;-----------------------------------------
004C
004C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -