SWITCH TEST PROGRAM

Switch test program for Mainboard (PIC16F876)

The main part of the code at "Start" performs the following function:

Turn both LED's off
Test the switch
If it's on turn on the LED's and go back to Test the switch
If it's off go back to Start

The routine is in an endless loop.

This has the effect of turning on the LED's when the switch is pressed.

Notes of interest:
As RA2 and RA3 (LED's) are preset to analogue inputs at power on you have to change them to digital I/O's by loading b'00000110' into the ADCON1 register.
Likewise RA2 and RA3 have to be set to outputs by loading b'11110011' into the TRISA register.
Both these registers are in Bank1, bank 1 is selected by setting RP0 and resetting RP1 in the STATUS register.
The switch is on RC1 and is active low. (I/P goes to zero when the switch is pressed)

 

The Code:

 

	list p=16f876
#include "P16F876.inc"
;Define ports so we can use them by name
#define AntL PORTA,2	;OUTPUT
#define AntR PORTA,3	;OUTPUT
#define Sw   PORTC,1	;INPUT
	cblock	20h
	VLDelay, LDelay, MDelay, SDelay		;variables for delay routines
	endc
	org 0
	goto init	;jump over interrupt vectors
	
	org 10
init 
	bsf		STATUS, RP0
	bcf		STATUS, RP1			;select bank 1
	movlw	b'11110011'
	movwf	TRISA				;RA2,RA3 set as outputs
	movlw	b'00000110'			;set porta i/o's as digital
	movwf	ADCON1
	bcf		STATUS, RP0			;select bank 0
Start
	bcf		AntL
	bcf		AntR
loop
	btfsc	Sw
	goto	Start
	bsf		AntL
	bsf		AntR
	goto	loop

;**************************
;***    Config word     ***
;**************************
	__CONFIG h'3FFF' & _LVP_OFF & _BODEN_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF 
	end