#include<reg52.h>
#include <intrins.h>
#include <stdio.h>//这是头文件
/*==============================宏定义===================*/
#define M 4 //要测试的芯片好坏的个数
#define N 8
#define input1 P1 //用于检测的引脚
#define input2 P2
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^0; // 选择检测芯片型号
sbit key2=P3^1; // 复位
sbit key3=P3^2; // 自动检测
sbit ledR=P3^7;/*红色发光led接单片机P3.7 */
sbit ledG=P3^6;/*绿色放发光LED接单片机P3.6 */
sbit dula4=P2^6;//声明锁存器的锁存端
sbit dula1=P3^3;
sbit dula2=P3^4;
sbit dula3=P3^5;
sbit wela =P2^7;
unsigned int name[]={7400,7404,7420,7486,7474,7492};
uchar code table[] ={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//共阴极数码管编码
/*==============================按键的标志位============*/
unsigned char time=0; //用来标示某芯片各通道检测均完好的标志位
unsigned char k=0; //返回自动检测后芯片序号在已定义的数组中的序号
unsigned char code LS00[4][4]={
0x3f,0x3f,0x1b,0x1b, //74ls00
0x24,0x24,0x24,0x24,
0x36,0x36,0x36,0x36,
0x2d,0x2d,0x2d,0x2d
};
unsigned char code LS04[2][4]={
0x2a,0x2a,0x2a,0x2a, //74ls04
0x3f,0x3f,0x15,0x15
};
unsigned char code LS20[16][4]={
0x24,0x24,0x24,0x24, //74ls20
0x25,0x25,0x25,0x25,
0x26,0x26,0x26,0x26,
0x27,0x27,0x27,0x27,
0x2c,0x2c,0x2c,0x2c,
0x2d,0x2d,0x2d,0x2d,
0x2e,0x2e,0x2e,0x2e,
0x2f,0x2f,0x2f,0x2f,
0x34,0x34,0x34,0x34,
0x35,0x35,0x35,0x35,
0x36,0x36,0x36,0x36,
0x37,0x37,0x37,0x37,
0x3c,0x3c,0x3c,0x3c,
0x3d,0x3d,0x3d,0x3d,
0x3e,0x3e,0x3e,0x3e,
0x3f,0x3f,0x1f,0x1f
};
unsigned char code LS86[4][4]={
0x24,0x24,0x00,0x00, //74ls86
0x36,0x36,0x36,0x36,
0x2d,0x2d,0x2d,0x2d,
0x3f,0x3f,0x1b,0x1b
};
unsigned char code IC[M][N]={
0x24,0x24,0x24,0x24,0x3f,0x3f,0x1b,0x1b, //7400
0x3f,0x3f,0x15,0x15,0x3f,0x3f,0x15,0x15, //7404
0x3f,0x3f,0x1f,0x1f,0x3f,0x3f,0x1f,0x1f, //7420
0x3f,0x3f,0x1b,0x1b,0x3f,0x3f,0x1b,0x1b//7486
};
void delayms(unsigned int z)//延时函数
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/*=======================14脚芯片识别函数=====================*/
unsigned char detect(void) //14脚芯片识别函数
{
unsigned char i,output1,output2;
//7474的检测
 1=0xff; //初始化测试端口
 2=0xff;
input1=0x3b;
input2=0x39;
delayms(100);
input1=0x3f; //上升沿
input2=0x3d;
delayms(100);
output1=input1&0x3f;
output2=input2&0x3f;
if(output1==0x1f&&output2==0x2d)
{
return (4);
}
//7400/04/20/86的自动检测
P1=0xff; //初始化测试端口
P2=0xff;
for(i=0;i<M;i++)
{
input1=IC[0];
input2=IC[1];
delayms(500);
output1=input1&0x3f; //将芯片逻辑结果input1通过&0x3f取出
output2=input2&0x3f;
if(output1==IC[2]&&output2==IC[3])
{
input1=IC[4];
input2=IC[5];
delayms(500);
output1=input1&0x3f;
output2=input2&0x3f;
if(output1==IC[6]&&output2==IC[7])
{
return(i);
}
}
}
}
void display(uint namex)//数码管显示子程序
{
uchar qian,bai,shi,ge;
qian = namex/1000;//千位,把一个4位数分离后分别送数码管显示
bai = namex%1000/100;//百位
shi = namex%100/10;//十位
ge = namex%10;//个位
dula1 = 1;
P0 = table[qian];//送段选数据
dula1 = 0;
P0 = 0xff;//送位选数据前关闭所有显示
delayms(500);//延时500ms
dula2 = 1;
P0 = table[bai];
dula2 = 0;
P0 = 0xff;
delayms(500);
dula3 = 1;
P0 = table[shi];
dula3 = 0;
P0 = 0xff;
delayms(500);
dula4 = 1;
 0 = table[ge];
dula4 = 0;
 0 = 0xff;
delayms(500);
 0 = 0xff;
wela = 1;
 0 = 0xc0;
wela =0;
while(1)
{
if(key1==0) break;
if(key2==0) break;
}
}
int reset(void)//数码管和发光led初始化
{
ledR = 1; //led初始化,都熄灭
ledG = 1;
wela = 1;//数码管初始化,显示为0000
P0 = 0xc0;
wela = 0;
dula1 =1;
dula2 =1;
dula3 =1;
dula4 =1;
P0 = table[0];
dula1 = 0;
dula2 = 0;
dula3 = 0;
dula4 = 0;
}
void keyscan(void) //键盘扫描函数
{ int i;
unsigned char output1,output2;
if(key1==0)//按键1的子程序
{
delayms(10);
if(key1==0)
{
while(key1==0);//等待按键释放
k=detect();
display(name[k]);
}
}
if(key2==0)//按键2的子程序
{
delayms(10);
if(key2==0)
{
while(key2==0);//等待按键释放
ledR = 1;//灭绿led灯
ledG = 1;//灭红led灯
display(0);//数码管显示为0000
}
}
if(key3==0)//按键3的子程序
{
delayms(10);
if(key3==0)
{
while(key3==0);//等待按键释放
k=detect(); //调用检测芯片型号子程序
delayms(100);
if(k==0)//检测芯片好坏
{
for(i=0;i<4;i++)
{
input1=LS00[0];
input2=LS00[1];
delayms(500);
output1=input1&0x3f;
output2=input2&0x3f;
if(output1!=LS00[2]||output2!=LS00[3])
{
ledR= 0;
time=0;
break;
}
if(output1==LS00[2]&&output2==LS00[3])
{
time++;
}
}
if(time==4)
{
ledG = 0;
display(name[0]);
time=0;
}
}
if(k==1)
{
for(i=0;i<2;i++)
{
input1=LS04[0];
input2=LS04[1];
delayms(500);
output1=input1&0x3f;
output2=input2&0x3f;
if(output1!=LS04[2]||output2!=LS04[3])
{
ledR = 0;
time=0;
break;
}
if(output1==LS04[2]&&output2==LS04[3])
{
time++;
}
}
if(time==2)
{
ledG = 0;
time=0;
}
}
if(k==2)
{
for(i=0;i<16;i++)
{
input1=LS20[0];
input2=LS20[1];
delayms(500);
output1=input1&0x3f;
output2=input2&0x3f;
if(output1!=LS20[2]||output2!=LS20[3])
{
ledR = 0;//点亮红led
time=0;
break;
}
if(output1==LS20[2]&&output2==LS20[3])
{
time++;
}
}
if(time==16)
{
ledG = 0;//点亮绿led
display(name[k]);//显示芯片型号
time=0;
}
}
if(k==4)
{
for(i=0;i<4;i++)
{
input1=LS86[0];
input2=LS86[1];
delayms(500);
output1=input1&0x3f;
output2=input2&0x3f;
if(output1!=LS86[2]||output2!=LS86[3])
{
ledR = 0;
time=0;
break;
}
if(output1==LS86[2]&&output2==LS86[3])
{
time++;
}
if(time==4)
{
ledG = 0;
display(name[k]);
time=0;
}
}
}
}
}
}
int main()//主程序
{
reset();//初始化
while(1)//不停扫按键
{
keyscan();
}
return 0;//结束程序
}中的
unsigned char code LS00[4][4]={
0x3f,0x3f,0x1b,0x1b, //74ls00
0x24,0x24,0x24,0x24,
0x36,0x36,0x36,0x36,
0x2d,0x2d,0x2d,0x2d
};
unsigned char code LS04[2][4]={
0x2a,0x2a,0x2a,0x2a, //74ls04
0x3f,0x3f,0x15,0x15
};
unsigned char code LS20[16][4]={
0x24,0x24,0x24,0x24, //74ls20
0x25,0x25,0x25,0x25,
0x26,0x26,0x26,0x26,
0x27,0x27,0x27,0x27,
0x2c,0x2c,0x2c,0x2c,
0x2d,0x2d,0x2d,0x2d,
0x2e,0x2e,0x2e,0x2e,
0x2f,0x2f,0x2f,0x2f,
0x34,0x34,0x34,0x34,
0x35,0x35,0x35,0x35,
0x36,0x36,0x36,0x36,
0x37,0x37,0x37,0x37,
0x3c,0x3c,0x3c,0x3c,
0x3d,0x3d,0x3d,0x3d,
0x3e,0x3e,0x3e,0x3e,
0x3f,0x3f,0x1f,0x1f
};
unsigned char code LS86[4][4]={
0x24,0x24,0x00,0x00, //74ls86
0x36,0x36,0x36,0x36,
0x2d,0x2d,0x2d,0x2d,
0x3f,0x3f,0x1b,0x1b
};
unsigned char code IC[M][N]={
0x24,0x24,0x24,0x24,0x3f,0x3f,0x1b,0x1b, //7400
0x3f,0x3f,0x15,0x15,0x3f,0x3f,0x15,0x15, //7404
0x3f,0x3f,0x1f,0x1f,0x3f,0x3f,0x1f,0x1f, //7420
0x3f,0x3f,0x1b,0x1b,0x3f,0x3f,0x1b,0x1b//7486
};
void delayms(unsigned int z)//延时函数
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/*=======================14脚芯片识别函数=====================*/
unsigned char detect(void) //14脚芯片识别函数
{
unsigned char i,output1,output2;
//7474的检测
 1=0xff; //初始化测试端口
 2=0xff;
input1=0x3b;
input2=0x39;
delayms(100);
input1=0x3f; //上升沿
input2=0x3d;
delayms(100);
output1=input1&0x3f;
output2=input2&0x3f;
if(output1==0x1f&&output2==0x2d)
{
return (4);
}
//7400/04/20/86的自动检测
P1=0xff; //初始化测试端口
P2=0xff;
for(i=0;i<M;i++)
{
input1=IC[0];
input2=IC[1];
delayms(500);
output1=input1&0x3f; //将芯片逻辑结果input1通过&0x3f取出
output2=input2&0x3f;
if(output1==IC[2]&&output2==IC[3])
{
input1=IC[4];
input2=IC[5];
delayms(500);
output1=input1&0x3f;
output2=input2&0x3f;
if(output1==IC[6]&&output2==IC[7])
{
return(i);
}
}
}
}
上面数组是怎么得来的,求分析unsigned char detect(void)函数,越详细越好,谢谢!
|