;------------------------------------------------------------------------------ ;One Wire SS Prog ;------------------------------------------------------------------------------ .equ OW_PORT = PORTB .equ OW_PIN = PINB .equ OW_DDR = DDRB .equ OW_DQ = PB3 .def OWCount = r17 ;.def A = r16 ; GENERAL PURPOSE ACCUMULATOR ;------------------------------------------------------------------------------ ; ;------------------------------------------------------------------------------ .cseg ;------------------------------------------------------------------------------ ; Output : T - presence bit ;------------------------------------------------------------------------------ OWReset: cbi OW_PORT,OW_DQ sbi OW_DDR,OW_DQ ldi XH, HIGH(C4PUS*470) ;470us ldi XL, LOW(C4PUS*470) rcall Wait4xCycles cbi OW_DDR,OW_DQ ldi XH, HIGH(C4PUS*70) ;70us ldi XL, LOW(C4PUS*70) rcall Wait4xCycles set sbis OW_PIN,OW_DQ clt ldi XH, HIGH(C4PUS*240) ;240us ldi XL, LOW(C4PUS*240) rcall Wait4xCycles ret ;------------------------------------------------------------------------------ ; Input : C - bit to write ;------------------------------------------------------------------------------ OWWriteBit: brcc OWWriteZero ldi XH, HIGH(C4PUS*1) ;1us ldi XL, LOW(C4PUS*1) rjmp OWWriteOne OWWriteZero: ldi XH, HIGH(C4PUS*120) ;120us ldi XL, LOW(C4PUS*120) OWWriteOne: sbi OW_DDR, OW_DQ rcall Wait4xCycles cbi OW_DDR, OW_DQ ldi XH, HIGH(C4PUS*60) ;60us ldi XL, LOW(C4PUS*60) rcall Wait4xCycles ret ;------------------------------------------------------------------------------ ; Input : R18 -DATA - byte to write ;------------------------------------------------------------------------------ OWWriteByte: push OWCount ldi OWCount,8 OWWriteLoop: ror DATA rcall OWWriteBit dec OWCount brne OWWriteLoop pop OWCount ret ;------------------------------------------------------------------------------ ; Output : C - bit from slave ;------------------------------------------------------------------------------ OWReadBit: ldi XH, HIGH(C4PUS*1) ldi XL, LOW(C4PUS*1) sbi OW_DDR, OW_DQ rcall Wait4xCycles cbi OW_DDR, OW_DQ ldi XH, HIGH(C4PUS*5) ldi XL, LOW(C4PUS*5) rcall Wait4xCycles clt sbic OW_PIN,OW_DQ set ldi XH, HIGH(C4PUS*50) ldi XL, LOW(C4PUS*50) rcall Wait4xCycles sec brts OWReadBitEnd clc OWReadBitEnd: ret ;------------------------------------------------------------------------------ ; Output : r18 - DATA - byte from slave ;------------------------------------------------------------------------------ OWReadByte: push OWCount ldi OWCount,8 OWReadLoop: rcall OWReadBit ror DATA dec OWCount brne OWReadLoop pop OWCount ret ;------------------------------------------------------------------------------ ; ;------------------------------------------------------------------------------