This is a multi-part message in MIME format. ------=_NextPart_000_00D5_01C0DA1B.B4796280 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello Steve, I've took a look at your code and there's some things that seems strange to me: ////////////// #DEVICE ADC=10 ////////////// What this does? My version of CCS seens not to have this option. ////////////// set_adc_channel(0); delay_ms(100); dc_level = read_adc(); delay_ms(100); ////////////// I don't use this built-in functions of CCS. I preffer to write my own so I know exactly what they're doing. Anyway I don't see why this willn't work. Delays are longer than necessary, but not a problem. ////////////// if (dc_level < min) PORT_C=0x40; if (dc_level > max) PORT_C=0x80; ////////////// This also seens to be ok ////////////// if (min < dc_level < max) flag=0; else flag=1; ////////////// This construction (min < dc_level < max) seens very strange to me. I've never seen it and think this willn't work as you'd spect. ////////////// do { } while (flag=1); ////////////// The comparator operator is '==' and not '='. '=' is the assignment operator. So you have to use '(flag==1)'. Anyway, I prefer the construction: ////////////// while (flag == 1) { } ////////////// This is more compact and cleaner. Attached is your code with some alterations I've made. I would like if you try it. Best regards, Brusque ----------------------------------- Edson Brusque Research and Development C.I.Tronics Lighting Designers Ltda (47) 323-2138 / (47) 9993-6453 Blumenau - SC - Brazil www.citronics.com.br ----------------------------------- ------=_NextPart_000_00D5_01C0DA1B.B4796280 Content-Type: application/octet-stream; name="stev_acd.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="stev_acd.c" #include <16F873.H> #DEVICE ADC=10 #include #fuses HS, NOWDT, NOPROTECT, PUT, NOBROWNOUT //Tell compiler that clock is 20MHz for use in DELAY routines. #use DELAY(clock=20000000) #byte PORT_A=5 #byte PORT_B=6 #byte PORT_C=7 #use FAST_IO(B) #use FAST_IO(C) int flag; long dc_level, min, max; main() { disable_interrupts(GLOBAL); //Turn off ALL interrupts. SET_TRIS_A(0xFF); //Set PORTA to all INPUTS. SET_TRIS_B(0x00); //Set PORTB to all OUTPUTS. SET_TRIS_C(0x00); //Set PORTC to all OUTPUTS. min = 0x0474; //Lower threshold of desired output power. max = 0x0492; //Upper threshold of desired output power. setup_ccp1(CCP_OFF); setup_ccp2(CCP_OFF); setup_adc_ports( RA0_RA1_ANALOG_RA3_REF ); setup_adc( ADC_CLOCK_INTERNAL ); while (true) { DELAY_US(2); flag=1; while (flag == 1) { set_adc_channel(0); delay_ms(100); dc_level = read_adc(); delay_ms(100); if (dc_level < min) PORT_C=0x40; if (dc_level > max) PORT_C=0x80; if ((min < dc_level) && (dc_level < max)) flag=0; else flag=1; } } } ------=_NextPart_000_00D5_01C0DA1B.B4796280-- -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu