📄 assistant.c
字号:
//************************************************************************
//File Name: Assistant.c
//Include: Middle_Value -- Find the middle value from 3 data
// Absolute_Value -- Compute the absolute value
// Zero_Study_Self -- Study system zero by itself
// Force_Study_Self(unsigned channel)
//Description: Including some very useful assistant functions. Provide...
// help to other functions in other files.
//************************************************************************
#include "Headfiles.h"
//************************************************************************
//Func. Name: Middle_Value
//Input variables: int first_value -- the first value
// int second_value -- the second ...
// int third_value -- the third ...
//Output variables: int second_value -- the middle value
//Use sub-func.list: None
//Used by list: ADCDAC.c -- ADC
//Description: Compute the middle value of 3 value.
//************************************************************************
int Middle_Value(int first, int second, int third)
{
int tmp;
//--------------------------------------------------Compositor
if (first < second)
{
tmp = first;
first = second;
second = tmp;
}
if (first < third)
{
tmp = first;
first = third;
third = tmp;
}
if (second < third)
{
tmp = second;
second = third;
third = tmp;
}
//-------------------------------Return the middle value
return second;
}
//************************************************************************
//Func. Name: Absolute_Value ( |value| )
//Input variables: int number -- input value
//Output variables: int number -- output absolute value
//Use sub-func.list: None
//Used by list: Now is no used in any functions
//Description: Compute the absolute value
//************************************************************************
int Absolute_Value(int number)
{
if (number < 0)
{
return (-number);
}
else
{
return (number);
}
}
//************************************************************************
//Func. Name: Zero_Study_Self
//Input variables: char channel -- input channel label, 0 or 1
// int input -- input zero-point value for computing
//Output variables: None
//Use sub-func.list: None
//Used by list: PIDContorl.c -- PID_Control
//Description: Compute the zero point of all of the system, ...
// including hydraulic & electronic departure. And the result will ...
// be used in DAC function.
//************************************************************************
void Zero_Study_Self(unsigned char channel, int input)
{
//------------------------------Initializtion & Compution
if (System_Zero_Flag == 0) //Initizaliztion for the first run
{
Temp_Lint = input;
System_Zero_Flag = 1;
System_Zero_Point[channel] = 0;
}
else //Compute
{
Temp_Lint += input;
System_Zero_Flag++;
}
//---------------------------------Compute & Save
//Compute Finally, and save the zero point value to variables
if (System_Zero_Flag >= 128)
{
Temp_Lint = Temp_Lint >> 7;
System_Zero_Point[channel] = Temp_Lint;
Function_Ctrl = 0;
System_Zero_Flag = 0;
}
}
void Force_Study_Self(unsigned channel)
{
long int temp;
if(channel == 0)
{
temp = P1_Cylinder[0];
temp = (temp * 367 >> 8) - P2_Cylinder[0];
Control_Parameter[4] = temp;
}
else if (channel == 1)
{
temp = P1_Cylinder[1];
temp = (temp * 367 >> 8) - P2_Cylinder[1];
Control_Parameter[11] = temp;
}
else
{
}
}
void Number_Display(unsigned char x, unsigned char y,
unsigned char num_total_digit, unsigned char radix_ptr_digit,
int number)
{
unsigned char num[5] = {0, 0, 0, 0, 0}, i, j;
if (number < 0)
{
Code[y][x-1] = '-';
number = -number;
}
else if (Code[y][x-1] == '-')
{
Code[y][x-1] = ' ';
}
for(; number != 0;)
{
if (number >= 10000)
{
number = number - 10000;
num[0]++;
}
else if (number >= 1000)
{
number = number - 1000;
num[1]++;
}
else if ((number <= 999) && (number >= 100))
{
number = number - 100;
num[2]++;
}
else if ((number <= 99) && (number >= 10))
{
number = number - 10;
num[3]++;
}
else
{
num[4] = number;
number = 0;
}
}
for(i = 0; i < num_total_digit; i++)
{
num[i] = num[i + 5 - num_total_digit];
}
if (radix_ptr_digit != 0)
{
Code[y][x + num_total_digit - radix_ptr_digit] = '.';
}
else
{
}
for(i = 0, j = 0; j < num_total_digit; i++,j++)
{
if (Code[y][x+i] != '.')
{
Code[y][x+i] = num[j] + 0x30;
}
else
{
i++;
Code[y][x+i] = num[j] + 0x30;
}
}
}
/*
void LCD_Arrow_Position(unsigned char value, unsigned char *y_arrow_old, unsigned char *y_arrow_new,
unsigned char arrow_min, unsigned char arrow_max)
{
*y_arrow_old = *y_arrow_new;
if (value == UP_KEY)
{
if (*y_arrow_old == arrow_min)
{
*y_arrow_new = arrow_max;
}
else
{
*y_arrow_new = *y_arrow_old - 1;
}
}
else if (value == DOWN_KEY)
{
if (*y_arrow_old == arrow_max)
{
*y_arrow_new = arrow_min;
}
else
{
*y_arrow_new = *y_arrow_old + 1;
}
}
else
{
_NOP();
}
}*/
void LCD_Arrow_Position(unsigned char value, unsigned char *y_arrow,
unsigned char arrow_min, unsigned char arrow_max)
{
if (value == UP_KEY)
{
if (*y_arrow == arrow_min)
{
*y_arrow = arrow_max;
}
else
{
*y_arrow = *y_arrow - 1;
}
//--------------------------------------------------
if (Interface == CONTROL_SET_VIEW)
{
switch (*y_arrow)
{
//case 0: *y_arrow = 1; break;
case 8 : *y_arrow = 7; break;
case 16: *y_arrow = 15; break;
case 23: *y_arrow = 22; break;
default : break;
}
}
else if ((Interface == CHANNEL_1SET_VIEW) ||
(Interface == CHANNEL_2SET_VIEW))
{
switch (*y_arrow)
{
case 3 : *y_arrow = 2; break;
case 6 : *y_arrow = 5; break;
default : break;
}
}
else if (Interface == SYSTEM_SET_VIEW)
{
switch (*y_arrow)
{
case 4 : *y_arrow = 3; break;
default : break;
}
}
else if (Interface == SYSTEM_TEST_VIEW)
{
switch (*y_arrow)
{
case 10 : *y_arrow = 9; break;
}
}
else
{
}
//------------------------------------------------
}
else if (value == DOWN_KEY)
{
if (*y_arrow == arrow_max)
{
*y_arrow = arrow_min;
}
else
{
*y_arrow = *y_arrow + 1;
}
//-----------------------------------------
if (Interface == CONTROL_SET_VIEW)
{
switch (*y_arrow)
{
//case 0: *y_arrow = 1; break;
case 8 : *y_arrow = 9; break;
case 16: *y_arrow = 17; break;
case 23: *y_arrow = 24; break;
default : break;
}
}
else if ((Interface == CHANNEL_1SET_VIEW) ||
(Interface == CHANNEL_2SET_VIEW))
{
switch (*y_arrow)
{
case 3 : *y_arrow = 4; break;
case 6 : *y_arrow = 7; break;
default : break;
}
}
else if (Interface == SYSTEM_SET_VIEW)
{
switch (*y_arrow)
{
case 4 : *y_arrow = 5; break;
default : break;
}
}
else if (Interface == SYSTEM_TEST_VIEW)
{
switch (*y_arrow)
{
case 10 : *y_arrow = 11; break;
}
}
else
{
}
//------------------------------------------------//
}
}
void LCD_Arrow_Display(unsigned char y_arrow)
{
unsigned char i;
unsigned char temp;
/*
if ((y_arrow_old + 5) % 5 == 0) { temp = 0; }
else if ((y_arrow_old + 4) % 5 == 0) { temp = 1; }
else if ((y_arrow_old + 3) % 5 == 0) { temp = 2; }
else if ((y_arrow_old + 2) % 5 == 0) { temp = 3; }
else if ((y_arrow_old + 1) % 5 == 0) { temp = 4; }
Code[temp][0] = ' ';
*/
for (i = 0; i < 5; i++)
{
if (Code[i][0] == 0x84)
{
Code[i][0] = ' ';
}
}
if ((y_arrow + 5) % 5 == 0) { temp = 0; }
else if ((y_arrow + 4) % 5 == 0) { temp = 1; }
else if ((y_arrow + 3) % 5 == 0) { temp = 2; }
else if ((y_arrow + 2) % 5 == 0) { temp = 3; }
else if ((y_arrow + 1) % 5 == 0) { temp = 4; }
Code[temp][0] = 0x84;
}
void Number_Indecrease_Asic(unsigned char key_value, int *parameter,
unsigned char max, unsigned char min)
{
if (key_value == LEFT_KEY)
{
if (*parameter >= max)
{
*parameter = min;
}
else
{
*parameter += 1;
}
}
else if (key_value == RIGHT_KEY)
{
if (*parameter <= min)
{
*parameter = max;
}
else
{
*parameter -= 1;
}
}
}
void Number_Indecrease(unsigned char key_value, int *parameter,
int max, int min, int delt)
{
if (key_value == LEFT_KEY)
{
*parameter += delt;
if (*parameter >= max)
{
*parameter = max;
}
}
else if (key_value == RIGHT_KEY)
{
*parameter -= delt;
if (*parameter <= min)
{
*parameter = min;
}
}
}
void Array_Ptr(unsigned char interface, unsigned char y_arrow, unsigned char *array_ptr)
{
switch (interface)
{
case MAIN_VIEW : *array_ptr = y_arrow;
break;
case CONTROL_SET_VIEW :
if (y_arrow <= 7)
{
*array_ptr = y_arrow - 1;
}
else if (y_arrow <= 15)
{
*array_ptr = y_arrow - 2;
}
/* else if (y_arrow <= 22)
{
*array_ptr = y_arrow - 3;
}
else if (y_arrow <= 29)
{
*array_ptr = y_arrow - 4;
}*/
else
{
}
break;
case CHANNEL_1SET_VIEW :
if (y_arrow <= 2)
{
*array_ptr = y_arrow - 1;
}
else if (y_arrow <= 5)
{
*array_ptr = y_arrow - 2;
}
else if (y_arrow <= 8)
{
*array_ptr = y_arrow - 3;
}
else
{
}
break;
case CHANNEL_2SET_VIEW :
if (y_arrow <= 2)
{
*array_ptr = y_arrow - 1;
}
else if (y_arrow <= 5)
{
*array_ptr = y_arrow - 2;
}
else if (y_arrow <= 8)
{
*array_ptr = y_arrow - 3;
}
else
{
}
break;
case SYSTEM_SET_VIEW :
if (y_arrow <= 3)
{
*array_ptr = y_arrow - 1;
}
else if (y_arrow <= 14)
{
*array_ptr = y_arrow - 5;
}
else if (y_arrow <= 17)
{
*array_ptr = y_arrow - 12;
}
else if (y_arrow == 18)
{
*array_ptr = y_arrow - 8;
}
else
{
}
break;
case SYSTEM_TEST_VIEW :
if (y_arrow <= 9)
{
*array_ptr = y_arrow - 1;
}
else
{
*array_ptr = y_arrow - 2;
}
break;
default : break;
}
}
void Code_Inputs(unsigned char Code0[20], unsigned char Code1[20],
unsigned char Code2[20], unsigned char Code3[20],
unsigned char Code4[20])
{
unsigned char i;
for(i = 0; i < 20; i++)
{
Code[0][i] = Code0[i];
Code[1][i] = Code1[i];
Code[2][i] = Code2[i];
Code[3][i] = Code3[i];
Code[4][i] = Code4[i];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -