Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;.device ATTINY13
- .include "tn13def.inc"
- .def cnd = r16
- .def temp = r17
- .def temp1 = r20
- .def temp2 = r21
- .def temp3 = r26
- .def temp4 = r27
- .def cnt1 = r18
- .def cnt2 = r19
- .def t1 = r22
- .def t2 = r23
- .def t3 = r24
- .def mul1 = r5
- .def mul2 = r6
- .def mul3 = r7
- .def mul4 = r8
- .def mulv = r9
- .def per1 = r2
- .def per2 = r3
- .def per3 = r4
- .def PB = r25
- .def oldin = r0
- .def newin = r1
- rjmp RESET
- reti
- rjmp PCH
- rjmp TIMER
- reti
- reti
- reti
- reti
- reti
- reti
- usleep:
- swait:
- subi cnt1, 1
- sbci cnt2, 0
- brcc swait
- ret
- RESET:
- cli
- ldi temp, 0b00010111
- out DDRB, temp
- ldi PB, 0b00010111
- out PORTB, PB
- ldi cnt1, 0xFF
- ldi cnt2, 0x08
- rcall usleep
- ldi PB, 0b00010000
- out PORTB, PB
- ldi temp, 0b00100000
- out GIMSK, temp
- ldi temp, 0b00001000
- out PCMSK, temp
- ldi cnd, 0
- ; время протекания тока через катушку
- ldi t1, 0x04
- ldi t2, 0x00
- ldi t3, 0x00
- sts 0x60, t1
- sts 0x61, t2
- sts 0x62, t3
- ; время, пока уйдут помехи от искры.
- ; как и предыдущее, пока взято от балды
- ldi t1, 0x03
- ldi t2, 0x00
- ldi t3, 0x00
- sts 0x67, t1
- sts 0x68, t2
- sts 0x69, t3
- ldi temp, 255
- sts 0x63, temp
- ldi temp, 0b00000000
- out TCCR0A, temp
- ldi temp, 0b00000010
- out TCCR0B, temp
- ldi temp, 0b00000010
- out TIMSK0, temp
- clr per1
- clr per2
- clr per3
- sei
- STOP:
- rjmp STOP
- TIMER:
- ; считаем период
- ldi temp, 1
- add per1, temp
- ldi temp, 0
- adc per2, temp
- adc per3, temp
- ; отсчет таймера
- subi t1, 1
- sbci t2, 0
- sbci t3, 0
- brcc NOT_NOW
- bst cnd, 2
- brts _1xx
- _0xx:
- bst cnd, 1
- brts _01x
- _00x:
- bst cnd, 0
- brtc c0
- rjmp c1
- _01x:
- bst cnd, 0
- brtc c2
- rjmp c3
- _1xx:
- rjmp c4
- c0:
- ori cnd, 0b10000000 ;init
- rjmp C_END
- c1: ;подавляем дребезг
- lds t1, 0x6A
- lds t2, 0x6B
- lds t3, 0x6C
- andi cnd, 0b11111000
- ori cnd, 0b00000010
- rjmp C_END
- c2: ; включаем катушку
- lds t1, 0x60
- lds t2, 0x61
- lds t3, 0x62
- andi PB, 0b11101111
- ldi temp, 0x00
- out TCNT0, temp
- andi cnd, 0b11111000
- ori cnd, 0b00000011
- rjmp C_END
- c3: ; выключаем катушку - возникает искра
- ori PB, 0b00010000
- ldi temp, 0x00
- out TCNT0, temp
- andi cnd, 0b11111000
- ori cnd, 0b00000100
- lds t1, 0x67
- lds t2, 0x68
- lds t3, 0x69
- rjmp C_END
- c4: ; ждем, пока уйдут помехи от искры
- andi cnd, 0b11111000
- ldi t1, 0xFF
- ldi t2, 0xFF
- ldi t3, 0xFF
- rjmp C_END
- C_END:
- out PORTB, PB
- NOT_NOW:
- reti
- ; temp3:temp2:temp1
- ; mulv
- ; mul4:mul3:mul2:mul1
- mult3:
- clr mul1
- clr mul2
- clr mul3
- clr mul4
- clr temp4
- ldi cnt1, 8
- mult:
- bst mulv, 0
- brtc NO_ADD
- add mul1, temp1
- adc mul2, temp2
- adc mul3, temp3
- adc mul4, temp4
- NO_ADD:
- lsl temp1
- rol temp2
- rol temp3
- rol temp4
- lsr mulv
- subi cnt1, 1
- brne mult
- ret
- PCH:
- cli
- ;bst cnd, 7
- ;brtc NO
- mov oldin, newin
- in newin, PINB
- bst newin, 3
- brtc NO
- bst oldin, 3
- brts NO
- ;----------------------
- bst cnd, 2
- brts __1xx
- __0xx:
- bst cnd, 1
- brts __01x
- __00x:
- bst cnd, 0
- brtc GO
- rjmp NO
- __01x:
- bst cnd, 0
- brtc GO
- rjmp NO
- __1xx:
- rjmp NO
- GO:
- ; разомкнулся ФД - НМТ
- ldi temp, 0x00
- out TCNT0, temp
- mov t1, per1
- mov t2, per2
- mov t3, per3
- ; полпериода до ВМТ
- lsr t3
- ror t2
- ror t1
- ; вычтем время работы катушки
- lds temp1, 0x60
- lds temp2, 0x61
- lds temp3, 0x62
- sub t1, temp1
- sbc t2, temp2
- sbc t3, temp3
- ; и время подавления дребезга
- lds temp1, 0x67
- lds temp2, 0x68
- lds temp3, 0x69
- sub t1, temp1
- sbc t2, temp2
- sbc t3, temp3
- ; запишем время в память
- ;ldi t1, 0x00
- ;ldi t2, 0x02
- ;ldi t3, 0x00
- sts 0x6A, t1
- sts 0x6B, t2
- sts 0x6C, t3
- ; гасим дерезг
- mov t1, temp1
- mov t2, temp2
- mov t3, temp3
- andi cnd, 0b11111000
- ori cnd, 0b00000001 ;переходим в состояние 1
- P_END:
- clr per1 ; сбрасываем счетчик периода обращения
- clr per2
- clr per3
- ;----------------------
- NO:
- sei
- reti
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement