芯片:STC8C2K64S2

在我尚未添加 QRcode.c
跟随项目编译的时候,编译输出如下
Rebuild target 'Target 1'
assembling STARTUP.A51...
compiling Timer.c...
compiling UART.c...
compiling lcd_init.c...
compiling zk.c...
compiling lcd.c...
compiling protocol.c...
compiling model_bt.c...
compiling main.c...
source\main.c(44): warning C322: unknown identifier
source\main.c(196): warning C294: unreachable code
linking...
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?_DISPLAY_GB2312_STRING?ZK
Program Size: data=15.2 xdata=881 code=14130
creating hex file from ".\Objects\2025_02_10"...
".\Objects\2025_02_10" - 0 Error(s), 3 Warning(s).
Build Time Elapsed: 00:00:01
在我添加了 QRcode.c
以后,编译输出如下
Rebuild target 'Target 1'
assembling STARTUP.A51...
compiling Timer.c...
compiling UART.c...
compiling lcd_init.c...
compiling zk.c...
compiling lcd.c...
compiling QR_Encode.c...
compiling protocol.c...
compiling model_bt.c...
compiling main.c...
source\main.c(44): warning C322: unknown identifier
source\main.c(196): warning C294: unreachable code
linking...
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?_DISPLAY_GB2312_STRING?ZK
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?_ENCODEDATA?QR_ENCODE
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?_ISCHINESEDATA?QR_ENCODE
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?_CHINESETOBINALY?QR_ENCODE
Program Size: data=95.2 xdata=2284 code=30135
creating hex file from ".\Objects\2025_02_10"...
".\Objects\2025_02_10" - 0 Error(s), 6 Warning(s).
Build Time Elapsed: 00:00:01
然后我的延时函数就失效了?
我的延时是依靠定时器计算的。代码如下
void Timer3_Isr(void) interrupt 19
{
cnt++;
return;
}
/**
* @brief 定时器3初始化
* @param us
*/
int Timer3Init(unsigned long us)
{
unsigned long timerCnt = 0UL;
float timerCnt_f = 0.0;
unsigned int tm3ps = 1;
timerCnt_f = TIMER_MAX_COUNT - (FOSC * us / CONSTANT / 1.0);
timerCnt = timerCnt_f;
if ( timerCnt > MAX_UINT )
{
SET_BIT(P_SW2, 7); // 需要先开启扩展功能
if ( !FIND_BIT(P_SW2, 7) )
return TIMER3_INIT_FAIL;
TM3PS = 0U; // 初始化预分频
// 增加预分频系数直到重载值不超过0xFFFF
do
{
tm3ps = tm3ps + 1;
timerCnt_f = TIMER_MAX_COUNT - (FOSC * us / CONSTANT / tm3ps);
timerCnt = timerCnt_f;
} while ( timerCnt > MAX_UINT );
TM3PS = tm3ps - 1;// 增加预分频系数
}
CLEAR_BIT(T4T3M, 0);// Timer3, not output
SET_BIT(T4T3M, 1);// Timer3 set mode 1T
CLEAR_BIT(T4T3M, 2);// Timer3 set mode count
#if TIMER_CHECK
t3 = timerCnt;
t3_f = timerCnt_f;
#endif
T3L = (unsigned char)(timerCnt & 0xff);//Initial timer value
T3H = (unsigned char)((timerCnt >> 8) & 0xff);//Initial timer value
SET_BIT(IE2, 5);// Enable timer3 interrupt
return TIMER3_INIT_OK;
}
/**
* @brief 延时
* @param target 根据初始化来输入
*/
int UserDelay(const unsigned int target)
{
cnt = 0;
SET_BIT(T4T3M, 3);// Timer3 run
#if 0
while ( cnt != target )
WDT_RESET();// 防止因为延时导致WDT超时
#else
while ( cnt < target )
{
if ( cnt % 300 == 0 )
WDT_RESET();
}
#endif
CLEAR_BIT(T4T3M, 3);// Timer3 stop
return cnt;
}
#ifdef TIMER_DEFAULT_US
#define DEFAULT_DALEY_INIT() Timer3Init(TIMER_DEFAULT_US)
#define Delay_1ms() UserDelay(1U)
#define Delay_10ms() UserDelay(10U)
#define Delay_30ms() UserDelay(30U)
#define Delay_50ms() UserDelay(50U)
#define Delay_100ms() UserDelay(100U)
#define Delay_1s() UserDelay(1000U)
#endif // TIMER_DEFAULT_US
在我代码膨胀前,定时器都是有效且稳定可用的,但在膨胀后延时给我的感觉是起不了一点效果了。
希望有大神能帮我粗浅分析延时不起效果的原因???
由于手头上没有逻辑分析仪,Debug都是依赖UART来判断的。