|
发表于 2009-11-1 13:06:03
|
显示全部楼层
我比较傻看了X4还不是很明白怎么用,希望高人指点迷津
flash_read_sig:
RCALL WAIT_SPMEN // Wait for SPMEN flag cleared
MOV R31,R23
MOV R30,R22 // move adress to z pointer (R31=ZH R30=ZL)
LDI R20, ((1<<SPMEN) | (1<<SIGRD))
OUT _ASM_SFR_IO_(SPMCSR), R20 // argument 2 decides function (r18)
LPM // Store program memory
MOV R24, R0 // Store return value
RJMP WAIT_SPMEN // Wait for SPMEN flag cleared
flash_read_fuse:
RCALL WAIT_SPMEN // Wait for SPMEN flag cleared
MOV R31,R23
MOV R30,R22 // move adress to z pointer (R31=ZH R30=ZL)
LDI R20,((1<<SPMEN) | (1<<BLBSET))
OUT _ASM_SFR_IO_(SPMCSR), R20 // argument 2 decides function (r18)
LPM // Store program memory
MOV R24, R0 // Store return value
RJMP WAIT_SPMEN // Wait for SPMEN flag cleared
WAIT_SPMEN:
MOV R0, R18
IN R18,_ASM_SFR_IO_(SPMCSR) // get SPMCR into r18
SBRC R18,SPMEN
RJMP WAIT_SPMEN // Wait for SPMEN flag cleared
MOV R18, R0
RET
#define Flash_read_id1() ( flash_read_sig(0x0000)) //!< This macro function allows to read device ID1 of the product.
#define Flash_read_id2() ( flash_read_sig(0x0002)) //!< This macro function allows to read device ID2 of the product.
#define Flash_read_id3() ( flash_read_sig(0x0004)) //!< This macro function allows to read device ID3 of the product.
#define Flash_read_osccal() ( flash_read_sig(0x0001)) //!< This macro function allows to read the OSCAL byte of the product.
#define Flash_read_sn(pos) ( flash_read_sig((0x07*2)+pos))//!< This macro function allows to read the serial number of the product.
#define SN_LENGTH 10 //!< Size of the serial number containt in product. |
|