完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include
#include #include /*==============================宏定义===================*/ #define M 4//要测试的芯片好坏的个数 #define N 8 #define input1 P1//用于检测的引脚 #define input2 P2 #define uchar unsigned char #define uint unsigned int ***it key1=P3^0; // 选择检测芯片型号 ***it key2=P3^1; // 复位 ***it key3=P3^2; // 自动检测 ***it ledR=P3^7;/*红色发光led接单片机P3.7 */ ***it ledG=P3^6;/*绿色放发光LED接单片机P3.6 */ ***it dula4=P2^6;//声明锁存器的锁存端 ***it dula1=P3^3; ***it dula2=P3^4; ***it dula3=P3^5; ***it 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 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 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)函数,越详细越好,谢谢! |
|
相关推荐
8个回答
|
|
测试什么芯片的?
|
|
|
|
1.根据芯片的真值表得来的.
2.初始化测试端口->将芯片的逻辑结果读出来->匹配真值表,不匹配换另一个真值表,匹配则修改端口电平->将芯片的逻辑结果读出来->还是与真值表匹配,输出芯片对应的序号. |
|
|
|
74系列的
|
|
|
|
|
|
74LS系列的
|
|
|
|
我上面的程序有错吗?仿真是都没成功。
|
|
|
|
能仿真就看看各个环节与芯片真值表是否对应,与程序读出来的值是否对应,与程序的真值表是否对应.
|
|
|
|
怎么确定那个引脚是输入还是输出呢
|
|
|
|
只有小组成员才能发言,加入小组>>
2970 浏览 9 评论
2687 浏览 16 评论
3212 浏览 1 评论
8426 浏览 16 评论
3770 浏览 18 评论
6950浏览 6评论
求助,请问MS51FB9AE带隙电压能作为侦测的基准电压吗?
7449浏览 3评论
6950浏览 3评论
支持UART-to-BLE透传的新唐NuTool – BLE ATCMD开发工具推荐
5798浏览 3评论
9370浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-4-20 17:47 , Processed in 0.875962 second(s), Total 81, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号