千家论坛_智能建筑与智能家居技术交流社区

标题: X5045读写子程序 [打印本页]

作者: 豆儿    时间: 2003-8-8 18:52
标题: X5045读写子程序
X5045读写子程序 ;**************extern EEPROM const define****** WREN EQU 06H ;X5045 WRITE ENABLE ;WRDI EQU 04H ;X5045 write disable RDSR EQU 05H ;Read x5045 status register WRSR EQU 01H ;Write x5045 status register READ EQU 03H ;Read data from x5045 instruction WRITE EQU 02H ;Write data to x5045 instruction STATUS EQU 30H ;STATUS REGISTER INIT ;********************************************************* ;***********读数据子程序******************** ;数据最终在以R0间址的缓冲区中 RDX5_DAT: CLR A RDX5_DAT0: MOV R7,#08H ;8bit RDX5_DAT1: CLR C SETB SCK NOP NOP NOP NOP NOP CLR SCK ;产生下降边沿 NOP NOP NOP NOP NOP MOV C,SDO ;读出数据 RLC A ;SO->Cy->ACC.0 DJNZ R7,RDX5_DAT1 MOV @R0,A ;数据暂存在缓冲区 INC R0 CLR ACC DJNZ R1,RDX5_DAT0 ;未完继续 CLR SCK RET ;********写数据子程序******************* ;********数据长度在 R1,数据在RO指向的地址中 WRITE_CD: CLR A CLR C WRITE_CD0: MOV A,@R0 MOV R7,#08H WRITE_CD1: CLR SCK RLC A MOV SDI,C CPL SCK ;SCK FOR 1 DATA IS valideation CLR C DJNZ R7,WRITE_CD1 INC R0 ;NEXT BYTE DJNZ R1,WRITE_CD0 CLR SDI RET ;**************读状态寄存器子程序 READ_STATUS: CLR A CLR C CLR CS MOV A,#RDSR ;Read status register instruction MOV R7,#08H ; READ_ST1: CLR SCK RLC A ;FRIST FOR MSB BIT MOV SDI,C SETB SCK ;Make the rising edge of clock CLR C DJNZ R7,READ_ST1 MOV R7,#08H READ_ST2: CLR C SETB SCK ;DATA FROM X5045 TO CPU by the fulling edge NOP NOP NOP NOP NOP CPL SCK NOP NOP NOP NOP NOP MOV C,SDO RLC A ;SO->Cy->ACC.0 DJNZ R7,READ_ST2 MOV 30H,A ;DATA SAVE TO "X5045" BUFFER CLR SCK SETB CS RET 另外,如果不用X5045的看门狗的时候,请把它给禁止掉。 ;**************STATUS REGISTER INIT***** ST_INIT: LCALL READ_STATUS MOV A,30H JB ACC.0,$-5 ;X5045 IS BUSY THEN TURN CONTIUE TO READ MOV R0,#30H MOV @R0,#WRSR ;WRITE STATUS REGISTER INSTRUCTION MOV R1,#01H CLR CS ;X5045 CHIP IS SELECTED LCALL WRITE_CD MOV R0,#30H MOV @R0,#STATUS MOV R1,#01H LCALL WRITE_CD ;WRITE DATA TO X5045 SETB CS RET 提供给大家作为参考!
作者: hlm123    时间: 2006-5-31 13:09
看不懂啊  你是从哪些地方学的啊  谢谢
作者: 豆儿    时间: 2006-6-1 12:39

这是汇编语言,最简单的了,没学过啊!


作者: fclvgyfe    时间: 2006-6-5 12:29
要这么多NOP做什么,以为SPI不够快啊.




欢迎光临 千家论坛_智能建筑与智能家居技术交流社区 (http://bbs.qianjia.com:8020/) Powered by Discuz! X3.2