STC89C51 中断

#include<reg52.h>
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
sbit ENLED=P1^4;

unsigned char code LedChar[]={
    0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
    0x80,0x90,0x83,0xC6,0xA1,0x86,0x8E};

unsigned char LedBuFF[6]={
        0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
};

    
    
void main()
{
    unsigned int cnt=0;
    unsigned int sec=0;
    
    ENLED=0;
     ADDR3=1;
    TMOD=0x01;
    TH0=0xFC;
    TL0=0x67;
    TR0=1;
    EA=1;
    ET0=1;
    while(1)
    {
    
        
            if(cnt>=1000)
            {
                cnt=0;
                sec++;
                LedBuFF[0]=LedChar[sec%10];
                LedBuFF[1]=LedChar[sec/10%10];
                LedBuFF[2]=LedChar[sec/100%10];
                LedBuFF[3]=LedChar[sec/1000%10];
                LedBuFF[4]=LedChar[sec/10000%10];
                LedBuFF[5]=LedChar[sec/100000%10];
            
            }
                    

    }

}
unsigned char i=0;
unsigned int cnt=0;
void Interrupttime0() interrupt 1
{
    TH0=0xFC;
    TL0=0x67;
    cnt++;
    P0=0xFF;
        switch(i)
            {
                    case 0:     ADDR2=0;ADDR1=0;ADDR0=0; i++; P0=LedBuFF[0]; break;
                    case 1:     ADDR2=0;ADDR1=0;ADDR0=1; i++; P0=LedBuFF[1]; break;
                    case 2:     ADDR2=0;ADDR1=1;ADDR0=0; i++; P0=LedBuFF[2]; break;
                    case 3:     ADDR2=0;ADDR1=1;ADDR0=1; i++; P0=LedBuFF[3]; break;
                    case 4:     ADDR2=1;ADDR1=0;ADDR0=0; i++; P0=LedBuFF[4]; break;
                    case 5:     ADDR2=1;ADDR1=0;ADDR0=1; i++; P0=LedBuFF[5]; break;
                default:
                    break;
                
            }
                
                

        }    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值