I would put very short update, regarding my PWM trial
Corresponding ASM code is as follows. Indeed I greatly refer the C code at avrfreak and tried to convert to assembler by myself (so such a redundant code, ;-)
.def temp1 = R16
.def temp2 = R17
.def count_L = R18
.def count_H = R19
.def final_L = R20
.def final_H = R21
.def temp3 = R22
.def temp4 = R23
.def temp5 = R24
.def temp6 = R25
.equ topnum = 1000
.equ count_start = 0xff
.equ count_end = 0x01
.equ subnum = 0x01
; Replace with your application code
setup:
ldi temp1, (1<<PB0)+(1<<PB1);
out DDRB, temp1
ldi temp1, (1<<COM0A1)+(1<<COM0B1)+(1<<WGM01);
out TCCR0A, temp1
ldi temp1, low(topnum);1111101000
out ICR0L, temp1
ldi temp1, byte2(topnum)
out ICR0H, temp1
ldi temp1,(1<<CS01)+(1<<WGM03)+(1<<WGM02)
out TCCR0B, temp1
start:
;inc r16
ldi count_L, 0
ldi count_H, 0
ldi final_L, low(topnum)
ldi final_H, byte2(topnum)
ldi temp1, 0x01
ldi temp2, 0x00
loop1:
add count_L, temp1
adc count_H, temp2
out OCR0AL, count_L
out OCR0AH, count_H
mov temp3, count_L
mov temp4, count_H
ldi temp5, low(topnum)
ldi temp6, byte2(topnum)
sub temp5,temp3
sbc temp6,temp4
out OCR0BL, temp5
out OCR0BH, temp6
rcall delay
cp final_H, count_H
cpc final_L, count_L
brne loop1
rjmp start
delay: ; subroutine DELAY
ldi temp3, count_end
ldi temp4, count_start
ldi temp5, subnum
counter:
sub temp4, temp5
cpse temp4, temp3
rjmp counter
ret
Somehow this code realise "soft LED blinking" as shown on the top...
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.