- 打卡等级:常住居民III
- 打卡总天数:166
- 最近打卡:2025-06-16 09:42:32
中级会员
- 积分
- 365
|
出现了一个警告,看提示:
Rebuild target 'Target 1'
compiling main.c...
compiling key.c...
key.c(17): warning C280: 'time': unreferenced local variable
compiling TM1652.c...
linking...
Program Size: data=35.3 xdata=0 code=921
creating hex file from ".\Objects\STC89C52RC+TM1652+5LED"...
".\Objects\STC89C52RC+TM1652+5LED" - 0 Error(s), 1 Warning(s).
Build Time Elapsed: 00:00:01
再看代码:
//按键C文件
#include "key.h"
#include "TM1652.h" // 包含显示驱动头文件,用于更新显示
// 全局变量定义
unsigned int count = 0;
unsigned int upPressTime = 0;
unsigned int downPressTime = 0;
bit upIsPressed = 0;
bit downIsPressed = 0;
// 通用延时函数(ms级)
void delay1ms(unsigned char time) //@11.0592MHz
{
unsigned char data i, j;
_nop_();
_nop_();
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
// 按键扫描函数
void key()
{
static bit clrIsPressed = 0; // 清零键状态标志(静态变量保持状态)
// --------------------- 上键检测 ---------------------
if (up == 0) // 按键按下(低电平有效)
{
if (!upIsPressed) // 未触发长按标志
{
delay1ms(20); // 消抖
if (up == 0) // 确认按下
{
upIsPressed = 1; // 标记为已按下
upPressTime = 0; // 重置长按计时
count = (count < 99999) ? count + 1 : 99999; // 数值加1(上限99999)
TM_Digtal_Display(count); // 更新显示
}
}
else // 已触发长按标志,进入连续计数模式
{
upPressTime += 10; // 计时(10ms/次)
if (upPressTime >= LONG_PRESS_THRESHOLD && upPressTime % REPEAT_INTERVAL == 0)
{
count = (count < 99999) ? count + 1 : 99999; // 连续加1
TM_Digtal_Display(count); // 更新显示
}
}
}
else // 按键释放
{
if (upIsPressed) // 清除长按状态
{
upIsPressed = 0;
upPressTime = 0;
delay1ms(20); // 释放后消抖
}
}
// --------------------- 下键检测 ---------------------
if (down == 0)
{
if (!downIsPressed)
{
delay1ms(20);
if (down == 0)
{
downIsPressed = 1;
downPressTime = 0;
count = (count > 0) ? count - 1 : 0; // 数值减1(下限0)
TM_Digtal_Display(count);
}
}
else
{
downPressTime += 10;
if (downPressTime >= LONG_PRESS_THRESHOLD && downPressTime % REPEAT_INTERVAL == 0)
{
count = (count > 0) ? count - 1 : 0;
TM_Digtal_Display(count);
}
}
}
else
{
if (downIsPressed)
{
downIsPressed = 0;
downPressTime = 0;
delay1ms(20);
}
}
// --------------------- 清零键检测 ---------------------
if (clr == 0) // 按下清零键
{
if (!clrIsPressed) // 未触发清零状态
{
delay1ms(20); // 消抖
if (clr == 0) // 确认按下
{
clrIsPressed = 1; // 标记为已清零
count = 0; // 清零
TM_Digtal_Display(count);
}
}
}
else // 释放清零键
{
clrIsPressed = 0; // 重置状态
}
}
为什么出现“key.c(17): warning C280: 'time': unreferenced local variable”这个警告?key.h里添加了STC15.h头文件,而且STC15.h头文件是用STC-ISP生成的,并且整个文件已经保存在了工程文件夹里了。
|
|