e dang làm code về này mà no cứ sai cứ hiển thị giá trị đầu ra là ff thôi và khi thay đổi nhiệt độ khi mô phỏng bằng proteus thì dù thay đổi nhiệt độ nhưng nó vẫn không thay đổi các bác giúp e chỉ ra nó sai chỗ nào với : thank các bác ghé qua đây là code của nó e dùng thạch anh 4Mhz
PROCESSOR P16F877A
INCLUDE<P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF &_BODEN_OFF &_PWRTE_ON &_XT_OSC &_WRT_OFF &_LVP_OFF &_CPD_OFF
T1 EQU 0X20
T2 EQU 0X21
TAM EQU 0X22
DEM EQU 0X23
NHO EQU 0X24
TEMP1 EQU 0X25
TEMP2 EQU 0X26
XEM EQU 0X27
THEM EQU 0X28
;--------------------------TRE THOI GIAN T1X5 uS
ORG 0X00
GOTO MAIN
DELAY
MOVWF T1
MOVLW D'1'
MOVWF T2
D1
DECFSZ T1
GOTO +2
DECFSZ T2
GOTO D1
RETURN
;---------------------------------
WRITEBYTE
MOVWF TAM
MOVLW D'8' ; 8 LAN VONG LAP
MOVWF DEM
D2
RRF TAM,1
BTFSS STATUS,C
GOTO OUT_0
GOTO OUT_1
;-------------------------------
OUT_0 ; suat 1 bit ra ngoai
BCF PORTB,4
MOVLW D'12' ;12X5uS
CALL DELAY
BSF PORTB,4
NOP
NOP ; 2uS
GOTO OUTBYTE1
;==================OUT BIT 1
OUT_1
BCF PORTB,4
NOP
NOP ;2uS
BSF PORTB,4
MOVLW D'12'
CALL DELAY ; 20uS
GOTO OUTBYTE1
OUTBYTE1
DECFSZ DEM,1
GOTO D2
RETLW 0
;==============================================
READ_BYTE
MOVLW D'8'
MOVWF DEM
D3
CALL READ_BIT
MOVWF NHO
RRF NHO,1
RLF TEMP1
RLF TEMP2,1
BSF STATUS,RP0
BCF TRISB,4
BCF STATUS,RP0
DECFSZ DEM
GOTO D3
MOVLW D'24'
CALL DELAY
RETLW 0
READ_BIT
BCF PORTB,4
NOP
NOP ; 2uS
BSF PORTB,4
NOP
NOP
NOP
NOP
BSF STATUS,RP0 ; BANK 1
BSF TRISB,4 ; PORTA,BIT 4 LAM DAU VAO
BCF STATUS,RP0 ; BANK 0
BTFSC PORTB,4
RETLW 1
RETLW 0
;================================================= =================
INITIALIZATION
BCF PORTB,4
MOVLW D'100' ; 500uS
CALL DELAY
BSF PORTB,4
MOVLW D'100' ; 500uS
CALL DELAY
BSF PORTB,4
RETLW 0
;----------------------- CHUONG TRINH CHINH
MAIN
BSF STATUS,RP0
MOVLW 0X00
MOVWF TRISB
BCF STATUS,RP0 ; BANK 0
;CONFIG DS1820
LOOP
CLRF TEMP1
CLRF TEMP2
CALL INITIALIZATION ; INITIALIZATION DS1820
MOVLW 0XCC;SKIP ROM
MOVWF XEM
CALL WRITEBYTE
MOVLW 0X44 ; CONVERT
MOVWF XEM
CALL WRITEBYTE
; LAY GIA TRI
MOVLW D'24'
CALL DELAY
CALL INITIALIZATION ; INITIALIZATION DS1820
MOVLW 0XCC
MOVWF XEM
CALL WRITEBYTE
MOVLW 0XBE
MOVWF XEM
CALL WRITEBYTE
CALL READ_BYTE
GOTO LOOP
END
PROCESSOR P16F877A
INCLUDE<P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF &_BODEN_OFF &_PWRTE_ON &_XT_OSC &_WRT_OFF &_LVP_OFF &_CPD_OFF
T1 EQU 0X20
T2 EQU 0X21
TAM EQU 0X22
DEM EQU 0X23
NHO EQU 0X24
TEMP1 EQU 0X25
TEMP2 EQU 0X26
XEM EQU 0X27
THEM EQU 0X28
;--------------------------TRE THOI GIAN T1X5 uS
ORG 0X00
GOTO MAIN
DELAY
MOVWF T1
MOVLW D'1'
MOVWF T2
D1
DECFSZ T1
GOTO +2
DECFSZ T2
GOTO D1
RETURN
;---------------------------------
WRITEBYTE
MOVWF TAM
MOVLW D'8' ; 8 LAN VONG LAP
MOVWF DEM
D2
RRF TAM,1
BTFSS STATUS,C
GOTO OUT_0
GOTO OUT_1
;-------------------------------
OUT_0 ; suat 1 bit ra ngoai
BCF PORTB,4
MOVLW D'12' ;12X5uS
CALL DELAY
BSF PORTB,4
NOP
NOP ; 2uS
GOTO OUTBYTE1
;==================OUT BIT 1
OUT_1
BCF PORTB,4
NOP
NOP ;2uS
BSF PORTB,4
MOVLW D'12'
CALL DELAY ; 20uS
GOTO OUTBYTE1
OUTBYTE1
DECFSZ DEM,1
GOTO D2
RETLW 0
;==============================================
READ_BYTE
MOVLW D'8'
MOVWF DEM
D3
CALL READ_BIT
MOVWF NHO
RRF NHO,1
RLF TEMP1
RLF TEMP2,1
BSF STATUS,RP0
BCF TRISB,4
BCF STATUS,RP0
DECFSZ DEM
GOTO D3
MOVLW D'24'
CALL DELAY
RETLW 0
READ_BIT
BCF PORTB,4
NOP
NOP ; 2uS
BSF PORTB,4
NOP
NOP
NOP
NOP
BSF STATUS,RP0 ; BANK 1
BSF TRISB,4 ; PORTA,BIT 4 LAM DAU VAO
BCF STATUS,RP0 ; BANK 0
BTFSC PORTB,4
RETLW 1
RETLW 0
;================================================= =================
INITIALIZATION
BCF PORTB,4
MOVLW D'100' ; 500uS
CALL DELAY
BSF PORTB,4
MOVLW D'100' ; 500uS
CALL DELAY
BSF PORTB,4
RETLW 0
;----------------------- CHUONG TRINH CHINH
MAIN
BSF STATUS,RP0
MOVLW 0X00
MOVWF TRISB
BCF STATUS,RP0 ; BANK 0
;CONFIG DS1820
LOOP
CLRF TEMP1
CLRF TEMP2
CALL INITIALIZATION ; INITIALIZATION DS1820
MOVLW 0XCC;SKIP ROM
MOVWF XEM
CALL WRITEBYTE
MOVLW 0X44 ; CONVERT
MOVWF XEM
CALL WRITEBYTE
; LAY GIA TRI
MOVLW D'24'
CALL DELAY
CALL INITIALIZATION ; INITIALIZATION DS1820
MOVLW 0XCC
MOVWF XEM
CALL WRITEBYTE
MOVLW 0XBE
MOVWF XEM
CALL WRITEBYTE
CALL READ_BYTE
GOTO LOOP
END
Comment