SAmPLe PROGRAm
This program calculates a one-hour average temperature. The array named “numbers” sets
up a series of variables from 0 to 60 to hold a value for input 0 for each minute in an hour.
The 60 values are totaled, then averaged. The average can then viewed from the C & Ladder
Variables form, stored in the datalogger, or displayed on the Real-time screen.
By using an array, the program becomes substantially more concise. The program is first listed,
then a section by section explanation on how the program works is provided.
float numbers[60];
/* array: input 0 value for each minute */
int x;
/* index to the array */
float total;
/* total of the input 0 values */
float average;
/* total/60 */
int oldminute;
/* minute counter */
main()
{
if (oldminute != minutes)
{
oldminute=minutes;
numbers[minutes] = read_uaf(input,0,0);
total = 0;
for (x=0;x<60;x=x+1)
{
total = total + numbers[x];
}
average = total/60;
}
}
The following is a step by step explanation of the program.
1)
if (oldminute != minutes)
{
oldminute=minutes;
This checks the value of minutes to see if a minute has passed. If a minute has passed, the
value of oldminute is reset to the value of the new minute.
2)
numbers[minutes] = read_uaf(input,0,0);
This line sets the value of the variable “numbers” for a particular minute to the current value of
input 0. For example,
It is 3 minutes into the hour.
The value of input 0 is 72.
Therefore,
numbers[minutes] = read_uaf(input,0,0);
is equal to
numbers[3] = 72
3)
total = 0;
This line initializes the variable “total” to zero.
16-11
Chapter 16: Programming in C
Содержание Sensaphone SCADA 3000
Страница 1: ...Sensaphone SCADA 3000 User s Manual Version 2 34...
Страница 6: ...vi SCADA 3000 User s Manual...
Страница 10: ...x SCADA 3000 User s Manual...
Страница 30: ...1 6 SCADA 3000 User s Manual...
Страница 48: ...4 6 SCADA 3000 User s Manual...
Страница 70: ...9 8 SCADA 3000 User s Manual...
Страница 122: ...12 8 SCADA 3000 User s Manual...
Страница 190: ...15 30 SCADA 3000 User s Manual...
Страница 211: ...lead 1 lag 0 else lead 0 lag 1 16 21 Chapter 16 Programming in C...
Страница 212: ...16 22 SCADA 3000 User s Manual...
Страница 236: ...21 8 SCADA 3000 User s Manual...
Страница 248: ...22 12 SCADA 3000 User s Manual...
Страница 258: ...23 10 SCADA 3000 User s Manual...
Страница 274: ...25 8 SCADA 3000 User s Manual...
Страница 288: ...27 8 SCADA 3000 User s Manual...
Страница 294: ...28 6 SCADA 3000 User s Manual...
Страница 296: ...A 2 SCADA 3000 User s Manual...
Страница 302: ...D 2 SCADA 3000 User s Manual...
Страница 318: ...I 2 SCADA 3000 User s Manual...
Страница 320: ...J 2 SCADA 3000 User s Manual...
Страница 322: ...K 2 SCADA 3000 User s Manual...
Страница 335: ...Test Log...
Страница 336: ......