c语言外部中断程序,写了一个 51单片机外部中断程序

/*以下是能在keilC 中变异的源码,直接粘贴过去就行,外部中断0(INT0)和外部中断1都有(INT1)*/

/*程序很简单,但是对新手来说还是很实用的*/

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

/*                                                                 */

/* 单片机开发系统演示程序 - INT0 INT1 中断计数                     */

/*                                                                 */

/* 6位数码管显示                                                   */

/*                                                                 */

/* 作者:曾露337  店铺:http://shop58430712.taobao.com             */

/*                                                                 */

/*【声明】此程序仅用于学习与参考,引用请注明版权和作者信息!       */

/*                                                                 */

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

#include < reg51.h >

#include

#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;

}

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值