Advertisement
Guest User

Untitled

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