bing2005
Junior Member level 2
How to select multiple channel by using PIC microcontroller?
Everytimes, i try with more than 1 channel, the output will always jump around.
I used PICC to write the source code. Please help me.
Thank you, guys.
The following source code is 2 channels adc:
[/code]
Everytimes, i try with more than 1 channel, the output will always jump around.
I used PICC to write the source code. Please help me.
Thank you, guys.
The following source code is 2 channels adc:
Code:
#include <pic.h>
#include "delay.c"
#include "delay.h"
void init_adc(void);
void select1(void);
void select2(void);
void output1(void);
void output2(void);
unsigned int result, result1, temp, temp1;
void config(void)
{
TRISA = 0x2f;
TRISB = 0x00;
PORTA = 0x00;
PORTB = 0x00;
}
void main(void)
{
config();
init_adc();
while(1)
{
select1();
temp = 0x00;
DelayUs(10);
select2();
temp1 = 0x00;
DelayUs(10);
}
}
void init_adc(void)
{
ADCON1 = 0x80;
}
void select1(void)
{
ADCON0 = 0x01;
DelayUs(20);
ADGO = 1;
while(ADGO);
result = ((ADRESH << 8) + ADRESL) & 0x03FF;
temp = result;
if(result>=925 && result<=930)
{
output1();
}
}
void select2(void)
{
ADCON0 = 0x09;
DelayUs(20);
ADGO = 1;
while(ADGO);
result1 = ((ADRESH << 8) + ADRESL) & 0x03FF;
temp1 = result1;
if(result1>=925 && result1<=930)
{
output2();
}
}
void output1(void)
{
RB7 = 1;
}
void output2(void)
{
RB6 = 1;
}