|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2015-8-1 16:15:11
|
显示全部楼层
本帖最后由 daiya 于 2015-8-1 21:14 编辑
试了,数码管没反应,我们的数组定义不同, 我用的是a[0]-a[4],你定义的是a[1]-a[5]
附代码:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar SEG7[16]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
uchar ACT[4]={0xf7,0xfb,0xfd,0xfe};
/***************************************************/
sbit D0=P2^0;
sbit D1=P2^1;
sbit D2=P2^2;
sbit D3=P2^3;
sbit D4=P2^4;
sbit D5=P2^5;
sbit D6=P2^6;
sbit D7=P2^7;
#define ON 0
#define OFF 1
uchar a[6];
bit outflag=0;
uint len=0;
/***************************************************/
void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++)
{
for(j=0;j<121;j++)
{
;
}
}
}
/***************************************************/
void init(void)
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SCON=0x50;
EA=1;
ES=1;
}
/***************************************************/
void main(void)
{
init();
while(1)
{
P0=SEG7[a[1]];
P1=ACT[1];
delay(1);
P0=SEG7[a[3]];
P1=ACT[0];
delay(1);
if(outflag==1)
{
switch(a[1])
{
case 1:if(a[3]==1)D0=ON;else D0=OFF;break;
case 2:if(a[3]==1)D1=ON;else D1=OFF;break;
case 3:if(a[3]==1)D2=ON;else D2=OFF;break;
case 4:if(a[3]==1)D3=ON;else D3=OFF;break;
case 5:if(a[3]==1)D4=ON;else D4=OFF;break;
case 6:if(a[3]==1)D5=ON;else D5=OFF;break;
case 7:if(a[3]==1)D6=ON;else D6=OFF;break;
case 8:if(a[3]==1)D7=ON;else D7=OFF;break;
default:break;
}
outflag=0;
}
}
}
/***************************************************/
void serial_serve(void) interrupt 4
{
uchar temp;
static uint len=0;
if(RI)
{
RI=0;
temp=SBUF;
if(!outflag)
{
if((temp=='#')&&(len==0))
{
a[len++]=temp;
}
else if(len)
{
a[len++]=temp;
if(len==5)
{
a[1]=a[1]-0x30;
a[3]=a[3]-0x30;
len=0;
outflag=1;
}
}
}
}
} |
|