|
本帖最后由 uc_c++ 于 2012-4-30 18:01 编辑
文件直接加入到IAR工程。
没有仔细测试。
- //IAR寄存器使用规则:
- //R0-R3,R16-23,R30,R31 草稿寄存器
- //R4-R7 R24-R27 存储寄存器 (R4-R7也可设置为为全局变量寄存器)
- //R8-R15 全局变量寄存器
- PUBLIC __eeput8_16
- PUBLIC __eeput16_16
- PUBLIC __eeput32_16
-
- PUBLIC __eeget8_16
- PUBLIC __eeget16_16
- PUBLIC __eeget32_16
-
- //r16 data
- //r20:r21 addr
- RSEG CODE:NOROOT(1)
- __eeput8_16:
- ST -Y, R2 //保护寄存器R2
- IN R2, 0x3F //保护SREG
- CLI //关中断
- ??__eeput8_16_1:
- SBIC 0x1F, 0x01 //while(EECR & (1 << EEPE));
- RJMP ??__eeput8_16_1
- OUT 0x22, R21 //EEARH=ADDR_H
- OUT 0x21, R20 //EEARL=ADDR_L
- OUT 0x20, R16 //EEDR=DATA
- SBI 0x1F, 0x02 //EECR |= (1 << EEMPE);
- SBI 0x1F, 0x01 //EECR |= (1 << EEPE);
- OUT 0x3F, R2 //恢复SREG
- LD R2, Y+ //恢复寄存器R2
- RET
- //r16:r17 data
- //r20:r21 addr
- RSEG CODE:NOROOT(1)
- __eeput16_16
- CALL __eeput8_16
-
- SUBI R20, HIGH(-1)
- SBCI R21, LOW(-1)
- MOV R16,R17
- CALL __eeput8_16
- RET
-
- //r16:r17:r18:r19 data
- //r20:r21 addr
- RSEG CODE:NOROOT(1)
- __eeput32_16
- CALL __eeput8_16
-
- SUBI R20, HIGH(-1)
- SBCI R21, LOW(-1)
- MOV R16,R17
- CALL __eeput8_16
-
- SUBI R20, HIGH(-1)
- SBCI R21, LOW(-1)
- MOV R16,R18
- CALL __eeput8_16
-
- SUBI R20, HIGH(-1)
- SBCI R21, LOW(-1)
- MOV R16,R19
- CALL __eeput8_16
-
- RET
-
-
- //r16 data
- //r20:r21 addr
- RSEG CODE:NOROOT(1)
- __eeget8_16:
- ??__eeget8_16_1:
- SBIC 0x1F, 0x01
- RJMP ??__eeget8_16_1
- OUT 0x22, R21
- OUT 0x21, R20
- SBI 0x1F, 0x00
- NOP
- NOP
- IN R16, 0x20
- RET
-
- //r16:17 data
- //r20:r21 addr
- RSEG CODE:NOROOT(1)
- __eeget16_16:
- SUBI R20, HIGH(-1)
- SBCI R21, LOW(-1)
-
- CALL __eeget8_16
- MOV R17,R16
-
- SUBI R20, HIGH(1)
- SBCI R21, LOW(1)
- CALL __eeget8_16
- RET
-
- //r16:17:R18:R19 data
- //r20:r21 addr
- RSEG CODE:NOROOT(1)
- __eeget32_16:
- SUBI R20, HIGH(-3)
- SBCI R21, LOW(-3)
-
- CALL __eeget8_16
- MOV R19,R16
-
- SUBI R20, HIGH(1)
- SBCI R21, LOW(1)
- CALL __eeget8_16
- MOV R18,R16
-
- SUBI R20, HIGH(1)
- SBCI R21, LOW(1)
- CALL __eeget8_16
- MOV R17,R16
-
- SUBI R20, HIGH(1)
- SBCI R21, LOW(1)
- CALL __eeget8_16
- RET
-
-
- END
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|