/**************************************************
*File Name :bianmaqi
*Autor :zwt
*Version :V1.0
*Data :20/11/2011
*Descrption :用于BOC面板
***************************************************
*
*
*
***************************************************/
/*
void DelayS(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
u8 a3,a2,a3old,a2old,wei1,wei0;
u8 count=0;
u8 JIANZHI=0;
uint8 bianmaqi()
{
a2=GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_0);
a3=GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3);
if(a2&&a3==0)
wei1++;
DelayS(0X0000000F);
a2=GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2);
a3=GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3);
if(a2&&!a3)
{
wei0++;
JIANZHI++;
}
if(a3&&!a2)
{
a3old--;
JIANZHI--;
}
return JIANZHI;
} */
#include "bianmaqi.h"
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
/* 设备驱动任务使用的结构体消息 */
//static uint8 NewKnobKey; /* 编码器寄存器,用于编码器检测 */
//static uint8 OldKnobKey;
static uint8 FgKnobCount;
static uint8 LeftCount;
static uint8 RightCount;
extern uint8 WeldCount; /* 寄存器,用于焊接开关检测 */
static uint8 FgWeldKey;
static uint8 KeyDelay; /* 寄存器,用于功能开关检测 */
static uint8 KeyTime;
static uint8 NewKeyData;
static uint8 OldKeyData;
static uint8 KeyCheckValidData;
typedef unsigned short CPU_INT16U;
static void EncoderForward (void);
static void EncoderReverse (void);
/*
*********************************************************************************************************
* EncoderKey
*
* Description : Encoder check key Functions.
*
* Arguments : None.
*
* Returns : None.
*********************************************************************************************************
*/
uint16 gg;
uint16 b, c;
//void EncoderKey(void) /* 编码器扫描函数 */
//{
static uint8 NewKnobKey = 0; /* 编码器寄存器,用于编码器检测 */
static uint8 OldKnobKey = 0;
static uint8 keytemp;
//
// uint16 keybuff;
//
// GPIO_ResetBits(GPIOA, GPIO_Pin_3); /* 使能编码器检测端口 */
//
// if (gg == 0) {
//// FgKnobCount = 1;
// gg = 1;
// NewKnobKey = ((u8)GPIO_ReadInputData(GPIOD)) & 0x03;
// c = NewKnobKey;
// } else {
// gg = 0;
// if (NewKnobKey == ((u8)GPIO_ReadInputData(GPIOD)) & 0x03) {
// keytemp = NewKnobKey; /* 传递最新编码器的状态 */
// keytemp ^= OldKnobKey; /* 新编码器的状态和上次状态是否不同 */
// b = keytemp;
// if (keytemp== 0) {
// //GPIO_SetBits(GPIOA, GPIOA_ENCODER_EN);
// return; /* 两次比较相同,编码器未旋转 */
// }
// if (keytemp & 0x02) { /* 判断编码器旋转方向 */
// if (NewKnobKey & 0x02) EncoderReverse();
// else if (NewKnobKey & 0x01) EncoderReverse();
// else EncoderForward();
// }
// else if (keytemp & 0x03) {
// if (NewKnobKey & 0x00) EncoderReverse();
// else if (NewKnobKey & 0x01) EncoderReverse();
// else EncoderForward();
// }
// OldKnobKey = NewKnobKey;
// } else {
// // GPIO_SetBits(GPIOA, GPIOA_ENCODER_EN);
// return;
// }
// }
//// GPIO_SetBits(GPIOA, GPIOA_ENCODER_EN);
//
//
// }
uint16 gg,cs;
void EncoderKey(void) /* 编码器扫描函数 */
{
CPU_INT16U keytemp;
uint16 keybuff;
GPIO_ResetBits(GPIOA, GPIO_Pin_3); /* 使能编码器检测端口 */
if (FgKnobCount == 1) {
FgKnobCount = 1;
NewKnobKey = ((u8)GPIO_ReadInputData(GPIOD)) & 0x03;
} else {
// FgKnobCount = 0;
NewKnobKey = ((u8)GPIO_ReadInputData(GPIOD)) & 0x03;
if (NewKnobKey ==((u8)GPIO_ReadInputData(GPIOD)) & 0x03) {
keytemp = NewKnobKey; /* 传递最新编码器的状态 */
keytemp ^= OldKnobKey; /* 新编码器的状态和上次状态是否不同 */
cs=keytemp & 0x03;
keytemp=cs;
if ((keytemp& 0x03)== 0) {
GPIO_SetBits(GPIOA, GPIO_Pin_3);
return; /* 两次比较相同,编码器未旋转 */
}
if (keytemp & 0x02) { /* 判断编码器旋转方向 */
if (NewKnobKey & 0x02) EncoderReverse();
else if (NewKnobKey & 0x01) EncoderReverse();
else EncoderForward();
}
else if (keytemp & 0x03) {
if (NewKnobKey & 0x00) EncoderReverse();
else if (NewKnobKey & 0x01) EncoderReverse();
else EncoderForward();
}
OldKnobKey = NewKnobKey;
} else {
// GPIO_SetBits(GPIOA, GPIOA_ENCODER_EN);
return;
}
}
}
/*
*********************************************************************************************************
* WheelRight
*
* Description : Encoder check forward Functions.
*
* Arguments : None.
*
* Returns : None.
*********************************************************************************************************
*/
uint8 l,r,jz;
static void EncoderForward(void)
{
LeftCount = 0;
RightCount++;
l++;
// if (RightCount > 1) {
RightCount = 0;
WeldCount++;
jz=WeldCount;
// }
}
static void EncoderReverse(void)
{
LeftCount ++;
RightCount = 0;
r++;
if (LeftCount > 2) {
LeftCount = 0;
WeldCount--;
}
}
/*
keybuff = GPIO_ReadInputData(GPIOD);
gg = keybuff;
NewKnobKey = keybuff & 0x03; */
// keybuff = NewKnobKey; /* 传递最新编码器的状态 */
// keybuff ^= OldKnobKey; /* 新编码器的状态和上次状态是否不同 */
// if (keybuff == 0) return; /* 两次比较相同,编码器未旋转 */
// if (keybuff & 0x02) { /* 判断编码器旋转方向 */
/* if (NewKnobKey & 0x02) EncoderReverse();
else if (NewKnobKey & 0x01) EncoderReverse();
else EncoderForward();
} else if (keybuff & 0x03) {
if (NewKnobKey & 0x00) EncoderReverse();
else if (NewKnobKey & 0x01) EncoderReverse();
else EncoderForward();
}
*/