单片机8*8点阵 利用中断控制显示0-3; 但是我只能显示一个“0” 不知道如何写下去了,求高手帮我完成!

2024-11-16 05:39:39
推荐回答(2个)
回答1:

#include
#define uint unsigned int
#define uchar unsigned char
#define DataPortA P0
uint i,i1,num;
sbit sn=P3^7;
uchar ShowNumber = 0;
uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //位码
uchar code duan0[]={0xFF,0xC7,0xBB,0xBB,0xBB,0xBB,0xBB,0xC7, //0
0xFF,0xDF,0xCF,0xDF,0xDF,0xDF,0xDF,0x8F, //1
0xFF,0xC7,0xBB,0xBF,0xBF,0xC3,0xFB,0x83, //2
0xFF,0xC7,0xBB,0xBF,0xC7,0xBF,0xBB,0xC7, //3
0xFF,0xDF,0xCF,0xD7,0xDB,0x83,0xDF,0xDF, //4
0xFF,0x83,0xFB,0xC3,0xBF,0xBF,0xBB,0xC7, //5
0xFF,0xC7,0xBB,0xFB,0x83,0xBB,0xBB,0xC7, //6
0xFF,0x83,0xBF,0xBF,0xDF,0xDF,0xDF,0xDF, //7
0xFF,0xC7,0xBB,0xBB,0xC7,0xBB,0xBB,0xC7, //8
0xFF,0xC7,0xBB,0xBB,0x87,0xBF,0xBB,0xC7, //9

};
void delay(uint t);
void main()
{

TMOD=0x11;
TH0=0x0FC;;
TL0=0xe8;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
ET1=1;
TR1=1;

while(1)
{
if(num==20)
{
num=0;
ShowNumber++;
if(ShowNumber>9)
ShowNumber = 0;

}

}
}

void delay(unsigned int t)
{
while(--t);
}
void timer0() interrupt 1
{
TH0=0x0FC;
TL0=0xe8;
i++;
if(i==8){i=0;}
DataPortA=wei[i];
sn=1; //使能端
sn=0;
DataPortA=0xff;
DataPortA=duan0[i+ShowNumber*8];
delay(50);
}
void timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num++;
}

回答2:

#include
#define uint unsigned int
#define uchar unsigned char
#define DataPortA P0
uint i;Uint number;
sbit sn=P3^7; //使能端
uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //位码

uchar code duan0[]={0xFF,0xC7,0xBB,0xBB,0xBB,0xBB,0xBB,0xC7, //0
0xFF,0xDF,0xCF,0xDF,0xDF,0xDF,0xDF,0x8F, //1
0xFF,0xC7,0xBB,0xBF,0xBF,0xC3,0xFB,0x83, //2
0xFF,0xC7,0xBB,0xBF,0xC7,0xBF,0xBB,0xC7, //3
};
void delay(uint t);
void main()
{

TMOD=0x01;
TH0=0x0FC;;
TL0=0xe8;
EA=1;
ET0=1;
TR0=1;
while(1)
{
;

}
}

void delay(unsigned int t)
{
while(--t);
}
void timer0() interrupt 1
{
TH0=0x0FC;;
TL0=0xe8;for(i=0;i<8;i++)
{ DataPortA=wei[i];
sn=1; //使能端
sn=0;
DataPortA=0xff;
DataPortA=duan0[i+number*8];}
number++;If(number>=3)number=0;
delay(50);
}