ATMega16 + код (без таблицы прерываний). Кварц 10Мгц
По идее (что и показывает студия) портС должен моргать в режиме SOS с периодом точки - 1 сек,
тире - 2 сек, пауза между ними - 2 сек что задается в массиве и умножением значения задержки на 98. В реале же порт моргает гораздо чаще. Переключения порта еле заметны глазом. Подскажите пожалуйста в чем я ошибся.
Код: Выделить всё
.include "m16def.inc"
.def temp=R16
.def time=R20
.def stage=R21
.def sign=R17
.DSEG
.CSEG
.ORG $000 ; (RESET)
RJMP Reset
Reset:
;èíèöèàëèçèðóåì ñòåê
LDI R16, low(RAMEND)
out SPL, R16
LDI R16, high(RAMEND)
out SPH, R16
;nastroyka portov
ldi R16, 0b11111111
out DDRC, R16
;out DDRA, R16
;out DDRB, R16
;ïåðâè÷íûé íàñòðîéêà è çàïóñê òàéìåðà
ldi ZH, high(array*2)
ldi ZL, low(array*2)
lpm
out OCR1AL, R0
ldi temp, 0
out TCNT1H, temp
out TCNT1L, temp
ldi temp, 1<<2|1<<0
;ldi temp, 1<<0
out TCCR1B, temp
ldi temp, 1<<4
out TIMSK, temp
sei
ldi temp, 1
add ZL, temp
ldi temp, 0
adc ZH, temp
lpm
mov sign, R0
;îáíóëÿåì âðåìÿ ÷òîáû ïðîãðàììà çàãðóçèëà ñëåäóþùåå çíà÷åíèå âðåìåíè
ldi time, 0
ldi stage, 2
ldi R16, 0b11111111
out PORTA, R16
ldi R16, 0b00000000
out PORTB, R16
Main:
rcall tststage
cpi sign, 1
brne offsignal
ldi R16, 0b11111111
out PORTC, R16
rjmp oute
offsignal:
ldi R16, 0b00000000
out PORTC, R16
oute:
rjmp Main
array:
.db 100, 1, 200, 0
.db 100, 1, 200, 0
.db 100, 1, 200, 0
.db 200, 1, 200, 0
.db 200, 1, 200, 0
.db 200, 1, 200, 0
.db 100, 1, 200, 0
.db 100, 1, 200, 0
.db 100, 1, 200, 0
;*********************************************************************
;ïîäïðîãðàììû
tststage:
push temp
cpi time, 0
brne out1
cpi stage, 36
brne okstage
ldi stage, 0
okstage:
ldi ZH, high(array*2)
ldi ZL, low(array*2)
mov temp, stage
add ZL, temp
ldi temp, 0
adc ZH, temp
lpm
mov time, R0
ldi temp, 1
add ZL, temp
ldi temp, 0
adc ZH, temp
lpm
mov sign, R0
ldi temp, 2
add stage, temp
out1:
pop temp
ret
;********************************************************************
;ïðåðûâàíèÿ
tim1a:
push temp
push R1
push R0
ldi temp, 0
out TCNT1H, temp
out TCNT1L, temp
ldi temp, 98
mul time, temp
out OCR1AL, R0
out OCR1AH, R1
ldi time, 0
pop R0
pop R1
pop temp
reti