- 打卡等级:初来乍到
- 打卡总天数:4
- 最近打卡:2026-01-23 10:02:21
已绑定手机
注册会员
- 积分
- 60
|
发表于 2026-1-23 10:02:21
|
显示全部楼层
STC32G8K的,将协程移植放进去,task_delay(1000);不是一1S。非常快,串口一直不停的发。根本没延时,P34P35是LED灯也不受控。怎么也关不掉。是怎么回事,以下是各相关的代码,帮忙看一下
void Task11(void)
{
task_start(11);
TX1_write2buff(0x30);
TX1_write2buff(0x37);
TX1_write2buff(0x31);
TX1_write2buff(0x30);
P34=~P34;
P35=~P35;
task_delay(1000);
task_end(1);
}
……………………
#define Task_Max_Num 12
……
//每隔任务的数据结构
typedef struct
{
unsigned int time;
unsigned long state;
} _task;
……
void Timer_config(void)
{
TIM_InitTypeDef TIM_InitStructure; //结构定义
TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload; //指定工作模式, TIM_16BitAutoReload,TIM_16Bit,TIM_8BitAutoReload,TIM_16BitAutoReloadNoMask
TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_1T; //指定时钟源, TIM_CLOCK_1T,TIM_CLOCK_12T,TIM_CLOCK_Ext
TIM_InitStructure.TIM_ClkOut = DISABLE; //是否输出高速脉冲, ENABLE或DISABLE
TIM_InitStructure.TIM_Value = (u16)(65536UL - (MAIN_Fosc / 1000UL)); //中断频率, 1000次/秒
TIM_InitStructure.TIM_PS = 0; //8位预分频器(n+1), 0~255
TIM_InitStructure.TIM_Run = ENABLE; //是否初始化后启动定时器, ENABLE或DISABLE
Timer_Inilize(Timer0,&TIM_InitStructure); //初始化Timer0 Timer0,Timer1,Timer2,Timer3,Timer4
NVIC_Timer0_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
}
……
void Timer0_ISR_Handler (void) interrupt TMR0_VECTOR //进中断时已经清除标志
{
set_task_mode();
} |
|