Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; This program reads the analogue input
  2. ; voltage on the ADC and displays it on
  3. ; the scope via the DAC.
  4.  
  5. ; A sample is taken from the ADC every 20 us
  6. ; This is achieved by setting timer 0
  7. ; to interrupt the main program every 20 us.
  8. ; The timer 0 ISR then initiates an ADC
  9. ; conversion.
  10.  
  11. ; When the conversion is complete the
  12. ; ADC interrupt line goes low. This line
  13. ; is interfaced with the 8051 external 0
  14. ; interrupt line. The external 0 ISR
  15. ; therefore takes the reading from the ADC
  16. ; on P2 and passes it to the DAC on P1.
  17.  
  18. ; Therefore, while the program is running,
  19. ; the scope voltage level should be the
  20. ; same as the ADC input voltage.
  21. ; However, when a change is made to the
  22. ; ADC input voltage it will take some time
  23. ; for the scope to update (ie; until the
  24. ; next timer 0 interrupt). This simulates
  25. ; the 20 us delay between samples.
  26.  
  27. ; Note: when running this program make sure
  28. ; the ADC is enabled (the blue button above
  29. ; the input voltage slider should say ADC Enabled).
  30.  
  31. org 0               ; reset vector
  32.     jmp main        ; jump to the main program
  33.  
  34. org 3               ; external 0 interrupt vector
  35.     jmp ext0ISR     ; jump to the external 0 ISR
  36.  
  37. org 0bh             ; timer 0 interrupt vector
  38.     jmp timer0ISR       ; jump to timer 0 ISR
  39.  
  40. org 30h             ; main program starts here
  41. main:
  42.     setb it0        ; set external 0 interrupt as edge-activated
  43.     setb ex0        ; enable external 0 interrupt
  44.     clr p0.7        ; enable DAC WR line
  45.     mov tmod, #2        ; set timer 0 as 8-bit auto-reload interval timer
  46.     mov th0, #-20       ; put -20 into timer 0 high-byte - this reload value,
  47.                 ;    with system clock of 12 MHz, will result in a timer 0 overflow every 20 us
  48.     mov tl0, #-20       ; put the same value in the low byte to ensure the timer starts counting from
  49.                 ;    236 (256 - 20) rather than 0
  50.     setb tr0        ; start timer 0
  51.     setb et0        ; enable timer 0 interrupt
  52.     setb ea         ; set the global interrupt enable bit
  53.     jmp $           ; jump back to the same line (ie; do nothing)
  54.  
  55. ; end of main program
  56.  
  57.  
  58. ; timer 0 ISR - simply starts an ADC conversion
  59. timer0ISR:
  60.     clr p3.6        ; clear ADC WR line
  61.     setb p3.6       ; then set it - this results in the required positive edge to start a conversion
  62.     reti            ; return from interrupt
  63.  
  64.  
  65. ; external 0 ISR - responds to the ADC conversion complete interrupt
  66. ext0ISR:
  67.     clr p3.7        ; clear the ADC RD line - this enables the data lines
  68.     mov p1, p2      ; take the data from the ADC on P2 and send it to the DAC data lines on P1
  69.     setb p3.7       ; disable the ADC data lines by setting RD
  70.     reti            ; return from interrupt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement