#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar x,y,face,a,b;
uchar i=0;
uchar shuzu[8][8];
/*uchar shuzu[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=10;y>0;y--);
}
void init()
{
TMOD=0x22;
TH1=0XFf; //波特率設置,波特率為57600
TL1=0XFf;
TH0=0x00;
TL0=0x00;
TR1=1;
TR0=1;
SCON=0X50;
PCON|=0x80;
EA=1;
ES=1;
ET0=1;
PS=1; //讓串口中斷優先,設置優先級高些
}
void main()
{
b=0;
init();
while(1)
{
}
}
void rxd()
interrupt 4
{
uchar temp=0;
RI=0;
++b;
if(b>=8) //上位機中發數據的時候,前面一個不變的地址碼,
//要去掉,故到2的時候才存數據
{
temp=SBUF;
shuzu[x][y]=temp;//把數據存到數組中
x++; if(x>=8) //一列一列存
{
x=0;
y++;
if(y>=8)
y=0;
}
}
if(b>=65) //到65,64個數據接收完畢
b=0;
}
void timer0_isr(void)
interrupt 1 //把數組取出來,送給鎖存器、三極管基極
{
for (i=0;i<7;i++)
{
P2|=(0x01<<i); //573使能端
P0=~(shuzu[face][i]);//573數據輸入端
P2&=~(0x01<<i); //delay(20); }
P3=0X03; // P3=~(0x01<<face); //面選擇端(八個面分別的公共端) //不要加(taf)
if(face<7)
face++;
else
face=0;
}
}
|