This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ADC for windshield wiper, Error C67: Sensor_value undefined identifier

Hey guys hows it going
Im working on a programming assignment where we have to write a program to control windshield wipers, and im having some trouble compiling it. The code seems fine to me, but in the main.c file, it keeps bringing up this error about sensor_value being an undefined identifier. Can you guys help me out? Here is the code:

/****************/
/* MAIN PROGRAM */
/****************/

#include <reg167.h> /* special function registers of the C167 */
#include <stdio.h> /* Standard input/output header file */
#include "adc.h" /* ADC Header File */
#include "pwm.h" /* PWM Header File */
#include "timer.h" /* Timer Header Files */

/* Main Program */
void main(void) {

/* initialize serial interface, 9600 bps, 8-N-1 */
DP3 |= 0x0400; /* PORT 3.10 DIRECTION CONTROL: OUTPUT (TXD) */
DP3 &= ~0x0800; /* PORT 3.11 DIRECTION CONTROL: INPUT (RXD) */
P3 |= 0x0400; /* PORT 3.10 DATA: HIGH (LINE IDLE) */
S0TIC = 0x80; /* SET TRANSMIT INTERRUPT FLAG (TX COMPLETE) */
S0RIC = 0x00; /* CLEAR RECEIVE INTERRUPT FLAG (NOTHING REC.) */
S0BG = 0x40; /* SET BAUDRATE TO 9600 BAUD */
S0CON = 0x8011; /* SET SERIAL MODE */

/* Initialise ADC */
ADC_init();

/* initialise PWM */
PWM_init();

/* Initialise Timer */
Timer_init();

/* Allow interrupts */
IEN=1;

/* Wait for a sweep cycle to end, to avoid starting a new cycle when one is already running */
while (T3 > 0){}

/* Control the wiper motor, depending on return ADC result */
while(1) {

/* load return ADC value into sensor voltage */
float sensor_value = ADC_read()

/* Outputs for various states */
if (sensor_value > 4.5) { PWM_set(1.0); /* Sets the Off-Phase to 100% of the pulse width */ PTR3=0; /* Resets PWM */ T3R=0; /* Sets the timer off */ printf("No Rain Detected!\n"); }

else if (sensor_value <= 4.5 && sensor_value >=1.5) { PWM_set(0.5); /* Sets the Off-Phase to half of the pulse width */ PTR3=1; /* Starts PWM */ T3=0x9860; /* Loads timer value of 2 sec (Prescale value 1024) */ T2=0x960; /* Loads auxiliary timer with 2 seconds */ T3R=1; /* Starts the timer */ printf("Few Showers Detected!\n");

while (T3>0) {} /* Wait for Sweep cycle to cmplete */ PWM_set(1); /* Sets the duty cycle to zero */ T3=(1.67*sensor_value)-2.5; /* Loads a delay timer value proportional to the sensor value */

T2=(1.67*sensor_value)-2.5; /* Loads the auxiliary timer with same value */ T3R=1; /* Starts the timer */ }
else if (sensor_value < 1.5) { PWM_set(0); /* Sets the Off-Phase of the pulse width to zero */ PTR3 =1; /* Starts PWM */ T3=0x4C30; /* timer value of 1 second (Prescale factor of 1024) */ T2=0x4C30; /* Loads the auxiliary timer with 1 second */ T3R =1; /* Starts the timer */ printf("Heavy Rain Detected!\n"); } } }

0