Not your question, but:
Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
#if defined(__PCM__)#include <16F877A.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay(clock = 16000000)
#use rs232(baud = 9600, xmit = PIN_C6, rcv = PIN_C7)
#endif
#include <touch.c>
#include <string.h>
#include <stdlib.h>
void main(void) {
signed int direction;
int pwm;
float voltageold;
float powerold;
float measuredpower;
float measuredvoltage;
float measuredcurrent;
float deltav;
float deltap;
voltageold = 0;
powerold = 0;
pwm = 0x1F;
direction = 0.001;
setup_adc(ADC_CLOCK_DIV_32);
setup_adc_ports(ALL_ANALOG);
output_low(PIN_C1);
setup_ccp1(ccp_pwm);
setup_timer_2(T2_DIV_BY_1, 159, 1);
while (1) {
delay_ms(1000);
set_adc_channel(0);
delay_ms(20);
measuredvoltage = read_adc();
set_adc_channel(1);
delay_ms(20);
measuredcurrent = read_adc();
measuredpower = measuredvoltage * measuredcurrent;
deltav = measuredvoltage - voltageold;
deltap = measuredpower - powerold;
if (deltap == 0) {
pwm = pwm;
} else {
if (deltap > 0) {
if (deltav > 0) {
pwm--;
} else {
pwm++;
}
} else {
if (deltav < 0) {
pwm--;
} else {
pwm++;
}
}
}
voltageold = measuredvoltage;
powerold = measuredpower;
set_pwm1_duty(pwm);
}
}
Indentation style - Wikipedia[
^]
Best C++ Formatter and Beautifier[
^]
Online C/C++ Formatter, Indenter and Beautifier – Techie Delight[
^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[
^]
-----
Quote:
Undeclared identifier 'setup_adc' in expression p&o.c
The compiler tells you that it don't know what is
setup_adc
, your code never tells what it is.