整个程序:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar xx=0,yy=0,layer=0,icnt,rxcnt;
uchar display[8][8];
/*uchar display[8][8]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
}; */
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
TMOD=0x22;
TH1=0Xff;
TL1=0Xff;
TH0=0xff;
TL0=0xff;
TR1=1;
TR0=1;
SCON=0X50;
PCON|=0x80; //波特率加倍
EA=1;
ES=1;
ET0=1; //开定时器0中断
PS=1; //配置串口中断优先
}
void main()
{
//P3=0x01;
rxcnt=0;
init();
while(1)
{
}
}
void rxd() interrupt 4
{
uchar temp=0;
ES=0;
RI=0;
rxcnt++; //前面有一个地址码0xf2,要去掉,>=2时才能接收数据
if(rxcnt>=2)
{
temp=SBUF;
display[xx][yy]=temp;
yy++;
if(yy>=8)
{
yy=0;
xx++;
if(xx>=8)
xx=0;
}
}
if(rxcnt>=65)
rxcnt=0;
ES=1;
}
void timer0_isr(void) interrupt 1
{
uchar i=0;
for (i=0;i<7;i++)
{
P2|=(0x01<<i);
P0=~(display[layer][i]);
P2&=~(0x01<<i);
}
P3=(0x01<<layer);
if(layer<7)
layer++;
else
layer=0;
}
|