打印

请教24C02的问题。读的时候出错.

[复制链接]
1986|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
irico|  楼主 | 2008-6-22 10:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我的24C02在写程序正常,但在读的时候,写入A1指令后24C02没有返回应答信号,请大家帮忙看看。

;--------------------------------------------------------------------
NOPP8:
        CALL    NOPP4
NOPP4:        
        NOP
        NOP
        NOP
        NOP
        
        RET
;--------------------------------------------------------------------
; P0.3--SDA     P0.4--SCL

EEPROM_START:
        LD      BTCON, #02H       
        OR      P0, #18H        ;SDA=1,SCL=1;
        CALL    NOPP8
        AND     P0, #0F7H       ;SDA=0;
        CALL    NOPP8
        AND     P0, #0E7H       ;SCL=0;SDA=0;   
        RET                
;--------------------------------------------------------------------
; P0.3--SDA     P0.4--SCL
EEPROM_STOP:     
        AND     P0, #0E7H
        CALL    NOPP8
        OR      P0, #10H
        CALL    NOPP8
        OR      P0, #18H 
                                                                      RET                                                                                                                                                                                      
;-------------------------------------------------------------------
; P0.3--SDA     P0.4--SCL
EEPROM_ERR:
        OR      ERROR_FLAG, #01H         
        JP      T, EEPROM_STOP   
;-------------------------------------------------------------------
; P0.3--SDA     P0.4--SCL
MASTER_ACK:
        AND     P0, #0E7H
        CALL    NOPP8
        OR      P0, #10H
        CALL    NOPP8
        AND     P0, #0E7H
 
        RET
;---------------------------------------------------------------------
; P0.3--SDA     P0.4--SCL
EEPROM_ACK:
        OR      P0, #10H                ;SCL=1;
        CALL    NOPP8
        CLR     R3
  ACK_LOOP:
        DEC     R3
        JR      Z,EEPROM_ERR
        CALL    NOPP8
        TM      P0, #00001000B          ;SDA=?
        JR      NZ, ACK_LOOP
        AND     P0, #0EFH               ;SCL=0; 
        
        RET
;-------------------------------------------------------------------
; P0.3--SDA        P0.4--SCL
;
EEPROM_RD:
        LD      R0, #08H
        CLR     R1
        AND     P0, #0EFH       ;SCL=0;
        CALL    NOPP8 
        OR      P0,#08H         ;SDA=1;
EEPROM_RD0: 
        CALL    NOPP8           
        OR      P0, #10H        ;SCL=1;
        CALL    NOPP8 
        
        RCF
        TM      P0, #08H        ;SDA=?
        JR      Z, EEPROM_RD1
        SCF        
EEPROM_RD1:
        RLC     R1
        AND     P0, #0EFH       ;SCL=0;
        DEC     R0
        JR      NZ, EEPROM_RD0
        AND     P0, #0EFH       ;SCL=0;  
          
        RET
;--------------------------------------------------------------------
; P0.3--SDA        P0.4--SCL
EEPROM_WR:
        LD      R0, #08H
EEPROM_WR0:
        AND     P0, #0E7H         ;SCL=0,SDA=0;
        CALL    NOPP8
        TM      R1, #80H
        JR      Z, EEPROM_WR1               
        OR      P0, #08H          ;SDA=1;
EEPROM_WR1:
        RL      R1     
        CALL    NOPP8
        OR      P0, #10H          ;SCL=1;
        CALL    NOPP8
        AND     P0, #0EFH         ;SCL=0;
        NOP
        DEC     R0           
        JR      NZ, EEPROM_WR0
;           
        RET
;--------------------------------------------------------------------
; P0.3--SDA        P0.4--SCL
EEPROM_RD_PAGE:
        CALL    EEPROM_START
        
        LD      R1,#0A0H
        CALL    EEPROM_WR               ;>> R1 = R0 <<.
        CALL    EEPROM_ACK 

        LD      R1,R2
        CALL    EEPROM_WR               ;>> R1 = R0 <<.
        CALL    EEPROM_ACK 

        CALL    EEPROM_START
        
        LD      R1,#0A1H
        CALL    EEPROM_WR          ;>> R1 = R0 <<.
        CALL    EEPROM_ACK         ;问题就在这里:24C02没有ACK信号。
EEPROM_RD_PAGE1:
        CALL    EEPROM_RD               ;>> = R0  << R1.
        LD      EEPROM_DATA,R1                
        JP      T, EEPROM_STOP         
;--------------------------------------------------------------------
; P0.3--SDA        P0.4--SCL
EEPROM_WR_PAGE:     
        CALL    EEPROM_START
        LD      R1, #0A0H
        CALL    EEPROM_WR               ;>> R1 = R0 <<.
        CALL    EEPROM_ACK   
;
        LD      R1,EEPROM_ADDRESS
        CALL    EEPROM_WR               ;>> R1 = R0 <<.
        CALL    EEPROM_ACK                
EEPROM_WR_PAGE1: 
        LD      R1,EEPROM_DATA
        CALL    EEPROM_WR               ;>> R1 = R0 <<.
        CALL    EEPROM_ACK                                           
        JP      T, EEPROM_STOP                  

相关帖子

沙发
irico|  楼主 | 2008-6-22 12:32 | 只看该作者

问题已解决,原来在检测ACK时,SDA没有设为输入。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

51

主题

155

帖子

0

粉丝