;************************************************************************** ;**** File : Ex3.asm ;**** Read VR1 with the analog voltage input and convert the voltage ;**** to 8-bit digital on LED ;**************************************************************************
org 0x0000 ; bra Main ; org 0x0008 ; bra Hi_ISRs ; ;******************************************************************** ;**** The Main Program start from Here !! ;********************************************************************
org 0x0020 Main: call Init_IO call Init_AD ; AD_Loop call C_Hold_Time ; Delay 50uS for the sample hold time bsf ADCON0,ADON ; Start convert the A/D nop ; Nop btfsc ADCON0,GO ; Check the A/D completed ? bra $-4 ; A/D isn't completed yet, continut check. movff ADRESH,PORTD ; save the a/D result with MSB to PORTD ; goto AD_Loop ;*********************************************************************** ;**** Initial the PORTD for the output port ;*********************************************************************** Init_IO: clrf TRISD clrf PORTD ; bsf TRISA,RA0 ; Set RA0 with input mode ; return ;*********************************************************************** ;**** Initial A/D converter ;*********************************************************************** Init_AD: movlw b'00001110' ; Left Justified, Fosc/32 movwf ADCON1 ; Set AN0 for the Analog Input ; movlw b'10000001' ; Fosc/32 , Select AN0 channel movwf ADCON0 ; A/D on ; bcf PIE1,ADIE ; Disable interrupt of A/D
return ; ; ;*********************************************************************** ;**** Sample Hold (Charge) time delay routine (50uS) ;*********************************************************************** C_Hold_Time: movlw .50 movwf C_Hold_Delay nop decfsz C_Hold_Delay,F bra $-4 return
;*************************************************************************************** ;**** ISRs() : High priority interrupt service routine ;**** ;*************************************************************************************** Hi_ISRs retfie FAST ; Return with shadow register ; END