hi i am new to this forum and i am having trouble trying to get my microcontroller to read my analog signal from AN1 after finishing reading from AN0.
i am using PIC184550.
i am using PIC184550.
Rich (BB code):
T0CON=0b00000111; //Off Timer0, 16-bits mode, prescaler to 256
T2CON=0b00000111; //Timer2 is On, Prescaler is 16
CCP1CON=0b00001100; //Turn on PWM on CCP1, output at RC2
CCP2CON=0b00001100; //Turn on PWM on CCP2
PR2 = 149; //Load period of PWM 0.2msec for 5KHz
TRISA=0xFF;
TRISCbits.TRISC1 = 0; // RC1 as output pin
PORTCbits.RC1 = 0; // RC1 is connected to Relay
TRISCbits.TRISC2 = 0; // RC2 as output pin
PORTCbits.RC2 = 0; // RC2 is connected to Motor
ADCON0 = 0b00000001;
ADCON1 = 0b00001101;
ADCON2 = 0b00000111;
while(1)
{
ADCON0 = 0b00000001; //select channel 0 AN0
ADCON2 = 0b00000111;
ADCON0bits.GO = 1; // START CONVERSION NOW
while(ADCON0bits.GO == 1); // Waiting for DONE
{}
result1=ADRESH;
if(result1>0b10001001)
{
CCP1CON=0b00001100;
CCPR1L = 0b11100000;
CCP1CONbits.DC1B1=1;
CCP1CONbits.DC1B0=0;
Delay1sec();
}
else
{
CCP1CON=0b00000000;
CCPR1L = 0b00000000;
CCP1CONbits.DC1B1=1;
CCP1CONbits.DC1B0=0;
Delay1sec();
}
ADCON0 = 0b00010001; //select channel 1 AN1
ADCON2 = 0b00100111;
ADCON0bits.GO = 1; // START CONVERSION NOW
while(ADCON0bits.GO == 1); // Waiting for DONE
{}
PORTD=ADRESH;
result=ADRESH;
if(result>0b10001001)
{
CCP2CON=0b00001100;
CCPR2L = 0b11100000;
CCP2CONbits.DC2B1=1;
CCP2CONbits.DC2B0=0;
Delay1sec();
}
else
{
CCP2CON=0b00000000;
CCPR2L = 0b00000000;
CCP2CONbits.DC2B1=0;
CCP2CONbits.DC2B0=0;
Delay1sec();
}
}