单片机中断的应用

51单片机:

       P3.2 引脚为INT0 中断

       P3.3引脚为INT1 中断

按钮 P3.2    P3.3

按钮低电平触发:

    while(PB0==0);

    delay();

#include <reg51.h>         
#define    SEG    P0             //    定义七节显示器接至Port 0
sbit    LED = P2^0;      // 定义LED灯接至P2.0
sbit    com = P1^0 ;     // 数码管 com 口
sbit    OC  = P1^1;      // 定义573锁存器使能口,我是用的573驱动7段数码管
 
void delay10ms(int x);    //    声明延迟函数 10ms * x; 

sbit    PB0=P3^2;      //按钮0
sbit    PB1=P3^3;      //按钮1
 
unsigned char code TAB[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67 };    // 共阴极
 
main()                     
{  
    OC = 0;          //锁存置0 ,点亮数码管
    com = 0;         //点亮SEG    
    EA =1;             //总中断
     EX0 = 1;         //外部中断 INT0
     EX1 = 1;         //外部中断 INT1     
    TR0 = 1;         //    运行INT 0中断
      TR1 = 1;         // 运行INT1 中断
    //TCON = 0x05;     //    设置信号触发方式为负边沿触发
    while(1) 
    {    
        int i; 
        for(i=0;i<10;i++)    //    显示0-9(上数)
        {    SEG=TAB[i];     
            delay10ms(40);    //    延迟 0.4s

} } } void my_int0(void) interrupt 0 // INT 0 { int i; while(PB0==0); delay10ms(25); for (i=9;i>=0;i--) // for循环显示9-0(下数) { SEG=TAB[i]; // 显示数字至七节显示器 delay10ms(40); // 延迟 0.4s } } void my_int1(void) interrupt 2 //INT 1 { int i; while(PB1==0); delay10ms(25); for(i=0;i<10;i++) { LED = 0; delay10ms(25); LED = 1; delay10ms(25); } } /* 延迟函数,延迟约x*1ms */ void delay10ms(int x) // 延迟函数开始 { int i,j; for (i=0;i<x;i++) // 计数x次,延迟x*10ms for (j=0;j<1200;j++); // 计数1200次,延迟10ms 1200*8us }

 

       

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/zhaocundang/p/4976744.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值