程序:
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define T0_Value 50000
#define SEL_CHIP P1
#define IN_CHIP P2
#define LINE_OUT P0
uchar count=0;
uchar *pointer=&count;
uint offset=0;
uchar code dis[4][32]={
{0x04,0x28,0x08,0x24,0x32,0x22,0xC2,0x21,0xC2,0x26,0x34,0x38,0x04,0x04,0x08,0x18,0x30,0xF0,0xC0,0x17,0x60,0x10,0x18,0x10,0x0C,0x14,0x06,0x18,0x04,0x10,0x00,0x00},
{0x02,0x02,0x04,0x82,0xF8,0x73,0x04,0x20,0x02,0x00,0xE2,0x3F,0x42,0x20,0x82,0x40,0x02,0x40,0xFA,0x3F,0x02,0x20,0x42,0x20,0x22,0x20,0xC2,0x3F,0x02,0x00,0x00,0x00},
{0x00,0x01,0x04,0x02,0x1C,0x0C,0xC0,0x3F,0x1C,0xC0,0x02,0x09,0x02,0x16,0x92,0x60,0x4A,0x20,0x82,0x2F,0x02,0x20,0x0E,0x24,0x00,0x22,0x90,0x31,0x0C,0x20,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};
void delay_ms(uint ms);
void Init(void);
void scan(void);
int main(void)
{
pointer=&dis[0][0];
Init();
while (1)
{
scan();
}
}
void delay_ms(uint value)
{
uint i,j;
for(i=0;i<value;i++)
for(j=0;j<118;j++);
}
void Timer0_Handler(void) interrupt 1 using 3
{
TH0=(65536-T0_Value)/256;
TL0=(65536-T0_Value)%256;
if (count<20)
{
count++;
}
else
{
offset+=2;
if (offset>128)
offset=0;
count=0;
}
}
void Init(void)
{
TH0=(65536-T0_Value)/256;
TL0=(65536-T0_Value)%256;
TMOD|=0X01;
ET0=1;
EA=1;
count=0;
TR0=1;
}
void scan(void)
{
uchar i=0;
for (i=0;i<8;i++)
{
LINE_OUT=*(pointer+offset+2*i);
IN_CHIP=i;
SEL_CHIP=0x10;
delay_ms(1);
LINE_OUT=*(pointer+offset+2*i+1);
IN_CHIP=i;
SEL_CHIP=0x20;
delay_ms(1);
}
for (i=8;i<16;i++)
{
LINE_OUT=*(pointer+offset+2*i);
IN_CHIP=i;
SEL_CHIP=0x40;
delay_ms(1);
LINE_OUT=*(pointer+offset+2*i+1);
IN_CHIP=i;
SEL_CHIP=0x80;
delay_ms(1);
}
}