Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ******************************************************
- ; BASIC .ASM template file for AVR
- ; ******************************************************
- .include "E:\EEET22~1\TEACHI~1\Tools\VMLab\include\m32def.inc"
- .DEF TEMP = R16 ;GENERAL PURPOSE ACCUMULATOR
- .def TEMP1 = R17
- .ORG $0000 ;STARTUP VECTOR
- .ORG $0006 ;COMPARE MATCH VECTOR
- .CSEG
- ;------ Reset and interrupt vectors ------------------------------
- ;
- .ORG 0x00
- START:
- rjmp ON_RESET
- reti
- reti
- reti
- reti
- reti
- reti
- reti
- reti
- reti
- reti
- reti
- reti
- reti
- reti
- ON_RESET:
- ; SBI DDRB,0 ;SET PORTB0 FOR OUTPUT
- ; LDI TEMP,0b11001101 ;SET TO FAST PWM MODE 7
- ; OUT TCCR0, TEMP
- LDI TEMP,0b00001101 ;SET PRESCALER/DIVIDER TO /1024
- OUT TCCR0,TEMP
- LDI TEMP, 128 ;SET COMPARE TO 128
- OUT OCR0, TEMP
- ; clr R0 ; use as zero value
- ldi TEMP, low(RAMEND) ; Init stack pointer
- out SPL, TEMP ; RAMEND defined in M32DEF.INC
- ldi TEMP, high(RAMEND)
- out SPH, TEMP ; Start of program source code
- ;
- ldi TEMP,0xFF ; Set all pins of port D to be output
- out DDRC,TEMP
- ldi ZH,HIGH(2*SineTable) ; Point Z to Table in flash
- ldi ZL,LOW(2*SineTable)
- clr TEMP
- loop1:
- nop
- nop
- nop
- call Delay
- loop2:
- lpm ; Read from table
- ; Write value to port D
- adiw ZL,1 ; point to next value
- dec TEMP ; End of Table reached
- brne loop1
- ldi ZH,HIGH(2*SineTable); Point Z to Table in flash
- ldi ZL,LOW(2*SineTable)
- rjmp loop2
- ;
- ; End of source code
- ;
- ; Include sinewave table
- ;
- ;
- ; Sinewave table for 8 bit D/A
- ; VCC=5.000V, uLow=0.000V, uHigh=2.500V
- ; (generated by sinewave.pas)
- ;
- MAIN_LOOP: RJMP MAIN_LOOP;A DO-NOTHING LOOP
- Sinetable:
- .DB 64,65,67,68,70,72,73,75
- .DB 76,78,79,81,82,84,85,87
- .DB 88,90,91,92,94,95,97,98
- .DB 99,100,102,103,104,105,107,108
- .DB 109,110,111,112,113,114,115,116
- .DB 117,118,118,119,120,121,121,122
- .DB 123,123,124,124,125,125,126,126
- .DB 126,127,127,127,127,127,127,127
- .DB 128,127,127,127,127,127,127,127
- .DB 126,126,126,125,125,124,124,123
- .DB 123,122,121,121,120,119,118,118
- .DB 117,116,115,114,113,112,111,110
- .DB 109,108,107,105,104,103,102,100
- .DB 99,98,97,95,94,92,91,90
- .DB 88,87,85,84,82,81,79,78
- .DB 76,75,73,72,70,68,67,65
- .DB 64,62,61,59,58,56,54,53
- .DB 51,50,48,47,45,44,42,41
- .DB 39,38,36,35,34,32,31,30
- .DB 28,27,26,25,23,22,21,20
- .DB 19,18,17,15,14,13,13,12
- .DB 11,10,9,8,8,7,6,5
- .DB 5,4,4,3,3,2,2,2
- .DB 1,1,1,0,0,0,0,0
- .DB 0,0,0,0,0,0,1,1
- .DB 1,2,2,2,3,3,4,4
- .DB 5,5,6,7,8,8,9,10
- .DB 11,12,13,13,14,15,17,18
- .DB 19,20,21,22,23,25,26,27
- .DB 28,30,31,32,34,35,36,38
- .DB 39,41,42,44,45,47,48,50
- .DB 51,53,54,56,58,59,61,62
- Delay: ret
- PUSH R16 ; save R16 and 17 as we're going to use them
- PUSH R17 ; as loop counters
- PUSH R0 ; we'll also use R0 as a zero value for compare
- CLR R0
- CLR R16 ; init inner counter
- CLR R17 ; and outer counter
- L1: DEC R16 ; counts down from 0 to FF to 0
- CPSE R16, R0 ; equal to zero?
- RJMP L1 ; if not, do it again
- CLR R16 ; reinit inner counter
- L2: DEC R17
- CPSE R17, R0 ; is it zero yet?
- RJMP L1 ; back to inner counter
- ;
- POP R0 ; done, clean up and return
- POP R17
- POP R16
- RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement