2017-02-23 119 views
-1

我想做一個C程序,它使用各種功能,然後通過連接到LPCXpresso 1769的DIP開關,它必須選擇要執行的功能(例如00二進制計數器01旋轉LED等) 。現在,我已經做了它,但想要改變選擇程序從嵌套if執行到switch語句的函數,但它不起作用。它會進行編譯,但是,調試器會在拋出LPCXpresso併爲其執行的每個任務選擇組合後,引發一些警告(第123行和第132行的'語句無效',第100行'未使用的參數pvParameter')做一件事。 我正在使用恩智浦的LPCXpresso IDE。C Switch Statement CMSIS FreeRTOS

下面的代碼

#include <string.h> 
#include "FreeRTOS.h" 
#include "task.h" 
#ifdef __USE_CMSIS 
#include "LPC17xx.h" 
#endif 

#include <cr_section_macros.h> 
#include <NXP/crp.h> 
#include "lpc17xx_gpio.h" 
#include "lpc17xx_timer.h" 
#include "lpc17xx_adc.h" 
#include "lpc17xx_pinsel.h" 
/* Library includes. */ 
#include "LPC17xx.h" 
#include "LPC17xx_gpio.h" 
#include "system_LPC17xx.h" 



/* Used as a loop counter to create a very crude delay. */ 
IRQn_Type TIMER0; 
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ; 
/* Used in the run time stats calculations. */ 
/* Used in the run time stats calculations. */ 
static uint32_t ulClocksPer10thOfAMilliSecond = 0UL; 
#define mainDELAY_LOOP_COUNT (0xfffff) 
void CONFIG_GPIO(void); 

static void init_adc(void); 
extern int Timer0_Wait(); 

#define RGB_RED 0x01000000 
#define RGB_BLUE 0x02000000 
#define RGB_GREEN 0x04000000 
void init_rgb (void); 
void counter_rgb (void); 

void vTaskKit(void *pvParameters); 

int main(void) 
{ 
    init_adc(); 
    init_rgb(); 
    CONFIG_GPIO(); 

    xTaskCreate (vTaskKit, "Kit", 240, NULL, 1, NULL); 
    /* Start the FreeRTOS scheduler. */ 
    vTaskStartScheduler(); 

    /* The following line should never execute. If it does, it means there was 
insufficient FreeRTOS heap memory available to create the Idle and/or timer 
tasks. See the memory management section on the http://www.FreeRTOS.org web 
site for more information. */ 
for(;;); 
} 


/*-----------------------------------------------------------*/ 


void CONFIG_GPIO(void) 
      { 
       GPIO_SetDir(0,0x000000FF, 1); 
       GPIO_ClearValue(0, 0x000000FF); 
       GPIO_SetDir(2,0x000000FF,0); 
       GPIO_ClearValue(2, 0x000000FF); 
      } 
void init_rgb (void) 
      { 
       GPIO_SetDir (0,0x01000000, 1); 
       GPIO_SetDir (0,0x02000000, 1); 
       GPIO_SetDir (0,0x04000000, 1); 
      } 
static void init_adc(void) 
{ 

/* 
* Init ADC pin connect 
* AD0.0 on P0.23 
*/ 
PINSEL_CFG_Type PinCfg; 
PinCfg.Funcnum = 1; 
PinCfg.OpenDrain = 0; 
PinCfg.Pinmode = 0; 
PinCfg.Pinnum = 23; 
PinCfg.Portnum = 0; 
PINSEL_ConfigPin(&PinCfg); 

/* Configuration for ADC : 
* Frequency at 1Mhz 
* ADC channel 0, no Interrupt 
*/ 
ADC_Init(LPC_ADC, 100000); 
ADC_IntConfig(LPC_ADC,ADC_ADINTEN0,ENABLE); 
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,ENABLE); 
ADC_EdgeStartConfig(LPC_ADC,ADC_START_ON_FALLING); 
} 

