我使用RBO和Rb1连接到10K锅。我想看到价值的变化。我的代码看起来像下面我看不到变化是价值
以上来自于百度翻译
以下为原文
i m using RBO & Rb1 connected to 10k pot. I would like to see change in value.
my code look like below i cant see change is value
unsigned int curr1;
float curr[27] = 0;
bit select = 0,Auto_flag = 0, curr1_min=0, curr2_min=0, curr3_min=0, curr4_min=0, curr5_min=0, curr6_min=0, curr7_min=0, curr8_min=0, curr9_min=0, curr10_min=0;
void PIN_MANAGER_Initialize(void) {
/**
LATx registers
*/
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
/**
TRISx registers
*/
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x80;
/**
ANSELx registers
*/
ANSELC = 0x00;
ANSELB = 0x3F;
ANSELA = 0x00;
/**
WPUx registers
*/
WPUE = 0x00;
WPUB = 0x00;
WPUA = 0x00;
WPUC = 0x00;
/**
ODx registers
*/
ODCONA = 0x00;
ODCONB = 0x00;
ODCONC = 0x00;
bool state = (unsigned char)GIE;
GIE = 0;
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 0x00; // unlock PPS
RC6PPS = 0x09; //RC6->EUSART:TX;
RXPPSbits.RXPPS = 0x17; //RC7->EUSART:RX;
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 0x01; // lock PPS
GIE = state;
}
float Adc12_Cha(unsigned char val) {
unsigned char adc_hbit,adc_lbit;
unsigned long adc_temp,adc_temp0,adc_val;
ADCON2=0x95; //ADFM=1,adc_clk=FOSC/4
adc_temp0=0;
for(unsigned char j=0; j<10; j++) {
ADCON0=val<<2;
ADON=1;
__delay_ms(5);
GODONE =1;
while(GODONE==1);
adc_hbit=ADRESH;
adc_lbit=ADRESL;
adc_temp = adc_lbit + (256*adc_hbit);
adc_temp0+=adc_temp;
}
adc_val=adc_temp0/10;
return adc_val;
}
void ADC_Manipulation() {
curr1 = (int)(curr[0]);
if ((curr1<=102) ||(curr1>=502 && curr1<=514)||(curr1>=922)) {
curr1=0;
curr1_min=0;
} else if (curr1>514) {
if((curr1>514)||(curr1<540)) curr1= (((curr1-512)*74)/100);
else curr1=(((curr1-512)*74)/100);
curr1_min=0;
} else {
if((curr1>102)||(curr1<150)) curr1= (((511-curr1)*74)/100);
else curr1=(((510-curr1)*74)/100);
// curr1_min=1;
}
}
void main(void) {
while (1)
{
curr[0] = Adc12_Cha(10);
ADC_Manipulation();
__delay_ms(100);
}
}
我使用RBO和Rb1连接到10K锅。我想看到价值的变化。我的代码看起来像下面我看不到变化是价值
以上来自于百度翻译
以下为原文
i m using RBO & Rb1 connected to 10k pot. I would like to see change in value.
my code look like below i cant see change is value
unsigned int curr1;
float curr[27] = 0;
bit select = 0,Auto_flag = 0, curr1_min=0, curr2_min=0, curr3_min=0, curr4_min=0, curr5_min=0, curr6_min=0, curr7_min=0, curr8_min=0, curr9_min=0, curr10_min=0;
void PIN_MANAGER_Initialize(void) {
/**
LATx registers
*/
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
/**
TRISx registers
*/
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x80;
/**
ANSELx registers
*/
ANSELC = 0x00;
ANSELB = 0x3F;
ANSELA = 0x00;
/**
WPUx registers
*/
WPUE = 0x00;
WPUB = 0x00;
WPUA = 0x00;
WPUC = 0x00;
/**
ODx registers
*/
ODCONA = 0x00;
ODCONB = 0x00;
ODCONC = 0x00;
bool state = (unsigned char)GIE;
GIE = 0;
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 0x00; // unlock PPS
RC6PPS = 0x09; //RC6->EUSART:TX;
RXPPSbits.RXPPS = 0x17; //RC7->EUSART:RX;
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 0x01; // lock PPS
GIE = state;
}
float Adc12_Cha(unsigned char val) {
unsigned char adc_hbit,adc_lbit;
unsigned long adc_temp,adc_temp0,adc_val;
ADCON2=0x95; //ADFM=1,adc_clk=FOSC/4
adc_temp0=0;
for(unsigned char j=0; j<10; j++) {
ADCON0=val<<2;
ADON=1;
__delay_ms(5);
GODONE =1;
while(GODONE==1);
adc_hbit=ADRESH;
adc_lbit=ADRESL;
adc_temp = adc_lbit + (256*adc_hbit);
adc_temp0+=adc_temp;
}
adc_val=adc_temp0/10;
return adc_val;
}
void ADC_Manipulation() {
curr1 = (int)(curr[0]);
if ((curr1<=102) ||(curr1>=502 && curr1<=514)||(curr1>=922)) {
curr1=0;
curr1_min=0;
} else if (curr1>514) {
if((curr1>514)||(curr1<540)) curr1= (((curr1-512)*74)/100);
else curr1=(((curr1-512)*74)/100);
curr1_min=0;
} else {
if((curr1>102)||(curr1<150)) curr1= (((511-curr1)*74)/100);
else curr1=(((510-curr1)*74)/100);
// curr1_min=1;
}
}
void main(void) {
while (1)
{
curr[0] = Adc12_Cha(10);
ADC_Manipulation();
__delay_ms(100);
}
}
举报