读写24c02里面的数据(IIC通讯)

JSR F_Start
	MOV #10100000B ;硬件地址+写
	STR R_Temp0
	JSR F_Send8Bit
	;应答位
	JSR F_Wait_Ask
	LJNC L_MainPress1Key ;应答失败,重新写地址
	    
	    
	    
	    
	    
	    
	                     
	MOV #000H ;           选择00H写数据
	STR R_Temp0
	JSR F_Send8Bit
		;应答位
	JSR F_Wait_Ask
	LJNC L_MainPress1Key ;应答失败,重新写地址
	
	MOV #01010101B ;           把FE写入00H
	STR R_Temp0
	JSR F_Send8Bit
		;应答位
	JSR F_Wait_Ask
	LJNC L_MainPress1Key ;应答失败,重新写地址
	JSR F_SCL_OutLow
	NOP
	NOP
	JSR F_Stop
	NOP
	NOP                           ;写数据完成
	
L_MainPress1Key1:	
	JSR F_Start
	MOV #10100000B ;硬件地址+写
	STR R_Temp0
	JSR F_Send8Bit
	JSR F_Wait_Ask
	LJNC L_MainPress1Key ;应答失败,重新写地址
	
	
	MOV #000H ;           选择00H读数据
	STR R_Temp0
	JSR F_Send8Bit
		;应答位
	JSR F_Wait_Ask
	LJNC L_MainPress1Key1 ;应答失败,重新写地址
	
	JSR F_Start
	MOV #10100001B ;硬件地址+读
	STR R_Temp0
	JSR F_Send8Bit
	JSR F_Wait_Ask
	LJNC L_MainPress1Key1 ;应答失败,重新写地址
	
	NOP
	JSR F_SCL_OutLow
	NOP
	NOP
	
	
	
	
	
	
	
	JSR F_SDA_OutHight
	NOP
	NOP
	JSR F_SDA_InPutHight
	
	JSR F_ReadBeat
	
	MOV R_Temp2    
	NOP
	
	JSR F_SCL_OutLow             ;给EEprom发送非应答,结束通讯
	NOP
	NOP
	NOP
	NOP
	JSR F_SDA_OutHight
	NOP
	NOP
	NOP
	NOP
	JSR F_SCL_OutHight
	NOP
	NOP
	NOP
	NOP
	JSR F_SCL_OutLow
	NOP
	NOP
	NOP
	NOP
	JSR F_SDA_OutLow
	NOP
	NOP
	NOP
	NOP
	
	JSR F_Stop
	MOV R_Temp2
	NOP
	
	
	
	
	
	
	
	JSR F_SCL_OutLow


F_ReadBeat:	
	JSR F_SDA_InPutHight
	MOV #08
	STR R_Temp0
	MOV #00H
	STR R_Temp2
L_LOOOP8:	
	JSR F_SDA_InPutHight
	NOP
	NOP
	JSR F_SCL_OutHight
	NOP
	NOP
	MOV P_P0_DAT	
	EOR #FFH
	AND #00001000B
	LJNZ     L_IS0
L_IS1:	
	JSR F_SCL_OutLow
	NOP
	NOP
	SET   STATUS,C 
	RCLR  R_Temp2
	JMP L_CHECKBIT
	
	
	
	
L_IS0:		
	JSR F_SCL_OutLow
	NOP
	NOP	
	CLR   STATUS,C  
	RCLR  R_Temp2
L_CHECKBIT:
	MOV R_Temp2
	DECR 	R_Temp0
	LJNZ L_LOOOP8
	RTS
	
F_Stop:	JSR F_SCL_OutHight
	NOP
	NOP
	NOP
	NOP
	JSR F_SDA_OutHight

	NOP
	NOP
	NOP
	NOP
	
	RTS
	
