用电涡流传感器+51单片机来实现的金属检测原件清单:
同厚金属板材质分辨的proteus仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include <STC15F2K60S2.H>
- #include <ADC.h>
- #include <math.h>
- #define IRON 93
- #define COPPER 86
- #define ALUM 84
- sbit get_init=P0^0;
- sbit switch_mode=P0^1;
- sbit resolution=P0^2;
- //数码管变量区
- unsigned char code Table[]={
- 0x3f,0x06,0x5b,0x4f,
- 0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,
- 0x39,0x5e,0x79,0x71};
- unsigned char code Wei_Table[]={
- 0xef,0xdf,0xbf,0x7f};
- unsigned char Screen_Table[4],wei;
- unsigned char number=0; //物质编号
- unsigned char standard,current,texture;
- void Delay50ms() //@11.0592MHz
- {
- unsigned char i, j, k;
- _nop_();
- _nop_();
- i = 3;
- j = 26;
- k = 223;
- do
- {
- do
- {
- while (--k);
- } while (--j);
- } while (--i);
- }
- void Timer0Init(void) //2毫秒@11.0592MHz
- {
- AUXR &= 0x7F; //定时器时钟12T模式
- TMOD &= 0xF0; //设置定时器模式
- TL0 = 0xCD; //设置定时初值
- TH0 = 0xF8; //设置定时初值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- ET0 = 1;
- EA = 1;
- }
- void main()
- {
- ADC_Init();
- Timer0Init();
- Screen_Table[0]=0;
- P2M1=0x00;
- P2M0=0xff;
- while(1)
- {
- if(get_init==0) //获取无介质时初始值
- {
- standard=GetADC(0);
- P31=0; //获取成功标志
- }
- if(resolution==0) //获取介质值并运算
- {
- current=GetADC(0);
- texture=(unsigned char)(((float)current*100/standard));
- if(texture>90)
- Screen_Table[1]=Screen_Table[0];
- else if(texture>85)
- Screen_Table[2]=Screen_Table[0];
- else if(texture>80)
- Screen_Table[3]=Screen_Table[0];
- }
- if(switch_mode==0) //设置被检测物体编号
- {
- Delay50ms();
- if(switch_mode==0)
- {
- Screen_Table[0]=number;
- number++;
- if(number==4)
- number=0;
- while(switch_mode==0);
- Delay50ms();
- while(switch_mode==0);
- }
- }
- }
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
金属材质检测-.zip
(93.16 KB, 下载次数: 96)
|