void vTaskKit(void *pvParameters) 
{ 
volatile unsigned long ul; 

uint32_t var1=0x00000001; 
uint32_t del =0x000000FF; 
uint32_t var2=0x00000001; 
uint32_t analog = 0; 
uint32_t sw=0x00000000; 
unsigned int var=0; 
while(1) 
{ 
    sw=GPIO_ReadValue(2); 
    switch(sw) 
    { 
     case 0x00000001://Contador Binario 
      GPIO_SetValue(0,var); 
      var++; 
      vTaskDelay(100); 
      GPIO_ClearValue(0,0x000000FF); 
      break; 

     case 0x00000002://Auto Increible 
      for(var2;var2<=7;var2++) 
      { 
       GPIO_SetValue(0,var1); 
       var1= var1<<1; 
       for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++) 
       { 
       } 
       GPIO_ClearValue(0,del); 
      } 
      for(var2;var2>=2;var2--) 
      { 
       GPIO_SetValue(0,var1); 
       var1= var1>>1; 
       for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++) 
       { 
       } 
       GPIO_ClearValue(0,del); 
      } 
      break; 

     case 0x00000003://Contador RGB 
      GPIO_SetValue (0,RGB_RED); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_RED); 
      GPIO_SetValue (0,RGB_BLUE); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_BLUE); 
      GPIO_SetValue (0,(RGB_RED+RGB_BLUE)); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,(RGB_RED+RGB_BLUE)); 
      GPIO_SetValue (0,RGB_GREEN); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_GREEN); 
      GPIO_SetValue (0,RGB_GREEN+RGB_RED); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_GREEN+RGB_RED); 
      GPIO_SetValue (0,RGB_GREEN+RGB_BLUE); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE); 
      GPIO_SetValue (0,RGB_GREEN+RGB_BLUE+RGB_RED); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE+RGB_RED); 
      vTaskDelay(200/portTICK_RATE_MS); 
      break; 

     case 0x00000004://Contador ADC Binario 
      ADC_StartCmd(LPC_ADC,ADC_START_NOW); 
      analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0); 
      analog=analog/16; 
      GPIO_SetValue(0,analog); 
      vTaskDelay(100/portTICK_RATE_MS); 

      GPIO_ClearValue(0,0x000000FF); 
      break; 

     case 0x00000005://Contador ADC RGB 
      ADC_StartCmd(LPC_ADC,ADC_START_NOW); 
      analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0); 
      if(analog<585) 
      { 
       GPIO_SetValue(0,RGB_RED); 
       vTaskDelay(50/portTICK_RATE_MS); 
       GPIO_ClearValue (0,RGB_RED); 
      } 
      if(585<analog && analog<1170) 
      { 
       GPIO_SetValue (0,RGB_BLUE); 
       vTaskDelay(50/portTICK_RATE_MS); 
       GPIO_ClearValue (0,RGB_BLUE); 
      } 
      if(1170<analog && analog<1755) 
      { 
       GPIO_SetValue (0,(RGB_RED+RGB_BLUE)); 
       vTaskDelay(50/portTICK_RATE_MS); 
       GPIO_ClearValue (0,(RGB_RED+RGB_BLUE)); 
      } 
      if(1755<analog && analog<2340) 
      { 
       GPIO_SetValue (0,RGB_GREEN); 
       vTaskDelay(50/portTICK_RATE_MS); 
       GPIO_ClearValue (0,RGB_GREEN); 
      } 
      if(2340<analog && analog<2925) 
      { 
       GPIO_SetValue (0,RGB_GREEN+RGB_RED); 
       vTaskDelay(50/portTICK_RATE_MS); 
       GPIO_ClearValue (0,RGB_GREEN+RGB_RED); 
      } 
      if(2925<analog && analog<3510) 
      { 
       GPIO_SetValue (0,RGB_GREEN+RGB_BLUE); 
       vTaskDelay(50/portTICK_RATE_MS); 
       GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE); 
      } 
      if(3510<analog && analog<4095) 
      { 
       GPIO_SetValue (0,RGB_GREEN+RGB_BLUE+RGB_RED); 
       vTaskDelay(50/portTICK_RATE_MS); 
       GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE+RGB_RED); 
      } 
      break; 
    } 
} 
} 















void vMainConfigureTimerForRunTimeStats(void) 
{ 
/* How many clocks are there per tenth of a millisecond? */ 
ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ/10000UL; 
} 
/*-----------------------------------------------------------*/ 

uint32_t ulMainGetRunTimeCounterValue(void) 
{ 
uint32_t ulSysTickCounts, ulTickCount, ulReturn; 
const uint32_t ulSysTickReloadValue = (configCPU_CLOCK_HZ/ configTICK_RATE_HZ) - 1UL; 
volatile uint32_t * const pulCurrentSysTickCount = ((volatile uint32_t *) 0xe000e018); 
volatile uint32_t * const pulInterruptCTRLState = ((volatile uint32_t *) 0xe000ed04); 
const uint32_t ulSysTickPendingBit = 0x04000000UL; 

/* NOTE: There are potentially race conditions here. However, it is used 
anyway to keep the examples simple, and to avoid reliance on a separate 
timer peripheral. */ 


/* The SysTick is a down counter. How many clocks have passed since it was 
last reloaded? */ 
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount; 

/* How many times has it overflowed? */ 
ulTickCount = xTaskGetTickCountFromISR(); 

/* Is there a SysTick interrupt pending? */ 
if((*pulInterruptCTRLState & ulSysTickPendingBit) != 0UL) 
{ 
    /* There is a SysTick interrupt pending, so the SysTick has overflowed 
    but the tick count not yet incremented. */ 
    ulTickCount++; 

    /* Read the SysTick again, as the overflow might have occurred since 
    it was read last. */ 
    ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount; 
} 

/* Convert the tick count into tenths of a millisecond. THIS ASSUMES 
configTICK_RATE_HZ is 1000! */ 
ulReturn = (ulTickCount * 10UL) ; 

/* Add on the number of tenths of a millisecond that have passed since the 
tick count last got updated. */ 
ulReturn += (ulSysTickCounts/ulClocksPer10thOfAMilliSecond); 

return ulReturn; 
} 
/*-----------------------------------------------------------*/ 

void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName) 
{ 
(void) pcTaskName; 
(void) pxTask; 

/* Run time stack overflow checking is performed if 
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook 
function is called if a stack overflow is detected. */ 
taskDISABLE_INTERRUPTS(); 
for(;;); 
} 
/*-----------------------------------------------------------*/ 

void vApplicationMallocFailedHook(void) 
{ 
/* vApplicationMallocFailedHook() will only be called if 
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook 
function that will get called if a call to pvPortMalloc() fails. 
pvPortMalloc() is called internally by the kernel whenever a task, queue, 
timer or semaphore is created. It is also called by various parts of the 
demo application. If heap_1.c or heap_2.c are used, then the size of the 
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in 
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used 
to query the size of free heap space that remains (although it does not 
provide information on how the remaining heap might be fragmented). */ 
taskDISABLE_INTERRUPTS(); 
for(;;); 

} 
/*-----------------------------------------------------------*/ 

和工作的人,但與嵌套,如果是

#include <string.h> 
#include "FreeRTOS.h" 
#include "task.h" 
#ifdef __USE_CMSIS 
#include "LPC17xx.h" 
#endif 

#include <cr_section_macros.h> 
#include <NXP/crp.h> 
#include "lpc17xx_gpio.h" 
#include "lpc17xx_timer.h" 
#include "lpc17xx_adc.h" 
#include "lpc17xx_pinsel.h" 
/* Library includes. */ 
#include "LPC17xx.h" 
#include "LPC17xx_gpio.h" 
#include "system_LPC17xx.h" 



/* Used as a loop counter to create a very crude delay. */ 
IRQn_Type TIMER0; 
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ; 
/* Used in the run time stats calculations. */ 
/* Used in the run time stats calculations. */ 
static uint32_t ulClocksPer10thOfAMilliSecond = 0UL; 
#define mainDELAY_LOOP_COUNT (0xfffff) 
void CONFIG_GPIO(void); 

static void init_adc(void); 
extern int Timer0_Wait(); 

#define RGB_RED 0x01000000 
#define RGB_BLUE 0x02000000 
#define RGB_GREEN 0x04000000 
void init_rgb (void); 
void counter_rgb (void); 

void vTaskKit(void *pvParameters); 

int main(void) 
{ 
init_adc(); 
init_rgb(); 
CONFIG_GPIO(); 

xTaskCreate (vTaskKit, "Kit", 240, NULL, 1, NULL); 
/* Start the FreeRTOS scheduler. */ 
vTaskStartScheduler(); 

/* The following line should never execute. If it does, it means there was 
insufficient FreeRTOS heap memory available to create the Idle and/or timer 
tasks. See the memory management section on the http://www.FreeRTOS.org web 
site for more information. */ 
for(;;); 
} 


/*-----------------------------------------------------------*/ 


void CONFIG_GPIO(void) 
      { 
       GPIO_SetDir(0,0x000000FF, 1); 
       GPIO_ClearValue(0, 0x000000FF); 
       GPIO_SetDir(2,0x000000FF,0); 
       GPIO_ClearValue(2, 0x000000FF); 
      } 
void init_rgb (void) 
      { 
       GPIO_SetDir (0,0x01000000, 1); 
       GPIO_SetDir (0,0x02000000, 1); 
       GPIO_SetDir (0,0x04000000, 1); 
      } 
static void init_adc(void) 
{ 

/* 
* Init ADC pin connect 
* AD0.0 on P0.23 
*/ 
PINSEL_CFG_Type PinCfg; 
PinCfg.Funcnum = 1; 
PinCfg.OpenDrain = 0; 
PinCfg.Pinmode = 0; 
PinCfg.Pinnum = 23; 
PinCfg.Portnum = 0; 
PINSEL_ConfigPin(&PinCfg); 

/* Configuration for ADC : 
* Frequency at 1Mhz 
* ADC channel 0, no Interrupt 
*/ 
ADC_Init(LPC_ADC, 100000); 
ADC_IntConfig(LPC_ADC,ADC_ADINTEN0,ENABLE); 
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,ENABLE); 
ADC_EdgeStartConfig(LPC_ADC,ADC_START_ON_FALLING); 
} 

