#include
__CONFIG(0x3B31);
#defineA0RB0
#defineA1RB1
#defineCSRB2
#defineLERD0
#defineWRRD6
#defineRDRD7
constunsignedchartab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};//0-F-全灭-共阳极数码管
unsignedchartmp[]={0,0,0,0,0,0,0,0};
voiddelay1ms(unsignedintx)
{
unsignedchari;
for(;x》0;x–)
for(i=0;i《165;i++);
}
voidinit()
{
TRISB=0x00;
PORTB=0x00;
TRISD=0x00;
PORTD=0x00;
LE=0;WR=1;RD=1;//关373,制止8255读写
}
voidinit_8255()
{
LE=1;A1=1;A0=1;CS=0;//开373,发送写操控器指令,CS片选答应
LE=0;//锁住373,坚持A1.A0,CS
PORTB=0x80;//发送操控指令
WR=0;//翻开写入8255信号
NOP();NOP();
}
voidwrite_data(unsignedcharcomm,unsignedchardata)//comm:0=A,1=B,2=C
{
if(comm==0)
{
WR=1;
LE=1;A1=0;A0=0;CS=0;
LE=0;
PORTB=data;
WR=0;
NOP();NOP();
}
if(comm==1)
{
WR=1;
LE=1;A1=0;A0=1;CS=0;
LE=0;
PORTB=data;
WR=0;
NOP();NOP();
}
if(comm==2)
{
WR=1;
LE=1;A1=1;A0=0;CS=0;
LE=0;
PORTB=data;
WR=0;
NOP();NOP();
}
}
voiddisplay()
{
unsignedchari,LED;
LED=0x01;
for(i=0;i《8;i++)
{
write_data(0,tab[tmp[i]]);
write_data(1,LED);
LED《《=1;
delay1ms(2);
write_data(1,0x00);
}
}
voidmain()
{
unsignedchari,j,RR[24];
init();
init_8255();
while(1)
{
for(i=0;i《24;i++)//悉数赋值为16,即显现为空,此处可精减,但演示用无所谓了
RR[i]=16;
RR[8]=2;RR[9]=0;RR[10]=0;RR[11]=9;RR[12]=0;RR[13]=7;RR[14]=1;RR[15]=2;
for(j=0;j《16;j++)
{
for(i=0;i《8;i++)//将RR[16]开端内部赋值tmp[]
tmp[i]=RR[16+i];
for(i=0;i《23;i++)
display();
for(i=23;i》0;i–)//此处将RR[]右移一位数组
RR[i+1]=RR[i];
}
}
}