缘由


cpp
#include "reg52.h"
sbit L1=P2^2;
sbit L2=P2^3;
sbit L3=P2^4;
unsigned char code ShuMaGuan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00,0X80,64};//0~9隐.小数点-号
void ShuMaXianShi(unsigned char s,unsigned char w,unsigned char d)
{
P0=L1=L2=L3=0;
switch(w)
{
case 2:{L1=0;L2=L3=1;}break;//011
case 3:{L2=0;L1=L3=1;}break;//101
case 4:{L1=L2=0;L3=1;}break;//001
case 5:{L1=L2=1;L3=0;}break;//110
case 6:{L1=L3=0;L2=1;}break;//010
case 7:{L1=1;L2=L3=0;}break;//100
case 8:{L1=L2=L3=0;}break;//000
case 1:{L1=L2=L3=1;}break;//111
default:{L1=L2=L3=0;}break;
}//d显示小数点11,10关闭
P0=ShuMaGuan[s]|ShuMaGuan[d];
}
unsigned char DuLlJuZhen(/*独立416矩阵*/)
{//1 2 4 8
unsigned char H=15,L=240,Ys=0,zhi=H+L;
P1=15;
if(P1!=15){while(++Ys);if(P1!=15)zhi=P1;while(P1!=zhi);return zhi;}
P1=14;
if(P1!=14){while(++Ys);if(P1!=14)zhi=P1;while(P1!=zhi);return zhi;}
P1=13;
if(P1!=13){while(++Ys);if(P1!=13)zhi=P1;while(P1!=zhi);return zhi;}
P1=11;
if(P1!=11){while(++Ys);if(P1!=11)zhi=P1;while(P1!=zhi);return zhi;}
P1=7;
if(P1!=7){while(++Ys);if(P1!=7)zhi=P1;while(P1!=zhi);return zhi;}
P1 = 0;
return (H+L);
}
void main()
{
unsigned char jz=0,ys=0,xs=0,sm=0;
while(1)
{
if(++ys==0)
{jz=DuLlJuZhen();if(jz!=255)sm=jz;
if(++xs>3)xs=1;
if(xs==1)ShuMaXianShi(sm%10,8,10);
else if(xs==2)ShuMaXianShi(sm/10%10,7,10);
// else if(xs==3)ShuMaXianShi(sm/100,6,10);
}
}
}