代码:
#ifndef configUSE_COUNTING_SEMAPHORES
#define configUSE_COUNTING_SEMAPHORES 1
#endif
#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;
}
用proteus仿真,收不到消息。请问高手,哪里有错误?谢谢!
确认一下按键按下是否触发了。
那有没可能就是仿真的问题?