Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list p=18f452
- include p18f452.inc
- ;## PART A
- ;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.
- ;## PART B
- ;Write an assembly subroutine that:
- ;- Samples analog channel 2, and places the left justified result in the variable `analog2H:analog2L`
- ;- Samples analog channel 3, and places the left justified result in the variable `analog3H:analog2H`
- ;All variables must be placed in data memory bank 1.
- ;## PART C
- ;Explain why the PIC18 Analog to Digital converter is termed a 'ratiometric' converter
- ;# ADC QUESTION 2
- UDATA 0x100
- analog2H res 2
- analog2L res 2
- analog3H res 2
- analog3L res 2
- ; Declare a code section at 0x0 named 'RST'. This instruction sends the
- ; program to the actual start of the program.
- RST code 0x0030
- GOTO Setup
- ; Declare a code section at 0x0030. This is where the actual program logic will start
- SRT code 0x0080
- Setup:
- clrf PORTA ; Clear PORTB
- BSF TRISA, 2
- BSF TRISA, 3
- movlw B'01000000' ; Fosc/8, A/D enabled
- IORLW B'010' ;Channel 2
- ; IORLW B'011' ;Channel 3
- movwf ADCON0
- movlw B'00001110' ; Left justify, 1 analog channel
- movwf ADCON1 ; VDD and VSS references
- MOVLB 01 ;slect BAnk 1
- Main:
- bsf ADCON0, GO ; Start A/D conversion
- call WaitForAdConversion
- ReadFirst:
- MOVF ADRESH, W ; Store value from the potentiometer
- MOVWF analog2H, BANKED
- MOVF ADRESL, W ; Store value from the potentiometer
- MOVWF analog2L, BANKED ; Send as the 'on time' for the wave
- MOVLW 0x0F ;Clear the channel bits
- ANDWF ADCON0
- MOVLW B'011' ;Channel 3
- movwf ADCON0
- bsf ADCON0, GO
- call WaitForAdConversion
- ReadSecond:
- MOVF ADRESH, W ; Store value from the potentiometer
- MOVWF analog2H, BANKED
- MOVF ADRESL, W ; Store value from the potentiometer
- MOVWF analog2L, BANKED ; Send as the 'on time' for the wave
- goto Main ; Repeat the process
- WaitForAdConversion:
- btfss PIR1, ADIF ; Wait for conversion to complete
- goto WaitForAdConversion
- return
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement