Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; FLIP-FLOP de LEDs a várias frequências dependendo do switch premido
- .include <m128def.inc>
- .cseg
- .org 0x00 ; vector: reset
- jmp main
- .org 0x1E ; vector: interrupcao timer/counter
- jmp subrotina
- .org 0x46
- init:
- ldi r16, 77 ; carrega 77 em r16
- out OCR0, r16 ; passa 77 para OCR0
- in r16, TIMSK ; TC0, OCIE0 compara OCR0 e valor contador
- ori r16, 2 ; "ou"
- out TIMSK, r16 ; enable timer output compare interrupt
- ldi r16, 0x08 ; 0b00001000, TC0: modo 2CTC, timer off
- out TCCR0, r16 ; enable timer output compare interrupt
- ldi r17, 0x01 ; 0b00000001
- out DDRC, r17 ; PORTC como saida dados (LED)
- ser r17 ; = ldi r17, 0b11111111, 0xFF
- out PORTC, r17 ; leds apagados
- clr r16 ; = ldi r16,0b00000000, 0x00
- out DDRA, r16 ; PORTA como entrada
- sei ; activa interrupcoes globais
- ret ; return
- subrotina:
- push r17
- in r20, SREG
- dec r18
- brne end_
- in r17, PORTC
- com r17 ; complementa r17 0PINA 0 25-1-0-1
- out PORTC, r17
- mov r18, r19
- end_:
- out SREG,r20
- pop r17
- reti ; return
- main:
- ldi r16,0xff ; stack pointer
- out SPL,r16
- ldi r16,0x10
- out SPH,r16
- call init
- ; f1 = 100
- sw1:
- in r16, PINA
- andi r16, 0x01 ; 0b00000001, verifica SW1
- brne sw2 ; se sw1 nao activo verifica sw2
- ldi r18, 100
- mov r19, r18
- ldi r16, 0x0F ; 0b00001111, TC0: modo 2CTC, prescaler 1024
- out TCCR0, r16
- jmp sw1 ; volta a ler sw1
- ; f2 = 50
- sw2:
- in r16, PINA
- andi r16, 0x02 ; 0b00000010, verifica SW2
- brne sw3 ; se sw2 nao activo verifica sw3
- ldi r18, 50
- mov r19, r18
- ldi r16, 0x0F ; 0b00001111, TCO: modo 2CTC,, prescaler 1024
- out TCCR0, r16
- jmp sw1
- ; f3 = 25
- sw3:
- in r16, PINA
- andi r16, 0x04 ; 0b00000100, verifica SW3
- brne sw6 ; se sw2 nao activo verifica sw3
- ldi r18, 25
- mov r19, r18
- ldi r16, 0x0F ; 0b00001111, TCO: modo 2CTC,, prescaler 1024
- out TCCR0, r16
- jmp sw1
- ; off
- sw6:
- in r16, PINA ; verifica sw6
- andi r16, 0x20 ; 0b00100000, se sw6 nao activo verifica sw1
- brne sw1
- ldi r16, 0x08 ; 0b00001000, TCO: modo 2CTC,, prescaler 1024
- out TCCR0, r16
- ser r17 ; apagar Led's
- out PORTC, r17
- jmp sw1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement