;****************************************************************
;Counter Demonstration							cntr_demo
;This program demos the TMR0 as counter, using ping-pong hardware 
;TJW 15.4.05									Tested 15.4.05
;****************************************************************
;Clock freq 800kHz approx (RC osc.)
;Port A 4  	right paddle (ip) Counter input.
;	  	2	"out of play" led (op)
;Port B 7-0	"play" leds (all op)
;Interrupts not used
;Config Word: RC oscillator, WDT off, PU timer on, code protect off
;
	list 	p=16F84A
	#include p16f84A.inc
;
		org 	00
; Initialise
		bsf		status,rp0 	;select memory bank 1
		movlw	B'00011000'
		movwf	trisa		;port A according to above pattern 
		movlw	00
		movwf	trisb		;all port B bits outout
		movlw 	B'00101000'	;set up TMR0 for external input, +ve edge, 
											;no prescale
		movwf 	TMR0		;as we are in Bank 1, this addresses OPTION
		bcf		status,rp0 	;select bank 0
;
		movlw	04		;switch on "out of play" led to show power is on
		movwf	porta	
loop 	movf	TMR0,0	;Continuously display Timer 0 on Port B
		movwf	portb
		goto 	loop
		end
