peterzatko
Joined: 20 Jun 2014 Posts: 14
|
ADC pic 12f683 |
Posted: Sat Jun 21, 2014 3:57 am |
|
|
Please help i´m begginner in c
i need use 10 bit adc i have ccs c version 5.0.17
My problem is maybe in adc because if i give on pin AN3 voltage 0,1 to 5V output is allways to low but if i give 0V to AN3 output is high.
I need this:
IF i have on AN3 - 0 - 2,5 V output is low and 2,55-5V i need output high.
I need use "r" because with "r" i need change delay later.
My Code:
#include <abs-c.h>
#include <stdio.h>
#use delay(clock=4000000)
#fuses HS,INTRC_IO,NOWDT, NOPUT, NOMCLR, NOBROWNOUT
#byte TRISIO = 0b00010000 // GP4 is an input (GP4 = AN3 for pic12f683)
#byte GPIO = 0x00 // set GPIO to low outputs
#byte ANSEL = 0b01111000 // ANS3 as analog input, Frc (internal clk )
#byte ADCON0 = 0b10001101 //right justified, vdd, -, -, 11=an3, 0=done, 0=adon on
#byte ADON=1 // turn on the A2D conversion module
#byte CMCON = 7 //Turn off comparator
void main()
{
int16 r;
setup_adc_ports(sAN3);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(3);
delay_ms(10);
while (True)
{
r = read_adc();
If (r >=500) {
output_low(PIN_A0);}
else if(r < 500)
{output_high (PIN_A0);}
delay_ms(10);
}
} |
|