Atmel AVR ATtiny13a as TV remote control IR receiver (assembly code)
Автор: Branislav Stanojkovic
Загружено: 2019-01-24
Просмотров: 11906
Описание:
In this video I go over the assembly code for Atmel ATtiny13a that interprets IR signals received from a TV remote control.
I also demonstrate how to program the ATtiny13a chip with an Arduino Uno as the programmer.
Assembly code for ATtiny 13a:
clr r1
// setupPort:
ldi r16, 0b11110000 // PB0-input, PB4-output
out DDRB, r16
// setupTimer:
ldi r16, 0b00000000
out TCCR0A,r16
ldi r16, 0b00000101 // prescaler 9.6MHz/1024
out TCCR0B,r16
// start:
in r17, PINB
andi r17, 0b00000001
out TCNT0, r1
poll:
mov r16, r17
in r17, PINB // two consecutive sample readings
andi r17, 0b00000001
cp r16, r17
brne toggle
rjmp poll
toggle:
cpi r17, 0x00 // evaluate only high-voltage pulses
breq poll
in r18, TCNT0
cpi r18, 9 // 0-8 cycles - skip
brlo poll
cpi r18, 12 // 9-11 cycles - binary zero
brlo binaryZero
cpi r18, 19 // 12-18 cycles - skip
brlo poll
cpi r18, 23 // 19-23 cycles - binary one
brlo binaryOne
rjmp reset // 23+ cycles - reset
binaryZero:
ldi r19, 0b00000000
rjmp updateResult
binaryOne:
ldi r19, 0b00000001
rjmp updateResult
updateResult:
lsl r21 // shift bits left
or r21, r19 // put new value in bit 0
out TCNT0, r1
rjmp poll
reset:
cpi r21, 0x79 // was it the blue button that was pushed? 0x61 inverse is 0x79 (ASCII 'y')
brne finish
ldi r21, 0b00010000
out PINB, r21 // blue button was pushed, toggle PB4
finish:
clr r21
out TCNT0, r1
rjmp poll
Assembly code for Arduino Uno:
clr r1
// setupPort:
ldi r16, 0b11110000 // PB0-input, PB5-output
out DDRB, r16
// setupUART:
sts UBRR0H, r1
ldi r16, 0x67
sts UBRR0L, r16
ldi r16, 0x48
sts UCSR0B, r16
ldi r16, 0x06
sts UCSR0C, r16
// setupTimer:
ldi r16, 0b00000000
out TCCR0A,r16
ldi r16, 0b00000101 // prescaler 16MHz/1024
out TCCR0B,r16
// start:
in r17, PINB
andi r17, 0b00000001
out TCNT0, r1
poll:
mov r16, r17
in r17, PINB // two consecutive sample readings
andi r17, 0b00000001
cp r16, r17
brne toggle
rjmp poll
toggle:
cpi r17, 0x00 // evaluate only high-voltage pulses
breq poll
in r18, TCNT0
cpi r18, 15 // 0-14 cycles - skip
brlo poll
cpi r18, 20 // 15-19 cycles - binary zero
brlo binaryZero
cpi r18, 32 // 20-31 cycles - skip
brlo poll
cpi r18, 38 // 32-37 cycles - binary one
brlo binaryOne
rjmp reset // 38+ cycles - reset
binaryZero:
ldi r19, 0b00000000
ldi r20, 0x30 // ASCII '0'
rjmp updateResult
binaryOne:
ldi r19, 0b00000001
ldi r20, 0x31 // ASCII '1'
rjmp updateResult
updateResult:
sts UDR0, r20 // display ASCII
lsl r21 // shift bits left
or r21, r19 // put new value in bit 0
out TCNT0, r1
rjmp poll
reset:
ldi r20, 0x0D // carriage return
sts UDR0, r20
sts UDR0, r21 // display result, ASCII of inverse binary value
cpi r21, 0x79 // was it the blue button that was pushed? 0x61 inverse is 0x79 (ASCII 'y')
brne finish
ldi r21, 0b00100000
out PINB, r21 // blue button was pushed, toggle PB5 (built-in LED)
finish:
clr r21
out TCNT0, r1
rjmp poll
-----------------------------------
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: