EX_PULSE.C  



Example to create a pulse via RTCC( timer0 )

/////////////////////////////////////////////////////////////////////////
////                           EX_PULSE.C                            ////
////                                                                 ////
////  This program uses the RTCC (timer0) to time a single pulse     ////
////  input to the PIC.                                              ////
////                                                                 ////
////                                                                 ////
////        (C) Copyright 1996,1997 Custom Computer Services         ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////

#include <16F84.H>

#fuses   XT,NOPROTECT,NOWDT

#include 

#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)


char get_scale() {
   char scale;

   do {
     printf("\n\rPress S for short or L for long: ");
     scale = getc();
     scale = toupper(scale);
   } while ( (scale!='S') && (scale!='L') );

   return(scale);
}

void wait_for_low_to_high() {
 
   while(input(PIN_B1)) ;       /* if it's high, wait for a low */ 

   delay_us(3);                 /* account for fall time */

   while(!input(PIN_B1));       /* wait for signal to go high */
}

void wait_for_low() {

   delay_us(3);                 /* account for rise time */

   while(input(PIN_B1));        /* wait for signal to go high */
}


main() {

   char scale;
   byte time;

   do {
      scale = get_scale();

      if(scale=='S')
         setup_counters( RTCC_INTERNAL, RTCC_DIV_64 );
      else
         setup_counters( RTCC_INTERNAL, RTCC_DIV_256 );

      printf("\n\rWaiting...\n\r");

      wait_for_low_to_high();
      set_rtcc(0);
      wait_for_low();
      time = get_rtcc();

      printf("Counter value: %2X\n\n\r", time);

   } while (TRUE);
}

Navigation Bar

tech_support@blitzlogic.com