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

📄 int0+int1.c

📁 此代码为AT89S51单片机的外部中断C语言程序代码。
💻 C
字号:
/*******************************************************************/
/*                                                                 */
/* 单片机开发系统演示程序 - INT0 INT1 中断计数                     */
/*                                                                 */
/* 6位数码管显示                                                   */
/*                                                                 */
/* 版本: V1.0 (2006/11/20)                                        */
/*                                                                 */
/*【声明】此程序仅用于学习与参考,引用请注明版权和作者信息!       */
/*                                                                 */
/*******************************************************************/
	
#include < reg51.h >
#include <intrins.h>

#define uchar unsigned char
#define uint  unsigned int

unsigned char code  LEDData[ ] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,
                                  0x82,0xF8,0x80,0x90,0xff};
                                    
unsigned char data  display[8] = {0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x00};

unsigned char code  scan_bit[8] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

unsigned char count0,count1,temp=0 ;

/********************************************************
*                                                       *
* 延时函数                                              *
*                                                       *
********************************************************/
void delay(uint ms) 
// 延时子程序
{
 uchar k;
 while(ms--)
 {
  for(k = 0; k < 100; k++);
 }
}

/********************************************************
*                                                       *
*  数据处理与显示函数                                   *
*                                                       *
********************************************************/
void  disp_count()
{
    char n;  

    temp=count0;

    display[2]=temp/100;    //数据处理
    temp=temp%100;
    display[1]=temp/10;
    display[0]=temp%10;

	if(display[2]==0)        //高位为0,不显示 
	{ 
	  display[2]=0x0a;
	  if(display[1]==0)
	  display[1]=0x0a;  
    } 

    temp=count1;

    display[7]=temp/100;    //数据处理
    temp=temp%100;
    display[6]=temp/10;
    display[5]=temp%10;

	if(display[7]==0)        //高位为0,不显示 
	{ 
	  display[7]=0x0a;
	  if(display[6]==0)
	  display[6]=0x0a;  
    } 
     
    for(n=0;n<8;n++)
    {	 
      P0 =LEDData[display[n]] ;  //显示段码
      P2 =scan_bit[n];           //输出位码
      delay(1);
	  P2 = 0xff;                 //关闭显示
    } 
}

/********************************************************
*                                                       *
* 主程序                                               *
*                                                       *
********************************************************/
void main(void)
{  
   P0=0xff;
   P1=0xff;
   P2=0xff;   
   
   IT0=0;          //低电平触发
//   IT0=1;        //下降沿触发
   IT1=0;          //低电平触发
//   IT1=1;        //下降沿触发
   PX0=1;
   EA=1;
   EX1=1;
   EX0=1;

   while(1)
   {
      disp_count();
   }
}

/********************************************************
*                                                       *
* INT0中断函数                                          *
*                                                       *
********************************************************/
void  counter0(void) interrupt 0
{
   uchar  x;
   EX0=0;
   count0++;
    
   for(x=0;x<10;x++)
   {
     disp_count();
   }
   EX0=1;
}

/********************************************************
*                                                       *
* INT1中断函数                                          *
*                                                       *
********************************************************/
void  counter1(void) interrupt 2 
{
   uchar  x;
   EX1=0;
   count1++;
    
   for(x=0;x<10;x++)
   {
     disp_count();
   }
   EX1=1;
}

/********************************************************/


⌨️ 快捷键说明

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