abmoncivais
Newbie level 2
- Joined
- Dec 17, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Location
- Victoria de Durango, Mexico
- Activity points
- 18
Hi, i hope that someone can help me with a basic ADC program.
I'm trying to read 3 analogic pins in the portA, then the program have to compare the 3 inputs, and turn on a pin in the PORTB.
The action is for the lowest value in the portA
The program just turns on random leds in the portB
I'm using CCS and proteus, PIC16F877
#include <16F877A.h>
#device adc=10
#FUSES XT, NOWDT, NOPROTECT, PUT
#use delay (clock=4000000)
#BYTE TRISA=0X85
#BYTE PORTA=0X05
#BYTE PORTB=0X06
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_tris_b(0x00);
set_tris_a(0xFF);
while(1)
{
int16 x;
int16 y;
int16 z;
delay_ms(100);
set_adc_channel(0);
delay_ms(100);
x=read_adc();
delay_ms(100);
set_adc_channel(1);
delay_ms(100);
y=read_adc();
delay_ms(100);
set_adc_channel(3);
delay_ms(100);
z=read_adc();
delay_ms(100);
if (((x<y) && (x<z)))
{
PORTB=0b10000000;
delay_ms(100);
}
else
{
if (((y<x) && (y<z)))
{
PORTB=0b01000000;
delay_ms(100);
}
else
{
if(((z<x) && (z<y)))
{
PORTB=0b00100000;
delay_ms(100);
}
}
}
delay_ms(100);
}
}
I'm trying to read 3 analogic pins in the portA, then the program have to compare the 3 inputs, and turn on a pin in the PORTB.
The action is for the lowest value in the portA
The program just turns on random leds in the portB
I'm using CCS and proteus, PIC16F877
#include <16F877A.h>
#device adc=10
#FUSES XT, NOWDT, NOPROTECT, PUT
#use delay (clock=4000000)
#BYTE TRISA=0X85
#BYTE PORTA=0X05
#BYTE PORTB=0X06
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_tris_b(0x00);
set_tris_a(0xFF);
while(1)
{
int16 x;
int16 y;
int16 z;
delay_ms(100);
set_adc_channel(0);
delay_ms(100);
x=read_adc();
delay_ms(100);
set_adc_channel(1);
delay_ms(100);
y=read_adc();
delay_ms(100);
set_adc_channel(3);
delay_ms(100);
z=read_adc();
delay_ms(100);
if (((x<y) && (x<z)))
{
PORTB=0b10000000;
delay_ms(100);
}
else
{
if (((y<x) && (y<z)))
{
PORTB=0b01000000;
delay_ms(100);
}
else
{
if(((z<x) && (z<y)))
{
PORTB=0b00100000;
delay_ms(100);
}
}
}
delay_ms(100);
}
}