資源簡介
可實現(xiàn)兩位整數(shù)的加減乘除用數(shù)碼管顯示
代碼片段和文件信息
#include?“driver_KeyBoard.h“
static?GPIO_InitTypeDef?KeyBoardRow_InitStruct={GPIO_Pin_KeyBoardRGPIO_Speed_2MHzGPIO_Mode_Out_PP};
static?GPIO_InitTypeDef?KeyBoardClm_InitStruct={GPIO_Pin_KeyBoardCGPIO_Speed_2MHzGPIO_Mode_IPD};
static?TIM_TimebaseInitTypeDef?TIMKeyBoard_InitStruct={71TIM_CounterMode_Up999TIM_CKD_DIV1};
static?NVIC_InitTypeDef?NVICKeyBoard_InitStructure={TIM3_IRQn63ENABLE};
static?unsigned?short?key[KeyNum]?= { 0x1010 0x1020 0x1040 0x1080
0x2010 0x2020 0x2040 0x2080
0x4010 0x4020 0x4040 0x4080
0x8010 0x8020 0x8040 0x8080 };
static?char?value[KeyNum]= { 1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16 };
static?char?mean[KeyNum]= { ‘7‘ ‘8‘ ‘9‘ ‘+‘
‘4‘ ‘5‘ ‘6‘ ‘-‘
‘1‘ ‘2‘ ‘3‘ ‘*‘
‘=‘ ‘0‘ ‘~‘ ‘/‘ };
static?char?times[KeyNum];
static?char?timesold[KeyNum];
void?KeyBoard_Init(void)
{
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisableENABLE);
GPIO_Init(GPIOB&KeyBoardRow_InitStruct);
GPIO_Init(GPIOB&KeyBoardClm_InitStruct);
TIM_TimebaseInit(TIM3&TIMKeyBoard_InitStruct);
TIM_ITConfig(TIM3TIM_IT_UpdateENABLE);
NVIC_Init(&NVICKeyBoard_InitStructure);
TIM_Cmd(TIM3ENABLE);
}
static?unsigned?int?DictRecoverKey(unsigned?short?data)
{
for(int?i=0;i if(data==key[i])
return?value[i];
return?0;
}
static?unsigned?short?ReadKeyBoard(void)
{
return?((GPIO_ReadInputData(GPIOB)&GPIO_Pin_KeyBoardC)|(GPIO_ReadOutputData(GPIOB)&GPIO_Pin_KeyBoardR));
}
static?void?WriteKeyBoard(unsigned?int?RowX)
{
GPIO_Write(GPIOBGPIO_Pin_4< }
void?TIM3_IRQHandler(void)
{
static?int?i;
static?unsigned?int?kMem;
WriteKeyBoard((++i)%4);
kMem?=?DictRecoverKey(ReadKeyBoard());
if(kMem)
{
times[kMem-1]++;
}
if(!(i%64))
for(int?j=0;j {
if(times[j]>12)
if(timesold[j]==times[j])
{
BufPush(mean[j]);
timesold[j]=times[j]=0;
}
else
timesold[j]=times[j];
else
times[j]=0;
}
TIM_ClearFlag(TIM3TIM_FLAG_Update);
}
void?BufPush(char?value)?//?支持連續(xù)讀數(shù),不滿則寫
{??
????if(!isBufFull())
{
TopElement?+=?1;??
InputMem[TopElement]?=?value;
}
}??
??
void?BufPop(void)??
{??
????if(!isBufEmpty())
TopElement?-=?1;??
}??
??
char?BufTop(void)??
{??
????if(!isBufEmpty())
return?InputMem[TopElement];?
????else?return?‘0‘;?
}??
???
int?isBufEmpty(void)??
{??
????return?TopElement?==?-1;??
}??
??
int?isBufFull(void)??
{??
????return?TopElement?==?InputMemSize?-?1;??
}
評論
共有 條評論