信号量工程运行不对
<p>代码:</p><pre>
<code>#ifndef configUSE_COUNTING_SEMAPHORES
#define configUSE_COUNTING_SEMAPHORES 1
#endif</code></pre>
<pre>
<code>#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
#include "LEDBlinkV1.h"
#include "cfg.h"
#include "macromcu.h"
#define LONG_TIME 0xffff
xSemaphoreHandle xSemaphore;
void vTask1( void * pvParameters )
{
const portTickType xDelay = 500 / portTICK_RATE_MS;
// 创建信号
vSemaphoreCreateBinary( xSemaphore );
for( ;; )
{
//vTaskDelay( xDelay )
_delay_ms(500);
PININV(LED1);
//BUTTON按下时,发出信号
if(( xSemaphore != NULL ) && (PININ(BUTTON) == 0))
{
PININV(LED3);
xSemaphoreGive( xSemaphore );
}
}
}
void vTask2( void * pvParameters )
{
for( ;; )
{
//收到信号后LED2闪
if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE )
{
PININV(LED2);
PININV(LED4);
}
taskYIELD();
}
}
int main()
{
PINDIR(LED1, PIN_OUTPUT);
PINDIR(LED2, PIN_OUTPUT);
PINDIR(LED3, PIN_OUTPUT);
PINDIR(LED4, PIN_OUTPUT);
PINSET(LED2);
PINDIR(BUTTON, PIN_INPUT);
PINSET(BUTTON);
xTaskCreate( vTask1, "TASK1", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
xTaskCreate( vTask2, "TASK2", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
vTaskStartScheduler();
while(1);
return 0;
}
</code></pre>
<p>用proteus仿真,收不到消息。请问高手,哪里有错误?谢谢!</p>
<p>确认一下按键按下是否触发了。</p>
wangerxian 发表于 2024-11-12 18:52
确认一下按键按下是否触发了。
<p>触发了,就是收不到</p>
<p>那有没可能就是仿真的问题?</p>
<p>是不是LONG_TIME太小了哦</p>
页:
[1]