Debian Codegraph @

examples/ASM/sine-wave.S

raw
1 ; generates sine wave on the R-2R DAC connected on port C
2
3 #include <avr/io.h>
4
5 .section .data
6 .global stab
7 stab: ; sine table
8 .byte 128 , 150 , 171 , 191 , 209 , 223 , 234 , 240 , 242 , 240 , 234 , \
9 223 , 209 , 191 , 171 , 150 , 128 , 105 , 84 , 64 , 46 , 32 , 21 ,\
10 15 , 13 , 15 , 21 , 32 , 46 , 64 , 84 , 105 , 127
11
12 .section .text ; code section
13 .global __do_copy_data
14 .global __do_clear_bss
15
16 .global TIMER0_COMP_vect
17 TIMER0_COMP_vect: ; ISR
18 ld r24, X+ ; value from the sine table, increment pointer
19 sts PORTC, r24 ; write it to PORTC
20 inc r22 ; increment r22
21 CPSE r20,r22 ; is it 32 ?
22 reti ; if not equal return, else skip reti
23 clr r22 ; set it back to 0
24 subi r26,32 ; subtract 32 from XL, set X to beginning of the table
25 reti
26
27 .global main
28 main:
29 ldi r16, 255
30 sts DDRC, r16
31
32 ldi r16, (1 << WGM01) | 1 ; Set TCCR0 in the CTC mode
33 sts TCCR0 , r16
34 ldi r16, 50
35 sts OCR0, r16
36
37 ldi r16, (1 << OCIE0) ; set TC0 compare interrupt enable bit
38 sts TIMSK, r16
39 ldi r16, (1 << OCF0) ; interrupt enable bit
40 sts TIFR, r16
41
42 ldi XL, lo8(stab) ; point X to the sine table
43 ldi XH, hi8(stab)
44 clr r22 ; R22 will keep track of the location in table
45 ldi r20,32 ; Store size of the table in R20
46
47 sei
48 loop:
49 rjmp loop
50 .end
51