//****************************************************************************************** // dsPIC33FJ256GP506 Sample Program // Project : // Program Name : // Programer : // Create date : Version 1.0 H22.10.26 // Replace date : // History : // Laungage : FreeRTOS ( MPLAB C18 ) //****************************************************************************************** // Description // //****************************************************************************************** /* Scheduler include files. */ #include "FreeRTOS.h" #include "task.h" #include "semphr.h" void User_Confugration( void ); void Put_PORT(unsigned short int ); static void User_TASK_1( void *pvParameters ); static void User_TASK_2( void *pvParameters ); void Move_LED( unsigned short int *); // xSemaphoreHandle Ind_Seph; portBASE_TYPE Ind_tmp; volatile unsigned short int TASK1_LED = 0x0001; volatile unsigned short int TASK2_LED = 0x0010; // #define PI_OSC_CONV 6.78 // 50MHz / 7.37MHz ==> 6.78 void main( void ) { // ***************** // 1.Initalized // ***************** User_Confugration( ); vSemaphoreCreateBinary(Ind_Seph); // Create Semaphore // ***************** // 2.Create Task // ***************** xTaskCreate( User_TASK_1, ( const char * const ) "User_Task_1", 100, NULL, 1, NULL ); xTaskCreate( User_TASK_2, ( const char * const ) "User_Task_2", 100, NULL, 1, NULL ); // ***************** // 3.Start Scheduler // ***************** vTaskStartScheduler(); } //****************************************************************************************** // Function Name : User_TASK_1 // Title : // Input : // Output : //****************************************************************************************** static void User_TASK_1( void *pvParameters ) { while(1){ Move_LED(&TASK1_LED); Put_PORT(TASK1_LED | TASK2_LED); if((TASK1_LED & 0x0001)==1) xSemaphoreGiveFromISR(Ind_Seph, &Ind_tmp); vTaskDelay(125 / portTICK_RATE_MS /PI_OSC_CONV); } } //****************************************************************************************** // Function Name : User_TASK_2 // Title : // Input : // Output : //****************************************************************************************** static void User_TASK_2( void *pvParameters ) { while(1){ Move_LED(&TASK2_LED); Put_PORT(TASK1_LED | TASK2_LED); xSemaphoreTake(Ind_Seph, portMAX_DELAY); } } //****************************************************************************************** // Function Name : Move_LED // Title : // Input : // Output : //****************************************************************************************** void Move_LED( unsigned short int *led_lst ) { if((*led_lst & 0b10000000) != 0 ){ *led_lst = ( *led_lst << 1 ) | 0b00000001; }else{ *led_lst = ( *led_lst << 1 ) & 0b11111110; } } //****************************************************************************************** // // Confugration // // //****************************************************************************************** void User_Confugration( void ) { // (1)Set All Digital Port AD1PCFGH = 0xffff; AD1PCFGL = 0xffff; // (2)Define PortB TRISB = 0xFF00; PORTB = 0x0000; } void Put_PORT(unsigned short int put_data ) { PORTB = put_data; } //****************************************************************************************** // // Dummy Function // // //****************************************************************************************** void vApplicationIdleHook( void ){} void vParTestToggleLED( void ){} void vParTestSetLED( void ){}