Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. list p=18f452
  2. include p18f452.inc
  3.  
  4. ;## PART A
  5. ;Write an assembly subroutine to configure the ADC to use reference voltages Vdd and Vss. Analog Channels 2 and 3 will have some analog device on it.
  6. ;## PART B
  7. ;Write an assembly subroutine that:
  8. ;- Samples analog channel 2, and places the left justified result in the variable `analog2H:analog2L`
  9. ;- Samples analog channel 3, and places the left justified result in the variable `analog3H:analog2H`
  10. ;All variables must be placed in data memory bank 1.
  11. ;## PART C
  12. ;Explain why the PIC18 Analog to Digital converter is termed a 'ratiometric' converter
  13.  
  14. ;# ADC QUESTION 2
  15.  
  16.  
  17. UDATA 0x100
  18. analog2H res 2
  19. analog2L res 2
  20. analog3H res 2
  21. analog3L res 2
  22. ; Declare a code section at 0x0 named 'RST'. This instruction sends the
  23. ; program to the actual start of the program.
  24. RST code 0x0030
  25. GOTO Setup
  26.  
  27. ; Declare a code section at 0x0030. This is where the actual program logic will start
  28. SRT code 0x0080
  29.  
  30.  
  31. Setup:
  32. clrf PORTA ; Clear PORTB
  33. BSF TRISA, 2
  34. BSF TRISA, 3
  35.  
  36. movlw B'01000000' ; Fosc/8, A/D enabled
  37. IORLW B'010' ;Channel 2
  38. ; IORLW B'011' ;Channel 3
  39. movwf ADCON0
  40.  
  41. movlw B'00001110' ; Left justify, 1 analog channel
  42. movwf ADCON1 ; VDD and VSS references
  43. MOVLB 01 ;slect BAnk 1
  44.  
  45.  
  46.  
  47. Main:
  48. bsf ADCON0, GO ; Start A/D conversion
  49. call WaitForAdConversion
  50.  
  51.  
  52.  
  53. ReadFirst:
  54. MOVF ADRESH, W ; Store value from the potentiometer
  55. MOVWF analog2H, BANKED
  56. MOVF ADRESL, W ; Store value from the potentiometer
  57. MOVWF analog2L, BANKED ; Send as the 'on time' for the wave
  58. MOVLW 0x0F ;Clear the channel bits
  59. ANDWF ADCON0
  60. MOVLW B'011' ;Channel 3
  61. movwf ADCON0
  62. bsf ADCON0, GO
  63. call WaitForAdConversion
  64.  
  65.  
  66.  
  67. ReadSecond:
  68. MOVF ADRESH, W ; Store value from the potentiometer
  69. MOVWF analog2H, BANKED
  70. MOVF ADRESL, W ; Store value from the potentiometer
  71. MOVWF analog2L, BANKED ; Send as the 'on time' for the wave
  72. goto Main ; Repeat the process
  73.  
  74.  
  75.  
  76. WaitForAdConversion:
  77. btfss PIR1, ADIF ; Wait for conversion to complete
  78. goto WaitForAdConversion
  79. return
  80.  
  81.  
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement