新手编程,大家帮帮忙,谢谢了
下面程序大家有没有懂的,帮忙注释一下,谢谢了int16_t inputValue;
if(SysTickFlag)
{
angle = MMA7455_Angle();
if( angle < 100){
Insert_Angle(angle);
// Digit_Set(ANGLE_POS0, g_angle/10);
LCD12864_SetXY(1,6);
LCD12864_PutNumber(g_angle/10);
// Digit_Set(ANGLE_POS1, g_angle%10);
LCD12864_SetXY(1,7);
LCD12864_PutNumber(g_angle/10);
if(System_Function == 1){
//inputValue = pid_Controller(20, g_angle, &pidData);
//Set_Input(inputValue);
if(g_angle > 45)
{
pwm_value = 512 - (int16_t)(g_angle - 45)*15;
if(pwm_value < 0) pwm_value = 0;
}
else if(g_angle < 45)
{
pwm_value = 512 + (int16_t)(45-g_angle)*15;
if(pwm_value > 1023) pwm_value = 1023; }
PWM_OutPut(pwm_value); }
else if(System_Function == 2){
inputValue = pid_Controller(SettingAngle, g_angle, &pidData);
Set_Input(inputValue); }
}
}
}
#include "Message.h" #include "SysTimer.h"
enum KScanState{
KSCAN_IDLE = 0, /* 无键按下, 键盘扫描初始状态 */
KSCAN_PRESS, /* 键按下,判断抖动, 键按下>40ms */
KSCAN_NORMAL, /* 普通按键,判断是否长按键,键按下>1.6s */
KSCAN_LPRESS, /* 长按键,判断是否连发,键按下>1s */
KSCAN_LIANFA, /* 连发按键,判断连发,每0.4s一次连发按键 */ };
struct KStateFsm{
enum KScanState kpress_next; /* 键按下,下一个状态 */
enum KScanState nokey_next; /* 键抬起,下一个状态 */
unsigned char kpress_time; /* 键按下需持续的时间, 20ms的倍数 */
enum KeyType ktype; /* 键按下满足条件,输出按键类型 */ };
/* 状态转换表,保证状态编号值与在数组中的位置相同 */
struct KStateFsm kstate_fsm_table[] = {
/* current kpress_next, nokey_next, time, type */
/* KSCAN_IDLE */ {KSCAN_PRESS, KSCAN_IDLE, 1, eKTYPE_NOKEY},
/* KSCAN_PRESS */ {KSCAN_NORMAL, KSCAN_IDLE, 2, eKTYPE_NORMAL},
/* KSCAN_NORMAL */ {KSCAN_LPRESS, KSCAN_IDLE, 80, eKTYPE_LPRESS},
/* KSCAN_LPRESS */ {KSCAN_LIANFA, KSCAN_IDLE, 50, eKTYPE_LIANFA},
/* KSCAN_LIANFA */ {KSCAN_LIANFA, KSCAN_IDLE, 20, eKTYPE_LIANFA} };
static enum KScanState keystate; static unsigned char oldkey;
static unsigned char ktime_counter = 0;
static pFunKeyRead KeyRead_CallBack; /* 回调函数, 读按键,返回按键编号 */
void KeyScan_Run20ms(void) {
unsigned char key_id = 0;
struct MSG msg;
if(!KeyRead_CallBack) return;
key_id = (*KeyRead_CallBack)();
if( (key_id != 0) && (key_id == oldkey) )
{
if(++ktime_counter >= kstate_fsm_table[keystate].kpress_time )
{
ktime_counter = 0;
if(eKTYPE_NOKEY != kstate_fsm_table[keystate].ktype)
{
msg.msg_id = eMsg_Key;
msg.parma_len = 2;
msg.parma.data[0] = key_id;
msg.parma.data[1] = kstate_fsm_table[keystate].ktype;
Msg_PushMessage(&msg);
}
keystate = kstate_fsm_table[keystate].kpress_next;
}
} else
{
keystate = kstate_fsm_table[keystate].nokey_next;
oldkey = key_id; }
}
好多程序啊,晕乎乎的,谢谢大家了