void vTaskKit(void *pvParameters) 
{ 
volatile unsigned long ul; 

uint32_t var1=0x00000001; 
uint32_t del =0x000000FF; 
uint32_t var2=0x00000001; 
uint32_t analog = 0; 
char var=0; 
char sw=0x000000000; 
char bin=0x00000001; 
char inc=0x00000002; 
char rgb=0x00000003; 
char adcbin=0x00000004; 
char adcrgb=0x00000005; 

    while(1) 
    { 

     sw=GPIO_ReadValue(2); 
     if(sw==bin) 
     { 
        GPIO_SetValue(0,var); 
        var++; 
        vTaskDelay(100); 
        GPIO_ClearValue(0,0x000000FF); 




     } 


     if(sw==inc) 
     { 
     for(var2;var2<=7;var2++) 
       { 
        GPIO_SetValue(0,var1); 
        var1= var1<<1; 
        for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++) 
         { 
         } 

        GPIO_ClearValue(0,del); 
       } 

       for(var2;var2>=2;var2--) 
       { 
        GPIO_SetValue(0,var1); 
        var1= var1>>1; 
        for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++) 

        { 
        } 
        GPIO_ClearValue(0,del); 

         } 
        } 
     if(sw==rgb) 
     { 
      GPIO_SetValue (0,RGB_RED); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_RED); 
      GPIO_SetValue (0,RGB_BLUE); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_BLUE); 
      GPIO_SetValue (0,(RGB_RED+RGB_BLUE)); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,(RGB_RED+RGB_BLUE)); 
      GPIO_SetValue (0,RGB_GREEN); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_GREEN); 
      GPIO_SetValue (0,RGB_GREEN+RGB_RED); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_GREEN+RGB_RED); 
      GPIO_SetValue (0,RGB_GREEN+RGB_BLUE); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE); 
      GPIO_SetValue (0,RGB_GREEN+RGB_BLUE+RGB_RED); 
      vTaskDelay(200/portTICK_RATE_MS); 

      GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE+RGB_RED); 
      vTaskDelay(200/portTICK_RATE_MS); 


      } 

     if(sw==adcbin) 
        { 
         ADC_StartCmd(LPC_ADC,ADC_START_NOW); 
         analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0); 
         analog=analog/16; 
         GPIO_SetValue(0,analog); 
         vTaskDelay(100/portTICK_RATE_MS); 

         GPIO_ClearValue(0,0x000000FF); 


        } 
     if(sw==adcrgb) 
        { 
      ADC_StartCmd(LPC_ADC,ADC_START_NOW); 
      analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0); 
      if(analog<585) 
      { 
      GPIO_SetValue(0,RGB_RED); 
      vTaskDelay(50/portTICK_RATE_MS); 
      GPIO_ClearValue (0,RGB_RED); 
      } 
      if(585<analog && analog<1170) 
      { 
      GPIO_SetValue (0,RGB_BLUE); 
      vTaskDelay(50/portTICK_RATE_MS); 
      GPIO_ClearValue (0,RGB_BLUE); 
      } 
      if(1170<analog && analog<1755) 
      { 
      GPIO_SetValue (0,(RGB_RED+RGB_BLUE)); 
      vTaskDelay(50/portTICK_RATE_MS); 
      GPIO_ClearValue (0,(RGB_RED+RGB_BLUE)); 
      } 
      if(1755<analog && analog<2340) 
      { 
      GPIO_SetValue (0,RGB_GREEN); 
      vTaskDelay(50/portTICK_RATE_MS); 
      GPIO_ClearValue (0,RGB_GREEN); 
      } 
      if(2340<analog && analog<2925) 
      { 
      GPIO_SetValue (0,RGB_GREEN+RGB_RED); 
      vTaskDelay(50/portTICK_RATE_MS); 
      GPIO_ClearValue (0,RGB_GREEN+RGB_RED); 
      } 
      if(2925<analog && analog<3510) 
      { 
      GPIO_SetValue (0,RGB_GREEN+RGB_BLUE); 
      vTaskDelay(50/portTICK_RATE_MS); 
      GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE); 
      } 
      if(3510<analog && analog<4095) 
      { 
      GPIO_SetValue 
      (0,RGB_GREEN+RGB_BLUE+RGB_RED); 

      vTaskDelay(50/portTICK_RATE_MS); 

      GPIO_ClearValue 

      (0,RGB_GREEN+RGB_BLUE+RGB_RED); 

      } 


        } 
        } 
        } 















void vMainConfigureTimerForRunTimeStats(void) 
{ 
/* How many clocks are there per tenth of a millisecond? */ 
ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ/10000UL; 
} 
/*-----------------------------------------------------------*/ 

