??? 02/03/08 20:16 Read: times |
#150265 - 1 wire routines example Responding to: ???'s previous message |
Hi, 1 wire family is communication that sensitive with the timing. so you can't interrupt while execute the device. I put some subroutine and example for DS1820, but I skip reading & check CRC. You could add CRC table if needed.
Hope this can helpfull. Suhandry Salim RDTEMP: ACALL INIT1W ;Init 1Wire JB OWERROR,ERROR ;Check if Error MOV A,#0CCH ACALL WRBYTE1W ;Skip ROM MOV A,#44H ACALL WRBYTE1W ;Do Temp Measure LCALL PAUSE500MS ;Give a Time ACALL INIT1W ;Init 1Wire JB OWERROR,ERROR MOV A,#0CCH ACALL WRBYTE1W ;Skip ROM MOV A,#0BEH ACALL WRBYTE1W ;BEH = Read DATA ACALL RDBYTE1W ;Get LSB "save LSB in RAM" ACALL RDBYTE1W ;Get MSB "save MSB in RAM" RET ERROR: "do something" ; need do something if error RET ;------------------------------------------------- ;------------------------------------------------- ;Initialize 1-Wire Device ;Input : None ;Output: 1WERROR Flag -> 1 If No Device / Error ;------------------------------------------------- INIT1W: CLR OWERROR CLR DQ LCALL PAUSE500US SETB DQ LCALL PAUSE65US JNB DQ,OWVALID SETB OWERROR OWVALID: LCALL PAUSE500US RET ;-------------------------------------------------- ;Write 1 Byte to 1-Wire Device ;Input : A = Data / Command ;Output: None ;-------------------------------------------------- WRBYTE1W: PUSH 07H MOV R7,#8 OWWRNxtBit: CLR DQ RRC A MOV DQ,C JNC OWLBit SETB DQ OWLbit: LCALL PAUSE65US SETB DQ DJNZ R7,OWWRNxtBit POP 07H RET ;-------------------------------------------------- ;Read 1 Byte From 1-Wire Device's Register ;Input : None ;Output: A = Data / Status ;-------------------------------------------------- RDByte1W: PUSH 07H MOV R7,#8 OWRDNxtBit: CLR DQ NOP NOP NOP SETB DQ LCALL PAUSE10US MOV C,DQ RRC A LCALL PAUSE65US DJNZ R7,OWRDNxtBit SETB DQ POP 07H RET |
Topic | Author | Date |
DS18B20 help needed | 01/01/70 00:00 | |
Where have you looked ? | 01/01/70 00:00 | |
A DS18B20 is ???? | 01/01/70 00:00 | |
Start here | 01/01/70 00:00 | |
Re | 01/01/70 00:00 | |
Whilst we are on the topic | 01/01/70 00:00 | |
No, but | 01/01/70 00:00 | |
maxim usually | 01/01/70 00:00 | |
previous discussion | 01/01/70 00:00 | |
Re DS28EA00 | 01/01/70 00:00 | |
The problem | 01/01/70 00:00 | |
1 wire routines example | 01/01/70 00:00 | |
Not a good idea![]() | 01/01/70 00:00 | |
assembler source code | 01/01/70 00:00 | |
1wire.lst | 01/01/70 00:00 | |
Start from square 1 | 01/01/70 00:00 |