Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- ; fastPWM.asm
- ;
- ; Created: 03/05/2023 16:37:42
- ; Author : bemposta
- ;
- .ORG 0x0000
- sbi DDRB, PINB5
- rcall initFastPWMTmr0
- clr r17
- ser r18
- mainLoop:
- sbi PORTB, PINB5
- rcall delay100ms
- inc r17
- dec r18
- out OCR0A, r17
- out OCR0B, r18
- cbi PORTB, PINB5
- rcall delay100ms
- inc r17
- dec r18
- out OCR0A, r17
- out OCR0B, r18
- rjmp mainLoop
- /***************************************************************************************
- Funciones
- ***************************************************************************************/
- initFastPWMTmr0:
- push r16
- sbi DDRD, PIND6 ; Out 0A (pin D6)
- sbi DDRD, PIND5 ; Out 0B (pin D5)
- clr r16
- ori r16, (3 << WGM00) ; Modo 3 -> FastPWM [falta:(0 << WGM02) en TCCR0B]
- ori r16, (2 << COM0A0) ; Out 0A (pin D6), non inverting Compare Output = Clear OC0A on Compare Match.
- ori r16, (2 << COM0B0) ; Out 0B (pin D5), non inverting Compare Output = Clear OC0B on Compare Match.
- out TCCR0A, r16
- clr r16
- ori r16, (0 << WGM02) ; completar Modo 3 -> FastPWM y Modo 7.
- ori r16, (5 << CS00) ; Preescaler 1024. 0=No Clk, 1=No prescaling, 2=clk/8, 3=clk/64, 4=clk/256, 5=clk/1024
- out TCCR0B, r16
- ldi r16, 0
- out OCR0A, r16 ; Init PWM 0%
- out OCR0B, r16 ; Init PWM 0%
- pop r16
- ret
- /***************************************************************************************/
- delay100ms:
- ; 100ms at 16 MHz
- push r18
- push r19
- push r20
- ldi r18, 2
- ldi r19, 30
- ldi r20, 229
- delay100msL1:
- dec r20
- brne delay100msL1
- dec r19
- brne delay100msL1
- dec r18
- brne delay100msL1
- pop r20
- pop r19
- pop r18
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement