wzhn
Newbie level 2
- Joined
- Jun 4, 2013
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,298
Hi,
I'm very (VERY) new to programming. Currently, I am learning the ADC module for the PC16F887 and what I'm attempting to do is as follow:
Receive TWO analog inputs on the input ports, put them through ADC conversion, compare them by a simple logic and then output a HIGH on any of the pre-determined output ports.
Like any beginner, I tried with the ADC library example first and then modify the codes to play with it as I learn. Tried searching for beginner level programming but just couldn't find an appropriate one. Helpful feedbacks are much appreciated.
attached: is my simulation circuit
I'm very (VERY) new to programming. Currently, I am learning the ADC module for the PC16F887 and what I'm attempting to do is as follow:
Receive TWO analog inputs on the input ports, put them through ADC conversion, compare them by a simple logic and then output a HIGH on any of the pre-determined output ports.
Like any beginner, I tried with the ADC library example first and then modify the codes to play with it as I learn. Tried searching for beginner level programming but just couldn't find an appropriate one. Helpful feedbacks are much appreciated.
unsigned int volt_1, volt_2;
void main()
{
ANSEL = 0x06; // Configure AN2 and AN1 pin as analog
ANSELH = 0; // Configure other AN pins as digital I/O
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISA = 0xFF; // PORTA is input
TRISB = 0x00; // PORTB is output
TRISC = 0x00; // PORTC is output
do
{
volt_1 = ADC_Read(1); // Get 10-bit results of AD conversion
volt_2 = ADC_Read(2);
if (volt_1 > volt_2)
{
PORTC = 0xFF;
delay_ms(500);
}
else
{
PORTB = 0xFF;
delay_ms(500);
}
}
while(1);
}
attached: is my simulation circuit