; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; POT ; This program shows a technique for reading resistance. The pot input pin can ; only be changed during assembly, not once the program is running. P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off reset start org 8 temp Res d'1' ; Temporary counter for delay. potL Res d'1' ; Low byte of Pot measurement. potH Res d'1' ; High byte of Pot measurement. pot equ ;ra.0 Pin assigned to pot. out_pot equd'0' ; Value to set ra.0 to output for pot. in_pot equd'1' ; Value to set ra.0 to input for pot. org 0 start MOVLW out_pot ; RA.0 to output. TRIS 5h MOVLW d'0' ; All outputs for LEDs. TRIS 6h BSF 5h,d'0' ; Start charging cap. MOVLW d'8' ; Set up for 6-ms delay: 8 trips MOVWF potL start_wait DECFSZ temp ; through outside loop x 256 GOTO start_wait DECFSZ potL ; x 3 cycles for inside loop = 6.1 ms. GOTO start_wait CLRF potL CLRF potH MOVLW in_pot ; Get input from pot. TRIS 5h BCF 5h,d'0' ; Clear output latch for pot bit. start_loop BTFSS 5h,d'0' ; IF pot = 0 THEN :done GOTO start_done MOVLW out_pot ; Discharge cap a little. TRIS 5h MOVLW in_pot ; Change pot pin to input. TRIS 5h INCF potL ; Incerement potL. BTFSC status,z ; If zero then potL overfolowed, so INCFSZ potH ; increment potH. If it overflows, exit. GOTO start_loop ; Overflowed? No: loop. start_done MOVLW d'2' ; Divide 16-bit number represented by MOVWF temp start_div BCF status,c ; potH and potL by 2^temp (in this case, RRF potH ; 2^2 or 4). This scales the pot value to RRF potL ; fit within an 8-bit range. DECFSZ temp GOTO start_div MOVF potL,w ; Show the outcome on LEDs. MOVWF 6h GOTO start ; Do it a end