Вот пример кода, который глючит при непрерывном потоке байт на входе:
Код: Выделить всё
#include <avr/io.h>
#include <avr/interrupt.h>
uint8_t tmpvar;
ISR(USART_RXC_vect)
{
}
ISR(TIMER1_OVF_vect)
{
uint8_t tmp_l = tmpvar % 4;
switch(tmp_l)
{
case 0:
PORTD &= ~((1 << PD4) | (1 << PD5));
break;
case 1:
PORTD ^= (1 << PD4);
break;
case 2:
PORTD &= ~(1 << PD4);
PORTD ^= (1 << PD5);
break;
case 3:
PORTD ^= (1 << PD4);
break;
}
tmpvar++;
}
int main()
{
TCCR1B |= (1 << CS10) | (1 <<CS11);
TIMSK |= (1 << TOIE1);
DDRD |= (1 << PD4) | (1 << PD5);
sei();
while(1);
}А вот дезасемблированный hex, выше приведенного кода.
Код: Выделить всё
Disassembly of section .sec1:
00000000 <.sec1>:
0: 0c 94 2a 00 jmp 0x54 ; 0x54
4: 0c 94 47 00 jmp 0x8e ; 0x8e
8: 0c 94 47 00 jmp 0x8e ; 0x8e
c: 0c 94 47 00 jmp 0x8e ; 0x8e
10: 0c 94 47 00 jmp 0x8e ; 0x8e
14: 0c 94 47 00 jmp 0x8e ; 0x8e
18: 0c 94 47 00 jmp 0x8e ; 0x8e
1c: 0c 94 47 00 jmp 0x8e ; 0x8e
20: 0c 94 47 00 jmp 0x8e ; 0x8e
24: 0c 94 59 00 jmp 0xb2 ; 0xb2
28: 0c 94 47 00 jmp 0x8e ; 0x8e
2c: 0c 94 47 00 jmp 0x8e ; 0x8e
30: 0c 94 47 00 jmp 0x8e ; 0x8e
34: 0c 94 49 00 jmp 0x92 ; 0x92
38: 0c 94 47 00 jmp 0x8e ; 0x8e
3c: 0c 94 47 00 jmp 0x8e ; 0x8e
40: 0c 94 47 00 jmp 0x8e ; 0x8e
44: 0c 94 47 00 jmp 0x8e ; 0x8e
48: 0c 94 47 00 jmp 0x8e ; 0x8e
4c: 0c 94 47 00 jmp 0x8e ; 0x8e
50: 0c 94 47 00 jmp 0x8e ; 0x8e
54: 11 24 eor r1, r1
56: 1f be out 0x3f, r1 ; 63
58: cf e5 ldi r28, 0x5F ; 95
5a: d8 e0 ldi r29, 0x08 ; 8
5c: de bf out 0x3e, r29 ; 62
5e: cd bf out 0x3d, r28 ; 61
60: 10 e0 ldi r17, 0x00 ; 0
62: a0 e6 ldi r26, 0x60 ; 96
64: b0 e0 ldi r27, 0x00 ; 0
66: e0 ee ldi r30, 0xE0 ; 224
68: f0 e0 ldi r31, 0x00 ; 0
6a: 02 c0 rjmp .+4 ; 0x70
6c: 05 90 lpm r0, Z+
6e: 0d 92 st X+, r0
70: a0 36 cpi r26, 0x60 ; 96
72: b1 07 cpc r27, r17
74: d9 f7 brne .-10 ; 0x6c
76: 10 e0 ldi r17, 0x00 ; 0
78: a0 e6 ldi r26, 0x60 ; 96
7a: b0 e0 ldi r27, 0x00 ; 0
7c: 01 c0 rjmp .+2 ; 0x80
7e: 1d 92 st X+, r1
80: a0 36 cpi r26, 0x60 ; 96
82: b1 07 cpc r27, r17
84: e1 f7 brne .-8 ; 0x7e
86: 0e 94 69 00 call 0xd2 ; 0xd2
8a: 0c 94 6e 00 jmp 0xdc ; 0xdc
8e: 0c 94 00 00 jmp 0 ; 0x0
92: 1f 92 push r1
94: 0f 92 push r0
96: 0f b6 in r0, 0x3f ; 63
98: 0f 92 push r0
9a: 11 24 eor r1, r1
9c: df 93 push r29
9e: cf 93 push r28
a0: cd b7 in r28, 0x3d ; 61
a2: de b7 in r29, 0x3e ; 62
a4: cf 91 pop r28
a6: df 91 pop r29
a8: 0f 90 pop r0
aa: 0f be out 0x3f, r0 ; 63
ac: 0f 90 pop r0
ae: 1f 90 pop r1
b0: 18 95 reti
b2: 1f 92 push r1
b4: 0f 92 push r0
b6: 0f b6 in r0, 0x3f ; 63
b8: 0f 92 push r0
ba: 11 24 eor r1, r1
bc: df 93 push r29
be: cf 93 push r28
c0: cd b7 in r28, 0x3d ; 61
c2: de b7 in r29, 0x3e ; 62
c4: cf 91 pop r28
c6: df 91 pop r29
c8: 0f 90 pop r0
ca: 0f be out 0x3f, r0 ; 63
cc: 0f 90 pop r0
ce: 1f 90 pop r1
d0: 18 95 reti
d2: df 93 push r29
d4: cf 93 push r28
d6: cd b7 in r28, 0x3d ; 61
d8: de b7 in r29, 0x3e ; 62
da: ff cf rjmp .-2 ; 0xda
dc: f8 94 cli
de: ff cf rjmp .-2 ; 0xde
Может кто видел такие чудеса и знает как с ниби бороться? У меня идеи уже закончились....
ps: mega16 на ее месте себя ведет аналогично...