多路数据采集系统(Protues仿真)
{ v=v+10; if(v>50) v=1; break;
}
case 2://电压个位 { v++;
if(v>50) v=1; break; }
case 3://频率千位 { f=f+1000; if(f>2000) f=500; break; }
case 4://频率百位 { f=f+100;
if(f>1000) f=100; break; }
case 5://频率十位 { f=f+10; break;
}
case 6://频率个位 { f++; break;
}
}//switch }//if
if(key_sub==0)
16
多路数据采集系统(Protues仿真)
while(key_sub==0); switch(pos) {
case 1://电压十位 { v=v-10; if(v>50) v=1; break;
}
case 2://电压个位 { v--; if(v<0) v=1; break;
}
case 3://频率千位 { f=f-1000; if(f<0) f=500; break;
}
case 4://频率百位 { f=f-100; if(f<0) f=100; break;
}
case 5://频率十位 {
f=f-10;
break;
}
case 6://频率个位 { f--;
break;
17
{
多路数据采集系统(Protues仿真)
}
void lcd_show()//显示频率和电压 { uchar pos_tmp[2]={\ GotoXY(0,10);
Print(\pos_tmp[0]=pos+'0'; Print(pos_tmp); GotoXY(1,1); B_TEMP[1]=v/10+'0'; B_TEMP[3]=v+'0';
if(f>999) B_TEMP[7]=(f/1000)+'0'; else if(f>99)
B_TEMP[7]=' ';
}
}//switch }//if
if(key_move==0) { while(key_move==0); }
pos++;
if(pos>6) pos=1;
B_TEMP[8]=(f/100)+'0';else B_TEMP[7]=' ';
if(f>9) B_TEMP[9]=(f/10)+'0';else B_TEMP[7]=' '; B_TEMP[10]=f+'0'; Print(B_TEMP);
}
void g(int j)//从共享区读取数据进行AD转换 { int i,jj,j_tmp; j_tmp=j;
while((key_change & key_move) & (key_add & key_sub)) { jj=j_tmp; for(i=0;i<30;i++) { P0=tmp[i];
for(jj=0;jj void tran(void) //三角波 填充缓冲区 18 多路数据采集系统(Protues仿真) { uchar i,step,tmp1; step=5*v/15; lcd_show(); tmp1=0; for(i=0;i<15;i++) { tmp1=tmp1+step; tmp[i]=tmp1; } for(i=15;i<30;i++) { tmp1=tmp1-step; tmp[i]=tmp1; } g(1000/f); } void mysin( ) //正弦波 填充缓冲区{ uchar i; float step,tmp1; step=6.28/30; lcd_show(); tmp1=0; for(i=0;i<30;i++) { tmp1=tmp1+step; tmp[i]=2.5*v+2.5*v*sin(tmp1); } g(1000/f); } void square(void) //方波 填充缓冲区 { uchar i; lcd_show(); for(i=0;i<15;i++) tmp[i]=v*5; for(i=15;i<30;i++) tmp[i]=0; g(1000/f); } 19 多路数据采集系统(Protues仿真) 6.2.2数据采集器 #include\#include\#include \#include\ #define uchar unsigned char uchar B_TEMP[16]={\可变显示缓冲区 uchar V_TEMP[10]; int count=0; int F_count=0,Fre, v,f,v_max; void lcd_show(); void init(void); sbit STATUS = P3^0; unsigned char xdata CTRL _at_ 0x2FFF; unsigned char xdata ADSEL _at_ 0x4FFF; unsigned char hByte; unsigned char lByte; void adc_Convert (void)//AD转换程序 { int MSB , LSB,v_tmp; // Start a conversion with A0 and A/$C$ low. // The convesion takes place on rising CE edge. CTRL = 0x00; ADSEL = 0x00; // Wait until we have completed a conversion . while(STATUS==1); // Set R/$C$ with A0 low and read the low byte. CTRL = 0x02; hByte = ADSEL; // Set R/$C$ with A0 high and read the high. CTRL = 0x03; lByte = ADSEL; MSB=(unsigned int)(hByte << 4); LSB=(unsigned int)(lByte >> 4); // adc_Res now has the converted data with 12-bit resolution. v_tmp = 5*(MSB + LSB)/203; 20 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库计算机控制课设——多路数据采集系统的设计(4)在线全文阅读。
相关推荐: