LED中断 - 武恩赐博客💻

LED中断

#include<reg51.h>
sbit k1=P3^2;
char k=0,i=0,count=0;
unsigned char led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void main()
{    
    TMOD=0x01;
    EA=1;
    EX0=1;
    IT0=1;
    ET0=1;
    TH0=(65535-50000)/256;
    TL0=(65535-50000)%256;
    TR0=0;
    while(1)
    {
    P1=led[i/10];
    P2=led[i%10];
    }
}
void int0() interrupt 0
{
  k++;
    if(k==3)
        k=0;
    switch(k)
    {
        case 0: i=0;TR0=0;break;
        case 1: TR0=1;break;
        case 2: TR0=0;break;            
    }
}
void int1() interrupt 1
{
    count++;
    if(count==19)
    {
        count=0;
        i++;
        if(i>99)
            i=0;
    }
}
无标签
打赏
评论区
头像