uint32_t ulMainGetRunTimeCounterValue(void) 
{ 
uint32_t ulSysTickCounts, ulTickCount, ulReturn; 
const uint32_t ulSysTickReloadValue = (configCPU_CLOCK_HZ/ configTICK_RATE_HZ) - 1UL; 
volatile uint32_t * const pulCurrentSysTickCount = ((volatile uint32_t *) 0xe000e018); 
volatile uint32_t * const pulInterruptCTRLState = ((volatile uint32_t *) 0xe000ed04); 
const uint32_t ulSysTickPendingBit = 0x04000000UL; 

/* NOTE: There are potentially race conditions here. However, it is used 
anyway to keep the examples simple, and to avoid reliance on a separate 
timer peripheral. */ 


/* The SysTick is a down counter. How many clocks have passed since it was 
last reloaded? */ 
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount; 

/* How many times has it overflowed? */ 
ulTickCount = xTaskGetTickCountFromISR(); 

/* Is there a SysTick interrupt pending? */ 
if((*pulInterruptCTRLState & ulSysTickPendingBit) != 0UL) 
{ 
    /* There is a SysTick interrupt pending, so the SysTick has overflowed 
    but the tick count not yet incremented. */ 
    ulTickCount++; 

    /* Read the SysTick again, as the overflow might have occurred since 
    it was read last. */ 
    ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount; 
} 

/* Convert the tick count into tenths of a millisecond. THIS ASSUMES 
configTICK_RATE_HZ is 1000! */ 
ulReturn = (ulTickCount * 10UL) ; 

/* Add on the number of tenths of a millisecond that have passed since the 
tick count last got updated. */ 
ulReturn += (ulSysTickCounts/ulClocksPer10thOfAMilliSecond); 

return ulReturn; 
} 
/*-----------------------------------------------------------*/ 

void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName) 
{ 
(void) pcTaskName; 
(void) pxTask; 

/* Run time stack overflow checking is performed if 
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook 
function is called if a stack overflow is detected. */ 
taskDISABLE_INTERRUPTS(); 
for(;;); 
} 
/*-----------------------------------------------------------*/ 

void vApplicationMallocFailedHook(void) 
{ 
/* vApplicationMallocFailedHook() will only be called if 
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook 
function that will get called if a call to pvPortMalloc() fails. 
pvPortMalloc() is called internally by the kernel whenever a task, queue, 
timer or semaphore is created. It is also called by various parts of the 
demo application. If heap_1.c or heap_2.c are used, then the size of the 
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in 
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used 
to query the size of free heap space that remains (although it does not 
provide information on how the remaining heap might be fragmented). */ 
taskDISABLE_INTERRUPTS(); 
for(;;); 

} 
/*-----------------------------------------------------------*/ 
+2

歡迎來到StackOverflow!你應該訪問幫助中心並閱讀關於如何發佈一個好問題的指導原則,因爲在你的發佈中有很多代碼。請記住,所提出的問題應該儘可能清晰和簡潔,並且只應發佈與您的問題最相關的代碼。謝謝。 –

+0

你是否已經在調試器中加入了代碼?輸入switch語句時,「sw」的值是多少? 'GPIO_ReadValue()'返回什麼類型?你爲什麼改變'sw'的類型? – kkrambo

+0

這些消息顯然不是來自調試器。而且我們對代碼牆沒有調試服務。 – Olaf

回答

1

參考未使用的參數警告:實現FreeRTOS tasks必須具有相同的原型函數和原型包括一個參數。但是,並非所有任務實際上都希望使用該參數,但如果該參數未被使用,編譯器將生成您所看到的警告。該警告是良性的,並且您無法通過刪除參數來修復它,因此爲了讓編譯器保持安靜,只需通過將以下代碼添加到任務中來執行參數的無效讀取:

/*移除有關編譯器警告的信息一個未使用的參數。 */ (void)pvParameters;

上線123沒有影響

參考語句無法評論,因爲我不知道這是行123

0

GPIO_ReadValue()返回一個uint32_t的類型。在工作程序中,返回值分配給8位字符類型,這意味着最重要的24位被屏蔽掉並被忽略。在隨後的比較語句中只使用該值的最低有效8位。

在非工作程序中,GPIO_ReadValue()的返回值分配給一個32位值。最重要的24位不會被屏蔽掉。所有32位用於確定switch語句的情況。案例值假定最重要的24位都是零。但是如果任何最重要的24位都不是0,那麼你的任何一個case語句都不會匹配這個值。也許你需要屏蔽掉這些最重要的24位。

sw = (GPIO_ReadValue(2) & 0x000000FF); 
switch(sw)