51单片机实现外部中断00H-FFH000-2550000-1023

Posted Velma

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了51单片机实现外部中断00H-FFH000-2550000-1023相关的知识,希望对你有一定的参考价值。

外部中断00H-FFH

#include< reg51.h>
#define uint unsigned int
#define uchar unsigned char
sfr P0M0 = 0x94;
sfr P0M1 = 0x93;
sfr P2M0 = 0x96;
sfr P2M1 = 0x95;
uchar count;
uchar i;
uchar code leddata[]={
    0xC0,  //"0"
    0xF9,  //"1"
    0xA4,  //"2"
    0xB0,  //"3"
    0x99,  //"4"
    0x92,  //"5"
    0x82,  //"6"
    0xF8,  //"7"
    0x80,  //"8"
    0x90,  //"9"
    0x88,  //"A"
    0x83,  //"B"
    0xC6,  //"C"
    0xA1,  //"D"
    0x86,  //"E"
    0x8E,  //"F"
    0x89,  //"H"
    0xC7,  //"L"
    0xC8,  //"n"
    0xC1,  //"u"
    0x8C,  //"P"
    0xA3,  //"o"
    0xBF,  //"-"
};
uchar code ledwei[]={
    0x01,0x02,0x04,0x08,
    0x10,0x20,0x40,0x80   
};
void delay(uint ms){
    uint i,j;
    for(i = 0;i < ms; i++)
    for(j = 0;j < 121; j++);
}
void init(){
    EX0 = 1;       
    IT0 = 1;      
    EA = 1;           
}
void display(){       
         while(1){
                P2 = ~ledwei[0];
                P0 = leddata[i];
            delay(50);
            P2 = ~ledwei[1];
            P0 = leddata[count];
            delay(50);
            P2 = ~ledwei[2];
            P0 = leddata[16];
            delay(50);
        }        
}
void main(){
    P0M0 = 0x00;
    P0M1 = 0x00;
    P2M0 = 0x00;
    P2M1 = 0x00;

    init();       
    while(1){
        display();       
    }
}
void int0() interrupt 2{
    count++;
    if(count == 16){
        count = 0;
        i++;
        if(i == 16){
            i = 0;
        }
    }
}

外部终端实现数码管000-255

#include< reg51.h>
#define uint unsigned int
#define uchar unsigned char
sfr P0M0 = 0x94;
sfr P0M1 = 0x93;
sfr P2M0 = 0x96;
sfr P2M1 = 0x95;
uchar count;
uchar i,j,m;
uchar code leddata[]={
    0xC0,  //"0"
    0xF9,  //"1"
    0xA4,  //"2"
    0xB0,  //"3"
    0x99,  //"4"
    0x92,  //"5"
    0x82,  //"6"
    0xF8,  //"7"
    0x80,  //"8"
    0x90,  //"9"
    0x88,  //"A"
    0x83,  //"B"
    0xC6,  //"C"
    0xA1,  //"D"
    0x86,  //"E"
    0x8E,  //"F"
    0x89,  //"H"
    0xC7,  //"L"
    0xC8,  //"n"
    0xC1,  //"u"
    0x8C,  //"P"
    0xA3,  //"o"
    0xBF,  //"-"
    0xFF,  //??
    0xFF  //???
};
uchar code ledwei[]={
    0x01,0x02,0x04,0x08,
    0x10,0x20,0x40,0x80   
};
void delay(uint ms){
    uint i,j;
    for(i = 0;i < ms; i++)
    for(j = 0;j < 121; j++);
}
void init(){
    EX0 = 1;      
    IT0 = 1;      
    EA = 1;         
}
void display(){        

        while(1){
            P2 = ~ledwei[0];
            P0 = leddata[j];
            delay(50);
            P2 = ~ledwei[1];
            P0 = leddata[i];
            delay(50);
            P2 = ~ledwei[2];
            P0 = leddata[count];
            delay(50);
        }        
}
void main(){
    P0M0 = 0x00;
    P0M1 = 0x00;
    P2M0 = 0x00;
    P2M1 = 0x00;

    init();       
    while(1)
    {
        display();       
    }
}
void int0() interrupt 2{
    count++;
    m++;
    if(m == 256){
        m = 0;
        count = 0;
        i = 0;
        j = 0;
    }
    if(count == 10){
        count = 0;
        i++;
        if(i == 10){
            i = 0;
            j++;
            if(j == 3){
                j = 0;
            }
        }
    }

}

0000-1023

#include< reg51.h>
#define uint unsigned int
#define uchar unsigned char
sfr P0M0 = 0x94;
sfr P0M1 = 0x93;
sfr P2M0 = 0x96;
sfr P2M1 = 0x95;
uchar count;
uchar i,j,m,n;
uchar code leddata[]={
    0xC0,  //"0"
    0xF9,  //"1"
    0xA4,  //"2"
    0xB0,  //"3"
    0x99,  //"4"
    0x92,  //"5"
    0x82,  //"6"
    0xF8,  //"7"
    0x80,  //"8"
    0x90,  //"9"
    0x88,  //"A"
    0x83,  //"B"
    0xC6,  //"C"
    0xA1,  //"D"
    0x86,  //"E"
    0x8E,  //"F"
    0x89,  //"H"
    0xC7,  //"L"
    0xC8,  //"n"
    0xC1,  //"u"
    0x8C,  //"P"
    0xA3,  //"o"
    0xBF,  //"-"
    0xFF,  //??
};
uchar code ledwei[]={
    0x01,0x02,0x04,0x08,
    0x10,0x20,0x40,0x80   
};
void delay(uint ms){
    uint i,j;
    for(i = 0;i < ms; i++)
    for(j = 0;j < 121; j++);
}
void init(){
    EX1 = 1;       
    IT1 = 1;       
    EA = 1;            
}
void display(){        

        while(1){
            P2 = ~ledwei[0];
            P0 = leddata[n];
            delay(20);
            P2 = ~ledwei[1];
            P0 = leddata[j];
            delay(20);
            P2 = ~ledwei[2];
            P0 = leddata[i];
            delay(20);
            P2 = ~ledwei[3];
            P0 = leddata[count];
            delay(20);
        }        
}
void main(){
    P0M0 = 0x00;
    P0M1 = 0x00;
    P2M0 = 0x00;
    P2M1 = 0x00;

    init();        
    while(1) {
        display();        
    }
}
void int0() interrupt 2{
    count++;
    m++;
    if(m == 1024){
        m = 0;
        count = 0;
        i = 0;
        j = 0;
    }
    if(count == 10){
        count = 0;
        i++;
        if(i == 10){
            i = 0;
            j++;
            if(j == 10){
                j = 0;
                n++;
                if(n == 2){
                    n = 0;
                }
            }
        }
    }

 

以上是关于51单片机实现外部中断00H-FFH000-2550000-1023的主要内容,如果未能解决你的问题,请参考以下文章

51单片机的中断嵌套怎么实现呢?

51单片机2个外部中断实现5中模式4中速度跑马灯效果

求助,51单片机无法进入外部中断的问题

51单片机实现外部中断0-F

关于51单片机的外部中断使用方法

51单片机外部中断0函数执行时,又来了个外部中断0信号