//
// pict21c.c
//
// Implementation of the PICT21.ASM program in Easy Pic 'N
// Event counting demo
//
// In this example, TOCKI (RA4) is the external clock source - the
// clock is pulsed by a debounced external switch. In the Easy Pic 'n
// book, the switch is debounced using a half mono multivibrator. 
// The program monitors the A0 port and when it is high, it displays
// the count of the number of external pulses that went into A4
//
// Using '84 on a board (simple solderless breadboard with
// 16F84 on it) and Peter Anderson's include file with 
// port/bit definitions (defs_f84.h available at www.phanderson.com)
// Settings:
// 	4Mhz resonator (not important)
//	All Port A inputs use external pullups (resistor 
//	SIP used)
//	Port B outputs tied to a LED array (Radio Shack 
//	has 'em)
// 	Port A4 used to get inbound external clock pulse
//	Port A0 used to signal when to show the clock total - this means
//	there are two switches in use. One to pulse TOCKI and the other to
//	enable the LED bar so you can see the TMR0 value.
#case
#include <16f84.h>
#include   // defines registers and bits
#fuses xt,nowdt,noput,noprotect
#use delay(clock=4000000)
 

void main(void)
{
   TRISA=0x1f;	// make porta inputs
   TRISB=0x00;  // make portb outputs

   setup_counters(RTCC_EXT_H_TO_L,RTCC_DIV_2);
   
   set_rtcc(0); // reset clock
   
   while(1)
   {
	if(ra0==1)
	{
          PORTB=TMR0;
	}
   }   	  
}