Use of the Internal Clock at 37 kHz and 4.0 MHz


This is one of some 100 routines in the tutorial associated with the PIC16F87X Development Package. The narrative and supporting files are contained in the tutorial. Although the major focus of the 16F87X Dev Package is the PIC16F87X family, the PIC16F628 shares many capabilities.

// OSC_1.C (PIC16F628) - CCS PCM
//
// Illustrates the operation of the internal clock at 37 kHz and at
// 4.0 MHz.  Also illustrates use of PORTA6 and PORTA7.  These terminals
// are normally used the processor's clock.
//
// When PORTB.0 is at logic one, processor goes into 37 kHz mode and flashes
// LED on PORTA6.  When at zero, flashes LED on PORTA.7.
//
// Program with clock set to INTRC, IO
//
// copyright, Peter H. Anderson, Baltimore, MD, Apr, '01

#case

#device PIC16F628 *=16

#include <defs_628.h>
#include <delay.h>

#define FALSE 0
#define TRUE !0

void main(void)
{
   byte x;

   ra6 = 0;		// initialize LED outputs to logic zero
   ra7 = 0;
   trisa6 = 0;
   trisa7 = 0;  // make LED an output 0

   not_rbpu = 0; // enable weak pullups
   oscf = 0;  // 37 kHz

   while(1)  // continually
   {
      while(!rb0) // if at logic zero
      {
         oscf = 1; // nominally 4.0 MHz
         ra7 = 1;
         delay_ms(200);
         ra7 = 0;
         delay_ms(200);
      }
      while(rb0)
      {
         oscf = 0; // 37 kHz
         ra6 = 1;
         for (x=0; x<100; x++)  ; // primitive delay
         ra6 = 0;
         for (x=0; x<100; x++)  ; // another delay
      }
   }
}

#include <delay.c>