jcmast
Joined: 17 Sep 2005 Posts: 1
|
help with a/d |
Posted: Sat Sep 17, 2005 11:33 am |
|
|
Hello,
I am a volunteering in my school's lab. I am programming a project to control some motors.
To get myself aquainted to a PIC and its internal a/d converter I wrote this simple program. However, I cannot seem to get it to operate correctly. All I am having it do is output high until it receives a certain input on the a/d. Any suggestions?
#include <16F873.h>
#device adc=8
#use delay(clock=4000000)
#fuses XT, PUT, NOWDT, NOPROTECT, NOLVP
void main()
{
int input;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
setup_spi(FALSE);
setup_counters(RTCC_EXT_L_TO_H,WDT_18MS);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
input = 0;
output_high(PIN_B0);
while(1)
{
delay_ms(500);
input = read_adc();
if(input >= 20)
{
output_low(PIN_B0);
}
}
} _________________ hi, im new |
|