Potentiometer input programming activity

Create the Input program

The entire INPUT.ASM program is shown below. INPUT reads the state of two of the CHRP pushbuttons and outputs a unique pattern for each button on the LEDs. Start a new project in MPLAB, copy the INPUT.ASM code into the project, and build the program.


;INPUT-POT.ASM 	v2.0	Last modified on August 3, 2010
;===============================================================================
;Description:	Senses potentiometer input digitally.

;Start of MPLAB and processor configuration.

	include	"p16f676.inc"		;Include processor definitions 

	__config _CPD_OFF & _CP_OFF & _BODEN_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT 

;End of MPLAB and processor configuration.

;Start of hardware equates.

P1		equ	4		;Potentiometer P1 Port A bit position

	org	3FFh			;Oscillator calibration location

oscillator				

	org	00h			;Start of program memory

		bsf	STATUS,RP0	;Select memory register page 1
		call	oscillator	;Store pre-programmed oscillator calibration
		movwf	OSCCAL		;constant in OSCCAL register
		goto	init		;Start program after Interrupt vector

	org     05h             	;Continue after interrupt vector

init		;Initialize ports A and C for digital I/O

		bcf	STATUS,RP0
		movlw	7		;Disable comparator and make
		movwf	CMCON		;RA0-2 digital I/O
		banksel	ANSEL		;Switch to register bank 1
		movlw	11010111b	;Disable Port A pull-ups, set TMR0 to
		movwf	OPTION_REG	;internal clock with prescaler 256
		clrf	ANSEL		;Set all PORTA pins to digital
		movlw	11011111b	;Set RA5 as output and all
		movwf	TRISA		;other PORTA pins as inputs
		clrf	TRISC		;Set all PORTC pins as outputs
		banksel	PORTC		;Return to PORTC register bank
		clrf	PORTA		;Turn off phototranstor LED
		clrf	PORTC		;Turn all LEDs off

checkP1		btfsc	PORTA,P1	;Check if P1 is low or high
		goto	P1On		;If high, turn high LEDs on
		movlw	00110000b	;If low, turn low LEDs on
		movwf	PORTC
		goto	checkP1		;Check again

P1On		movlw	00001111b	;Turn high LEDs on
		movwf	PORTC
		goto	checkP1		;Check again

	end
		

Download the program into the CHRP and verify its operation.