⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmr0.c

📁 这是MICROCHIP 的PIC 系列单片机常用 的C语言编译器。特别对PIC16F877系列 特别好用。
💻 C
字号:
#pragma option v;
/*
   These routines may be adapted for any purpose when
   used with the MPC Code Development system.  No
   warranty is implied or given as to their usability
   for any purpose.

        (c) Copyright 1995,1996

        Byte Craft Limited
        Waterloo, Ontario
        Canada N2J 4E4
        (519) 888-6911

        Sherif Abdel-Kader

 This example demonstrates using the TMR0 interrupt
 on the 16C74. The technique is the same for all PIC16Cxx devices

 With a 4MHz crystal and a 1:256 prescale value,
 a TMR 0 interrupt should occur approximately every
 65ms. Each time an interrupt occurs, 'i' is incremented
 and sent to PORT B. By connecting PORT B to 8-LEDs,
 one can verify that the value on PORTB is incrementing
 at uniform intervals.
*/

#define NOLONG     // Comment this out if using 'long' variables
#include <16C621.h>

void handle_TMR0();

unsigned int i=0;   // counter


///////////////////////////////////////////////////////////

void __INT(void)
{

 SaveContext();

  if (INTCON.T0IF)   // TMR0 overflowed
   { 
    INTCON.T0IF = 0; // Clear T0IF
    handle_TMR0();   // Call handler
   } // if

 RestoreContext();
}

///////////////////////////////////////////////////////////

void main()
{


  // Mask and clear all interrupts
     INTCON = 0;
     PIR1 = 0;
     PIE1 = 0;

     TRISB =0;       // PORT B in output mode

     OPTION = 0xD7;  // Internal clock for TMR0
                     // Prescaler = 1:256

  // Enable desired interrupts
     INTCON.T0IE = 1;      // Timer 0 overflow interrupt

  // Enable unmasked interrupts
     INTCON.GIE = 1;       // Global interrupt enable

  // Loop until an interrupt occurs
     while(1)
       {
       }
} // main


///////////////////////////////////////////////////////////

void handle_TMR0()
{
  // Code for handling TMR0 overflow interrupt
  //
  PORTB=i;
  i++;
}
//////////////////////////////////////////////////////////


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -