https://static.assets-stash.eet-china.com/album/old-resources/2009/5/14/ceba89a1-32a0-4361-98ac-91ab24b77466.rar# include <reg51.h>
unsigned char tab []={0xc0,0xf9,0xa4,0xb0,0x99,0x92, 0x82,0xf8,0x80,0x90,0xff}; //共阳数码管段码
sbit s0=P3^0;
sbit s1=P3^1;
sbit s2=P3^2;
sbit s3=P3^3;
sbit s4=P3^4;
sbit s5=P3^5;
sbit s6=P3^6;
sbit s7=P3^7;
unsigned char temp;
unsigned char lin;
unsigned char row;
void delay()
{
//去抖动
int i,j;
for (i=0;i<10;i++)
{
for (j=0;j<100;j++)
{}
}
}
void linscan ()
{
P3=0xf0;
if (s0==1)
{
delay() ;
if (s0==1)
lin="0";
}
if (s1==1)
{
delay() ;
if (s1==1)
lin="1";
}
if (s2==1)
{
delay() ;
if (s2==1)
lin="2";
}
if (s3==1)
{
delay() ;
if (s3==1)
lin="3";
}
}
void rowscan ()
{
P3=0x0f;
if (s4==1)
{
delay() ;
if (s4==1)
row="0";
}
if (s5==1)
{
delay() ;
if (s5==1)
row="1";
}
if (s6==1)
{
delay() ;
if (s6==1)
row="2";
}
if (s7==1)
{
delay() ;
if (s7==1)
row="3";
}
}
void main ()
{
while (1)
{
linscan ();
rowscan ();
temp="lin"*4+row;
P0=tab [temp];
}
}
用户218444 2009-6-25 17:56