📄 shuju.h
字号:
//文 件 名:shuju.h
//功 能:定义变量,包括PID数据结构,LCD显示所需字符串,电压,电流值
//作 者:吕定胜
//创建日期:2007-09-03
//修改日期:
//PID的数据结构
struct PID {
int gpwm; //跟踪值
float Proportion; //比例常数 Proportional Const
float Integral; //积分常数 Integral Const
float Derivative; //微分常数 Derivative Const
int LastError; //Error[-1]
int PrevError; //Error[-2]
float SumError; //Sums of Errors
float P;
float I;
float D;
}pid,*Ppid;
//LCD显示的相关字符串
bit clear; //清屏标志
bit waitin; //等待输入标志
unsigned char outu_list[5]="00.0"; //输出电压字符串
unsigned char outi_list[5]="0.00"; //输出电流字符串
//ADC测量的数据
int outu; //输出电压值,扩大10倍保存
int outi; //输出电流值,扩大100倍保存
//电源状态标志
bit flagpower; //电源开关标志
bit flagguo; //过载保护标志
bit I_Oput; //输入/确定标志,1为输入状态
bit error; //输入错误标志
char buff[2]; //按键记录
unsigned char inu; //按键输入电压值,扩大10倍后再赋值给fixoutu
char putcoun=0; //输入数字个数
int fixoutu; //输出电压给定值
//保护状态相关变量
unsigned char timer; //用于定时1.8s计数用,开始数据为80
//ADC转换查表
static const unsigned int code table0[]={
0,19,39,58,78,97,117,136,156,175,195,215,234,254,273,
293,312,332,351,371,391,410,430,449,469,488,508,527,547,566,
586,606,625,645,664,684,703,723,742,762,782,801,821,840,860,
879,899,918,938,957,977,997,1016,1036,1055,1075,1094,1114,1133,1153,
1173,1192,1212,1231,1251,1270,1290,1309,1329,1348,1368,1388,1407,1427,1446,
1466,1485,1505,1524,1544,1564,1583,1603,1622,1642,1661,1681,1700,1720,1739,
1759,1779,1798,1818,1837,1857,1876,1896,1915,1935,1955,1974,1994,2013,2033,
2052,2072,2091,2111,2130,2150,2170,2189,2209,2228,2248,2267,2287,2306,2326,
2346,2365,2385,2404,2424,2443,2463,2482,2502,2521,2541,2561,2580,2600,2619,
2639,2658,2678,2697,2717,2737,2756,2776,2795,2815,2834,2854,2873,2893,2913,
2932,2952,2971,2991,3010,3030,3049,3069,3088,3108,3128,3147,3167,3186,3206,
3225,3245,3264,3284,3304,3323,3343,3362,3382,3401,3421,3440,3460,3479,3499,
3519,3538,3558,3577,3597,3616,3636,3655,3675,3695,3714,3734,3753,3773,3792,
3812,3831,3851,3870,3890,3910,3929,3949,3968,3988,4007,4027,4046,4066,4086,
4105,4125,4144,4164,4183,4203,4222,4242,4261,4281,4301,4320,4340,4359,4379,
4398,4418,4437,4457,4477,4496,4516,4535,4555,4574,4594,4613,4633,4652,4672,
4692,4711,4731,4750,4770,4789,4809,4828,4848,4868,4887,4907,4926,4946,4965,
4985,};
static const unsigned int code table1[]={
9,29,48,68,87,107,127,146,166,185,205,224,244,263,283,
303,322,342,361,381,400,420,439,459,478,498,518,537,557,576,
596,615,635,654,674,694,713,733,752,772,791,811,830,850,869,
889,909,928,948,967,987,1006,1026,1045,1065,1085,1104,1124,1143,1163,
1182,1202,1221,1241,1260,1280,1300,1319,1339,1358,1378,1397,1417,1436,1456,
1476,1495,1515,1534,1554,1573,1593,1612,1632,1652,1671,1691,1710,1730,1749,
1769,1788,1808,1827,1847,1867,1886,1906,1925,1945,1964,1984,2003,2023,2043,
2062,2082,2101,2121,2140,2160,2179,2199,2218,2238,2258,2277,2297,2316,2336,
2355,2375,2394,2414,2434,2453,2473,2492,2512,2531,2551,2570,2590,2609,2629,
2649,2668,2688,2707,2727,2746,2766,2785,2805,2825,2844,2864,2883,2903,2922,
2942,2961,2981,3000,3020,3040,3059,3079,3098,3118,3137,3157,3176,3196,3216,
3235,3255,3274,3294,3313,3333,3352,3372,3391,3411,3431,3450,3470,3489,3509,
3528,3548,3567,3587,3607,3626,3646,3665,3685,3704,3724,3743,3763,3782,3802,
3822,3841,3861,3880,3900,3919,3939,3958,3978,3998,4017,4037,4056,4076,4095,
4115,4134,4154,4173,4193,4213,4232,4252,4271,4291,4310,4330,4349,4369,4389,
4408,4428,4447,4467,4486,4506,4525,4545,4565,4584,4604,4623,4643,4662,4682,
4701,4721,4740,4760,4780,4799,4819,4838,4858,4877,4897,4916,4936,4956,4975,
5000,};
//PWM数据输出查表
static const unsigned int code pwm[]={153,308,318,328,338,348,358,};
//延时子函数
void delay(unsigned char i)
{
unsigned char j;
while(i--)
for(j=0;j<200;j++);
}
//延时50us
void delay_50us(unsigned char i)
{
unsigned char j;
while(i--)
for(j=0;j<146;j++);
}
//延时50us
void delay_50us1(unsigned char i)
{
unsigned char j;
while(i--)
for(j=0;j<146;j++);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -