Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Тактовая частота 1200 kHz
- .include "tn12def.inc"
- .def Temp=R16
- .def Temp1=R17
- .def Data=R18
- .def Duration=R19
- .def Count=R20
- .def Count1=R21
- .def EEAdr=R22
- .equ DATAPIN=2
- .equ PULLUPPIN=1
- .equ POWERPIN=0
- .equ RANDPIN=4
- .equ LED_B=3
- .cseg
- .org $000 ; вектора прерываний
- rjmp RESET
- reti ; int0
- reti ; pins
- rjmp TIMER ; timer0 ovfl
- reti ; eeprom
- reti ; anacomp
- RESET:
- ldi Temp, (1<<ACD)
- out AINBG, Temp ; отключить аналоговый компаратор
- ldi Temp, (1<<SE)
- out MCUCR, Temp
- ldi Temp, 0b00000010
- out TIMSK, Temp ; включить прерывание по таймеру T0
- ldi Temp, (1<<PULLUPPIN)
- out DDRB, Temp ;
- out PORTB, Temp
- START:
- sei
- rcall ONEWIRE_RESET
- ldi Data, 0x33 ; read Rom
- rcall ONEWIRE_SEND
- ldi Count1, 8
- ldi EEAdr, 0x00
- RD_LOOP:
- rcall ONEWIRE_RECEIVE
- cpi EEAdr, 0x00
- brne NoCompare
- cpi Data, 0x00
- breq STOP
- cpi Data, 0xFF
- breq STOP
- NoCompare:
- rcall EEWR
- inc EEAdr
- dec Count1
- brne RD_LOOP
- STOP:
- ldi Duration, 0xFF
- rcall DELAY_MS
- rcall DELAY_MS
- rcall DELAY_MS
- rcall DELAY_MS
- rjmp START
- ONEWIRE_RESET:
- sbi DDRB, DATAPIN
- ldi Duration, 184 ; x3 600clk, 500uS
- rcall DELAY_US
- rcall DELAY_US
- rcall DELAY_US
- cbi DDRB, DATAPIN ; release dataline
- sbi PORTB, DATAPIN ; pullup on
- ldi Duration, 50 ; 66clk, 55uS
- rcall DELAY_US
- sbic PINB, DATAPIN
- ldi Duration, 239 ; x2 510clk, 425uS
- rcall DELAY_US
- rcall DELAY_US
- sbi PORTB, DATAPIN ; pullup off
- ret
- ONEWIRE_SEND:
- ldi Count, 8
- TX_LOOP:
- lsr Data
- brcs TX_ONE
- TX_ZERO:
- sbi DDRB, DATAPIN ; pull down
- ldi Duration, 56 ; 72clk, 60uS
- rcall DELAY_US
- cbi DDRB, DATAPIN ; release
- ldi Duration, 1 ; 16clk, 10uS
- rcall DELAY_US
- rjmp TX_ENDBIT
- TX_ONE:
- sbi DDRB, DATAPIN ; pull down
- nop ; 7clk, 6uS
- nop
- nop
- nop
- nop
- nop
- nop
- cbi DDRB, DATAPIN ; release
- ldi Duration, 60 ; 76clk, 64uS
- rcall DELAY_US
- TX_ENDBIT:
- dec Count
- brne TX_LOOP
- ret
- ONEWIRE_RECEIVE:
- ldi Data, 0
- ldi Count, 8
- RX_LOOP:
- lsr Data
- sbi DDRB, DATAPIN ; pull down
- nop ; 7clk, 6uS
- nop
- nop
- nop
- nop
- nop
- nop
- cbi DDRB, DATAPIN ; release
- nop ; 10clk, 9uS
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- sbic PINB, DATAPIN ; 0 - skip
- ori Data, 0b10000000
- ldi Duration, 50 ; 66 clk, 55uS
- rcall DELAY_US
- dec Count
- brne RX_LOOP
- ret
- EEWR: ; запись в EEPROM
- sbic EECR, 1
- rjmp EEWR
- cli
- out EEAR, EEAdr
- out EEDR, Data
- sbi EECR, 2
- sbi EECR, 1
- sei
- ret
- EEREAD: ; чтение из EEPROM
- sbic EECR, 1
- rjmp EEREAD
- out EEAR, EEAdr
- sbi EECR, 0
- in Data, EEDR
- ret
- ; функции задержек
- DELAY_US: ; %Duration%+16 clk
- ldi Temp, 0xFF
- sub Temp, Duration
- out TCNT0, Temp
- ldi Temp, 0b00000001; CK/1
- out TCCR0, Temp ; Start TIMER0
- sleep
- ret
- DELAY_MS: ; %Duration%*1024+16 clk
- ldi Temp, 0xFF
- sub Temp, Duration
- out TCNT0, Temp
- ldi Temp, 0b00000101; CK/1024
- out TCCR0, Temp ; Start TIMER0
- sleep
- ret
- ; обработчик прерывания таймера T0
- TIMER:
- ldi Temp, 0b00000000
- out TCCR0, Temp ; Stop TIMER0
- reti
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement