打印

18b20的引脚怎么没有存在信号的反馈啊??

[复制链接]
2682|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
drink1|  楼主 | 2007-8-25 16:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我的源代码如下:DAT BIT P1.0 ;数据通信口
WDLSB DATA 30H ;读出的温度低字节
WDMSB DATA 31H ;读出的温度高字节
;***************************************************************
                        ORG             0000H
                        LJMP             MAIN
                        ORG             000BH
                        SJMP             IT0P ;定时显示

;****************************************************************
;定时显示子程序,采用循环扫描方式
;显示缓冲区40H~47H
                        ORG              0040H
IT0P:

                        MOV             P0,40H ;最后一位值送p0
                        ORL             P0,#70H; 点亮最后一位
                        CALL             T1MS
                        MOV              P0,41H
                        ORL             P0,#60H
                        CALL             T1MS
                        MOV                P0,42H
                        ORL                P0,#50H
                        CALL          T1MS
                        MOV                 P0,43H
                        ORL                P0,#40H
                        MOV                TH0,#LOW(65536-10000) ;定时器10MS中断
                        MOV                TL0,#HIGH(65536-10000)
                        RETI
T1MS:                mov                r5,#00h ;延时子程序
tt:                    mov             r6,#9
                        djnz            r6,$
                        djnz             r5,tt
                        ret

;*********************************************************
;主程序:

MAIN:                 MOV                SP,#60H
                        MOV             P2,#0FFH
                        MOV                R2,#8
                        MOV             R0,#40H;
OVER:                MOV             @R0,#00H
                        INC             R0
                        DJNZ             R2,OVER
                        MOV             TMOD,#01H
                        MOV             TH0,#LOW(65536-10000)
                        MOV             TL0,#HIGH(65536-10000)
                        SETB             EA
                        SETB             ET0
                        SETB             TR0
LOOP:             LCALL         DSWD                                                     ;调用读出DS18B20温度程序
                        SJMP             LOOP                                                     ; 读出DS18B20温度程序
;---------------------------------------------------------------------
;读出DS18B20温度子程序
;---------------------------------------------------------------------

DSWD:                CLR             EA
                        LCALL         RST
                        JNB             F0,ACKEND                                         ;如果没有应答,返回主程序
                        MOV             R0,#0CCH
                        LCALL         SEND_BYTE                                         ;CCH指令跳过ROM匹配

                        MOV             R0,#44H                                             ;发出温度转换命令
                        LCALL         SEND_BYTE

                        SETB             EA
                        SETB            DAT        
                        MOV             48H,#85H                                                 ;廷时2s以上准备读
SS2:                 MOV             49H,#0FAH
SS1:                 MOV             4AH,#0FAH
SS0:              DJNZ             4AH,SS0
                        DJNZ             49H,SS1
                        DJNZ             48H,SS2
                        CLR                EA
                        LCALL         RST
                        JNB             F0,ACKEND                                                ;
                        MOV             R0,#0CCH                                             ;跳过ROM匹配
                        LCALL            SEND_BYTE
                        MOV             R0,#0BEH                                             ;发出读温度命令
                        LCALL         SEND_BYTE
                        LCALL         READ_BYTE
                        MOV                WDLSB,A
                        LCALL         READ_BYTE
                        MOV                WDMSB,A
                        LCALL         TRANS12
ACKEND:         SETB            P1.0
                        SETB             EA
                        RET
;**********************************************************
;温度转换程序:精确到:0.06 ;
TRANS12:        MOV A,30H
                        ANL A,#0F0H
                        MOV 3AH,A
                        MOV A,31H
                        ANL A,#0FH
                        ORL A,3AH
                        SWAP A
                        MOV B,#10
                        DIV AB
                        MOV 43H,A
                        MOV 42H,B 
                        MOV DPTR,#TABB
                        MOV A,30H
                        ANL A,#0FH
                        MOV B,#2
                        MUL AB
                        MOVC A,@A+DPTR
                        MOV 41H,A
                        MOV A,30H
                        ANL A,#0FH
                        MOV B,#2
                        MUL AB
                        INC A
                        MOVC A,@A+DPTR
                        MOV 40H,A
                        RET
                        TABB: DB 0,0,0,6,1,2,1,8,2,5,3,1,3,7,4,3,5,0
                        DB 5,6,6,2,6,8,7,5,8,1,8,7,9,3
