;DS18B20 data-> 20H-28H DQ EQU P3.5 ORG 0000H ;FOSC=6MHZ
MAIN: LCALL RESET ;reset 1820 LCALL SKIP_ROM ;"CCH" ;LCALL MATCH_ROM ;"55H" LCALL CONVERT ;"44H" LCALL DELAY1s ;1S LCALL RESET ;reset 1820 LCALL SKIP_ROM ;"CCH" ;LCALL MATCH_ROM ;"55H" LCALL READ_SCRTCH ;READ CONVERT T DATA 9BYTES LCALL MATH lcall display LJMP MAIN COMMAND: LCALL RESET LCALL READ_ROM ; LCALL RESET LCALL READ_SCRTCH ;Read Scratchpad->20H-28H ; LCALL RESET LCALL WRITE_SCRCH ;Write Scratchpad TH TL (CONFIG) ; LCALL RESET LCALL SCRTCH_EE ;SCRTCH->EEPROM ; LCALL RESET LCALL EE_SCRTCH ;EEPROM->SCRTCH ; ;--------- ROM FUNCTION COMMANDS -------- READ_ROM: ;Read ROM [33h] MOV R0,#40H ;READ ROM DATA 9BYTES=>40H-48H MOV A,#33H LCALL RD9BYTE RET MATCH_ROM: ;Match ROM [55h] MOV A,#55H LCALL WRBYTE MOV R0,#40H MATCHLOOP: MOV A,@R0 LCALL WRBYTE INC R0 CJNE R0,#48H,MATCHLOOP RET SKIP_ROM: ;Skip ROM [CCh] MOV A,#0CCH LCALL WRBYTE RET SEARCH_ROM: ;Search ROM [F0h] LJMP $ RET ALARM_SEARCH: ;Alarm Search [ECh] LJMP $ RET ;--------- MEMORY COMMAND FUNCTIONS -------- WRITE_SCRCH: ;Write Scratchpad [4Eh] MOV A,#4EH LCALL WRBYTE MOV A,29H ;TH LCALL WRBYTE MOV A,2AH ;TL LCALL WRBYTE MOV A,2BH ;DS18B20 D6.D5=00 01 10 11 LCALL WRBYTE ;TEMPRECHER = 9 10 11 12 BITS RET READ_SCRTCH: ;Read Scratchpad [BEh] MOV R0,#20H ;9BYTES DATA =>20H-28H MOV A,#0BEH LCALL RD9BYTE RET SCRTCH_EE: ;Copy Scratchpad [48h] ;SCRTCH->EEPROM MOV A,#48H LCALL WRBYTE RET CONVERT: ;Convert T [44h] MOV A,#44H LCALL WRBYTE RET
EE_SCRTCH: ;Recall E2 [B8h] ;EEPROM->SCRTCH MOV A,#0B8H LCALL WRBYTE RET READ_POWER: ;Read Power Supply [B4h] LJMP $ ;------------------------------------------------------------------- RESET: MOV R6,#10H ;RESET 1820 CLR DQ LCALL DELAY_600 SETB DQ LCALL DELAY_60 LOOP: JNB DQ,RSTEND LCALL DELAY_15 DJNZ R6,LOOP SJMP RESET RSTEND: JNB DQ,$ RET RD9BYTE: LCALL WRBYTE LCALL DELAY_15 MOV R6,#9 ;READ 9BYTES DATA RD_LOP: MOV R5,#8 RT_LOP: SETB DQ LCALL DELAY_45 ;H 45US CLR DQ ;L 2US NOP SETB DQ ;H 15US LCALL DELAY_15 MOV C,DQ RRC A LCALL DELAY_45 DJNZ R5,RT_LOP MOV @R0,A INC R0 DJNZ R6,RD_LOP RET WRBYTE: MOV R6,#8 ;WRITR 1 BYTE WB_LOP: CLR DQ LCALL DELAY_15 RRC A MOV DQ,C LCALL DELAY_45 SETB DQ LCALL DELAY_15 DJNZ R6,WB_LOP RET DELAY_60: LCALL DELAY_15 DELAY_45: LCALL DELAY_15 DELAY_30: LCALL DELAY_15 DELAY_15: MOV R7,#2 DJNZ R7,$ RET DELAY_600: MOV R7,#100 DJNZ R7,$ RET DELAY1s: MOV R6,#200 DL_LOP2: DJNZ R7,$ DJNZ R7,$ DJNZ R7,$ DJNZ R6,DL_LOP2 RET |