|
void main(void)
{
LCD_ON;
P0M0 = 0x80; P0M1 = 0;
P1M0 = 0; P1M1 = 0;
P2M0 = 0; P2M1 = 0;
P3M0 = 0; P3M1 = 0;
P4M0 = 0x20; P4M1 = 0;
P5M0 = 0; P5M1 = 0;
Delay_ms(100);
Zero_Coeff_Init();
lcd_system_reset();
ads_initial();
Delay_ms(100);
string_write(0, 0, " Welcome to use ");
string_write(0, 1, " ");
Delay_ms(3500);
string_write(0, 0, "Range:10mV ");
string_write(0, 1, "Volt:0.000mVDC ");
ads_convert();
while (1)
{
Delay_ms(100);
//熄屏省電判斷
if(++power_saving_timer > 299){//30秒熄屏
LCD_OFF;
}
//定時(shí)數(shù)據(jù)采集
if(++data_acqui_timer > 1){//100ms采集一次
if(current_ch < 4){//自動換擋
if((volt_val > 9900)&&(current_ch < 3)){
current_ch++;
Input_CH_Select();
}else if((volt_val < 10)&&(current_ch > 1)){
current_ch--;//
Input_CH_Select();
}
}
if(current_ch < 4||current_ch < 7){//自動換擋
if((volt_val > 9000)&&(current_ch < 6)){//
current_ch++;
Input_CH_Select();
}else if((volt_val < 100)&&(current_ch > 4)){//5
current_ch--;//
Input_CH_Select();
}
else if (volt_val < 20){
current_ch=6;
Input_CH_Select();
}
}
if(current_ch==4){
P07L=0;
Delay_ms(30);
}
if(current_ch==5){
P07L=1;
Delay_ms(30);
}
data_acqui_timer = 0;
//等待AD采集結(jié)束
while(1){
ad_val = ads_result();
if((ads_config_reg & 0x80) == 0)break;
}
volt_val = (ad_val - zero_val[current_ch - 1].sint_val)/coeff[current_ch - 1].float_val;
if(volt_val > 9999)volt_val = 9999;
if(volt_val < 0)volt_val = volt_val * -1;
Disp_Volt_Val();
ads_convert();//開啟下一次采集
}
if((volt_val > 9000)&&(current_ch < 6)){//
current_ch++;
Input_CH_Select();
}else if((volt_val < 100)&&(current_ch > 4)){//5
current_ch--;//
Input_CH_Select();
}
else if (volt_val < 20){
current_ch=6;
Input_CH_Select();
}
}這段程序沒測量時(shí)一直4 5 6通道變換,有沒有大佬講一下如何在內(nèi)有測量時(shí)保持在6通道。
|
|