;---------------------------------------
;发送一个字节程序
;---------------------------------------
SEND_BYTE:     
                        MOV A,R0
                        MOV R5,#8
SEN3:             CLR C
                        RRC A
                        JC SEN1
                        LCALL WRITE_0
                        SJMP SEN2
SEN1:             LCALL WRITE_1
SEN2:             DJNZ R5,SEN3 ; 循环8次,写一个字节
                        RET

;---------------------------------------
;读一个字节程序
;---------------------------------------
READ_BYTE:
                        MOV R5,#8
READ1:             LCALL READ
                        RRC A
                        DJNZ R5,READ1 ; 循环8次,读一个字节
                        MOV R0,A
                        RET



;------------------------------------------------------
;复位程序,如果复位有应答置位F0'1',没有就置位F0为'0'
;------------------------------------------------------
RST:                 SETB                         DAT
                        MOV                            R6,#24H
DELAY_3us:    DJNZ                        R6,DELAY_3us
                        CLR                         DAT
                        MOV                         R6,#0F0H                         ;主机发复位脉冲持续60μs×9=540μs
                        MOV                            R5,#09H
DELAY_540us:DJNZ                        R6,$
                        DJNZ                        R5,DELAY_540us
                        SETB                         DAT                                 ;主机释放总线,口线改为输入
                        MOV                         R6,#24H
                        DJNZ                         R6,$
                        CALL                        CHCK                                 ;调用应答检查程序
                        MOV                         R6,#3CH    
                        DJNZ                         R6,$
                        SETB                         DAT
                        RET    
CHCK:             MOV                         C,DAT
                        JC                             RST0
                        SETB                         F0                                     ;检测到信号,置位F0
                        SJMP                         CHCK0
RST0:             CLR                         F0                                    ;未准备好F0复位
CHCK0:             RET

WRITE_0:                                                                                 ;写0,持续60us
                        CLR                         DAT
                        MOV                         R6,#0F0H
                        DJNZ                         R6,$
                        SETB                         DAT
                        RET
WRITE_1:        CLR                         DAT                                 ;写1,持续60us
                        MOV                            R6,#0FH
                        DJNZ                        R6,$    
                        SETB                         DAT
                        MOV                          R6,#0F0H
                        DJNZ                        R6,$
                        RET
;-----------------------    
;读一位数据程序
;-----------------------
READ:             SETB                      DAT                                     ;先复位至少1us产生读起始信号
                        MOV                            R6,#08H
                        DJNZ                        R6,$    
                        CLR                         DAT
                        MOV                            R6,#08H                             ;保持15us的低电平
                        DJNZ                        R6,$    
                        SETB                      DAT                                     ;置位DAT准备接收数据
                        MOV                            R6,#50H
                        DJNZ                        R6,$    
                        MOV                          C,DAT
                        MOV                         R6,#78H
                        DJNZ                         R6,$
                        RET
END





不知道为什么会没有存在信号的啊.而且换了2个18B20的了,还是没有存在信号/
请高手看看啊!!!!@!!!

相关帖子

沙发
maychang| | 2007-8-26 12:04 | 只看该作者

没必要写这么长的程序,更没有必要贴出来

检查这种最底层的操作,程序约简单越好。对楼主的问题,应该把这些读温度、温度转换以及定时显示等程序都去掉,只保留必不可少的那些,然后用示波器看信号波形是否正确。这样才能够判断问题所在。

使用特权

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

本版积分规则

4

主题

4

帖子

1

粉丝