boyguitar1
Member level 1
Hello...Sir
Could you please help check my code as below ?
I use PIC16F737 (28pins)
I just want to read ADC by 4 channels (RA0,RA1,RA2,RA3)
RA0 for 1 ~ 1.5 vdc
RA1 for 2 ~ 2.5 vdc
RA2 for 3 ~ 3.5 vdc
RA3 for 4 ~ 4.5 vdc
if RA0 can read at 1 ~ 1.5 vdc then LED1 on [PORTB.F0]
if RA1 can read at 2 ~ 2.5 vdc then LED2 on [PORTB.F1]
if RA2 can read at 3 ~ 2.5 vdc then LED3 on [PORTB.F2]
if RA3 can read at 4 ~ 2.5 vdc then LED4 on [PORTB.F3]
2 day ago..it still does not work.
--------------------------------------------------------------
Please help advice me too...:-(
Thank you in advance...
Could you please help check my code as below ?
I use PIC16F737 (28pins)
I just want to read ADC by 4 channels (RA0,RA1,RA2,RA3)
RA0 for 1 ~ 1.5 vdc
RA1 for 2 ~ 2.5 vdc
RA2 for 3 ~ 3.5 vdc
RA3 for 4 ~ 4.5 vdc
if RA0 can read at 1 ~ 1.5 vdc then LED1 on [PORTB.F0]
if RA1 can read at 2 ~ 2.5 vdc then LED2 on [PORTB.F1]
if RA2 can read at 3 ~ 2.5 vdc then LED3 on [PORTB.F2]
if RA3 can read at 4 ~ 2.5 vdc then LED4 on [PORTB.F3]
2 day ago..it still does not work.
--------------------------------------------------------------
Please help advice me too...:-(
Thank you in advance...
Code:
// PIC16F737
// Clock 4 MHZ
long analog_val;
long analog_val2;
long analog_val3;
long analog_val4;
int i=0;
void main()
{
TRISB = 0B00000000; // Set PORTC as output
ADCON1 = 0x87; // Configure analog
TRISA = 0xFF; // Set PORTA as Input
PORTB = 0B00000000; // Clear PORTB
while (1)
{
analog_val = Adc_Read(0); //
Delay_ms(10);
analog_val = ((analog_val*2000)/2046);
if (analog_val >= 180 && analog_val <= 380){portb.f0=1;}
else { portb.f0 =0;}
/******************************************************************/
analog_val2 = Adc_Read(1);
Delay_ms(10);
analog_val2 = ((analog_val2*2000)/2046);
if (analog_val2 >= 380 && analog_val2 <=580){portb.f1=1;}
else { portb.f1 =0;}
/******************************************************************/
analog_val3 = Adc_Read(2);
Delay_ms(10);
analog_val3 = ((analog_val3*2000)/2046);
if(analog_val3 >= 580 && analog_val3 <= 780){portb.f2=1;}
else { portb.f2 =0;}
/******************************************************************/
analog_val4 = Adc_Read(3);
Delay_ms(10);
analog_val4 = ((analog_val4*2000)/2046);
if(analog_val4 >= 780 && analog_val4 < 1023) {portb.f3=1;}
else { portb.f3 =0;}
}
}