SOUNDER TEST PROGRAM

Sounder Test Program for Mainboard (PIC16F876)

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

Test the Switch
If off go back to Start
If on do the following:
Set sounder High
Wait 500 micro Seconds
Set sounder Low
Wait 500 micro Seconds
Go to Start

The program loops forever and has the following effect:
While the switch is pressed the buzzer will sound @ 1KHz

 

The Code:

 

	list p=16f876
#include "P16F876.inc"
;Define ports so we can use them by name
#define Snd  PORTC,0	;OUTPUT
#define	Sw   PORTC,1	;INPUT
	cblock	20h
	SDelay		;variable for delay routine
	endc
	org 0
	goto init	;jump over interrupt vectors
	
	org 10
init 
	bsf	STATUS, RP0
	bcf	STATUS, RP1	;select bank 1
	movlw	b'11111110'
	movwf	TRISC		;RC0 set as output RC1 as input
	bcf	STATUS, RP0	;select bank 0
Start
	btfsc	Sw		;if switch low skip next instruction
	goto	Start		;if switch high goto start
	bsf	Snd		;set sounder High
	movlw	.50		;50*10uS=500uS
	call	ShortDelay	;wait for 500 micro seconds
	bcf	Snd		;Set sounder Low
	movlw	.50		;50*10uS=500uS
	call	ShortDelay	;wait for 500 micro seconds
	goto	Start		;loop forever
	 

;***** Short Delay 10 uS to 2.55 mSec, value in w on entry, 1 tick = 10 uS
ShortDelay
	movwf	SDelay
WaitSDF	nop
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	SDelay,F
	goto	WaitSDF
	Return
;**************************
;***    Config word     ***
;**************************
	__CONFIG h'3FFF' & _LVP_OFF & _BODEN_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF 
	end

The Results:

The test point was the output at RC0.

Note the Frequency is approx 1KHz