; pot.asm ; Program to demonstrate getting data via the AD converter attached to the 5K potentiometer ; on the Raven board. The 5K pot is connected to RE0 which is one of the AD converters on the ; 16F877. The diagram is (sort of): ; ; Vcc ; | ; | |---- RE0 ; < | ; 5K < <----vvv---| ; < 100 ; | ; Vdd ;The input to the pot is 5 volts, which is then fed through the pot which has resistance varying ; from 0 to 5000 ohms and then through the 100 ohm (R11) resistor. So the voltage seen at RE0 will ; vary from ; LIST P=16F877, R=DEC INCLUDE "P16F877.inc" ; Definitions ; __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC20 ; Define start of vars RAM EQU 0x20 ; Variables Temp EQU RAM+0 ADValHi EQU RAM+1 ADValLo EQU RAM+2 DTemp1 EQU RAM+3 DTemp2 EQU RAM+4 ; Start of the Program ORG 3 goto Start ORG 0x20 Start bsf STATUS, RP0 clrf TRISA ; for output of value to led bar clrf TRISD bsf TRISE,0 ; input port bcf STATUS, RP0 call ADConfig ; This loop starts the AD conversion process and then keep getting values and outputting to ; the led_bar bsf ADCON0,GO ; start the conversion main_loop call ADConvert iorlw 0 btfss STATUS,Z goto main_loop ; Output the current value - first low and then hi with 250 ms delay movf ADValLo,W call DispLedBar movlw 250 call Delay_ms movf ADValHi,W call DispLedBar ; half second delay after second byte movlw 250 call Delay_ms movlw 250 call Delay_ms goto main_loop ; ------------------------------------------------------------------- ; AD routines ADConfig ; Set the conversion clock rate to Fosc/32, enable RE0 and turn on A/D conversion movlw b'10101001' movwf ADCON0 ; Configure the pin behavior, right justified, Vref+=Vdd, Vref-=Vss bsf STATUS,RP0 movlw b'10001001' bcf STATUS,RP0 return ADConvert ; Check to see if the conversion is done. btfss ADCON0, GO goto convert_done ; Return W = 0 to show that it is not complete retlw 0 convert_done ; Yes, get the value and store it. ; bsf STATUS, RP0 movf ADRESL, W bcf STATUS, RP0 movwf ADValLo movf ADRESH, W movwf ADValHi ; So now, start another conversion bsf ADCON0, GO ; Return W = 1 to show that it is complete retlw 1 return ; ----------------------------------------------- ; Output a value to the LED bar DispLedBar ; Enable the led bar and put the value in W there. movwf Temp ; save W movlw 0x12 movwf PORTA comf Temp,W movwf PORTD return ; ------------------------- ; Delay milliseconds Delay_ms bsf STATUS,RP0 bsf STATUS,RP1 movwf DTemp1 dloop_0 ; number of ms to delay movlw 250 movwf DTemp2 dloop_1 ; 1 ms delay (approximately) fill (nop), 17 decfsz DTemp2,F goto dloop_1 decfsz DTemp1,F goto dloop_0 bcf STATUS,RP1 bcf STATUS,RP0 return END