F_Wait_Ask:	
	
	JSR F_SCL_OutHight
	NOP
	NOP
	
	
	
	
	
	
	JSR F_SDA_InPutHight
	;JSR F_ScanKeyPortInit
	JSR	F_ScanDelay	
	MOV P_P0_DAT	
	EOR #FFH
	AND #00001000B
	LJZ L_Fail
L_AskSucc:
	JSR F_SDA_OutLow
	JSR F_SCL_OutLow
	  NOP
	  NOP           
			 
			
			
			
			
			
			
			
			SET   STATUS,C  
			RTS  		
L_Fail:			
			CLR   STATUS,C  
			RTS               

	
	
	
	

F_Start:
	
         JSR F_SDA_OutHight
      
	 JSR F_SCL_OutHight
	NOP
	NOP	
	JSR F_SDA_OutLow
	NOP
	NOP

	RTS	

F_Send8Bit:
	MOV #8
	STR R_Temp1
         ; MOV    R_Temp0
 
L_LOOP8:	
	RCLR  R_Temp0
	LJC		L_Send1
L_Send0:	
	JSR F_SCL_OutLow
	NOP
	NOP
	JSR F_SDA_OutLow
	NOP
	NOP
	JSR F_SCL_OutHight
	NOP
	NOP
	NOP
	NOP
	JMP L_DEC_R_Temp1
	
L_Send1:	
	JSR F_SCL_OutLow
	NOP
	NOP
	JSR F_SDA_OutHight
	NOP
	NOP
	JSR F_SCL_OutHight
	NOP
	NOP
	NOP
	NOP
L_DEC_R_Temp1:

	DECR 	R_Temp1
	LJNZ L_LOOP8
	NOP
	NOP
	NOP
	NOP
	NOP
	
	JSR  F_SCL_OutLow
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	
	RTS
F_SDA_InPutHight:		
				;CWDT					   //清看门狗		默认18ms溢出复位						
					MOV	  #00001000B
					STC	  P0CR       ;1=输入口   有效:BIT 3-0
					
					MOV Port0
					ORA #00001000B
					STR	  Port0      ;P0寄存器   有效:BIT 3-0
					
					MOV #11110111B
					STR	PU2_0      ;0=上拉     有效:BIT 5-0
			
					RTS		
	
	
	
	
F_SCL_OutLow:	
	
					CWDT	
					MOV Port0
					AND #11111011B
					STR	  Port0      ;P0寄存器   有效:BIT 3-0
									  ; //清看门狗		默认18ms溢出复位						
					MOV	  #0
					STC	  P0CR       ;1=输入口   有效:BIT 3-0
					
					MOV #FFH
					STR	PU2_0      ;0=上拉     有效:BIT 5-0

					RTS	
	
	
	
	
F_SDA_OutLow:	
				CWDT		
				MOV Port0
					AND #11110111B
					STR	  Port0      ;P0寄存器   有效:BIT 3-0			   //清看门狗		默认18ms溢出复位						
					MOV	  #0
					STC	  P0CR       ;1=输入口   有效:BIT 3-0
					
					MOV #FFH
					STR	PU2_0    ;0=上拉     有效:BIT 5-0

					RTS	
	
F_SDA_OutHight:	
	
					CWDT	
					MOV Port0
					ORA #00001000B
					STR	  Port0      ;P0寄存器   有效:BIT 3-0				   //清看门狗		默认18ms溢出复位						
					MOV	  #0
					STC	  P0CR       ;1=输入口   有效:BIT 3-0
					
					MOV #FFH
					STR	PU2_0  ;0=上拉     有效:BIT 5-0

					RTS	
	
	
	
	
F_SCL_OutHight:	
				CWDT	
				MOV Port0
					ORA #00000100B
					STR	  Port0      ;P0寄存器   有效:BIT 3-0				   //清看门狗		默认18ms溢出复位						
					MOV	  #0
					STC	  P0CR       ;1=输入口   有效:BIT 3-0
					
					MOV #FFH
					STR	PU2_0    ;0=上拉     有效:BIT 5-0

					RTS		
	
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值