This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/TM4C123GH6PM:颜色问题的功能

Guru**** 2964790 points

Other Parts Discussed in Thread: TM4C123GH6PM

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/833370/ccs-tm4c123gh6pm-function-with-color-problem

器件型号:TM4C123GH6PM

工具/软件:Code Composer Studio

您好!

有人能帮我处理代码吗? 当我在  while (1)中写入 Direct GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_2、GPIO_PIN_2)时、我在 MCU launchpad 上看到了颜色、并且当函数在 main.c 中被关闭时、一切都正常、但当我创建新的.c 和.h 文件并实现函数 Color_output2时、我不会得到相同的结果。 LaunchPad 是 TM4C123GH6PM,CCS 9.1,除了这一点,一切都很好。

color.c

#include "tm4c123ghp6.h"
#include 
#include 
#include 
#include 
#include "gpio.h"
#include "pin_map.h"

void Color_output2 (char *挑选颜色){
if (pickColor ="red"){
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、GPIO_PIN_1);
}
否则、如果(PickColor ="蓝色"){
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_2、GPIO_PIN_2);
}
否则、如果(PickColor ="绿色环保"){
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_3、GPIO_PIN_3);
}
否则、如果(PickColor ="粉色"){
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、GPIO_PIN_1);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_2、GPIO_PIN_2);
}
否则、如果(PickColor ="黄色"){
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、GPIO_PIN_1);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_3、GPIO_PIN_3);
}
否则、如果(PickColor ="sky_blue"){
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_2、GPIO_PIN_2);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_3、GPIO_PIN_3);
}
否则、如果(PickColor ="白色"){
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、GPIO_PIN_1);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_2、GPIO_PIN_2);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_3、GPIO_PIN_3);
}
否则、如果(PickColor ="黑色"){
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、GPIO_PIN_1);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_2、GPIO_PIN_2);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_3、GPIO_PIN_3);
}
否则{
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、GPIO_PIN_1);
SysCtlDelay (9000000);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、~GPIO_PIN_1);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_2、GPIO_PIN_2);
SysCtlDelay (9000000);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_2、~GPIO_PIN_2);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_3、GPIO_PIN_3);
SysCtlDelay (9000000);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_3、~GPIO_PIN_3);
}
}

Color.h
void Color_output2 (char PickColor[]);

Main.c

#include 
#include 
#include 
cinclude "hw_memmap.h"
#include "hw_types.h"
#include "hw_gpio.h"
#include "debug.h"

#include "sysctl.h"
#include "gpio.h"
#include "rom_prefix.h"

#include "ccc.h"






#include "包含"ngpc.h"#include "包含"包含"ngpc.h"#include #include "h.h"#include "包含"ngpc.h.h"#include "#include "#include "包含"ns"#include "mctrab.h.h.h.h"#include "#include "#include "#include "ns"#include "#include "#include "mctrab.h.h.h.h.h.h"#include "#include "#include "#include "#include "#include "#include "#include "#include "#ctrab.h.h.h.h.h.h"#include "#include "#include "#








include "tvist.h"
#include "interrupt.h"
#include "inttypes.h"
#include "lcd.h"
#include "iso646.h"
#include
"pprfos.h"
#include "locale.h"
#include "sysg小时


#include "mcs.h




#include "n.包含"symd.h"#include "#include "symcs.hr.md.h #include "#include "#include "state"#include "syt.md.hr.md.h #include "#include "#include "#tide"






SYSCTL_XTAL_16MHz | SYSCTL_SYSDIV_4);//时钟设置50MHz

SysCtlPeripheralEnable (SYSCTL_Periph_GPIOF);//启用 PORF
GPIOPinTypeGPIOOutput (GPIO_PORTF_BASE、GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1);

void 输出1 (1);/void 1 (pFIN-1)

char pom[30]="黄色";
while (1){
color_output2 (&pom);

}
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、米兰、

    为什么这些代码行在 main 之外?

    SysCtlClockSet (SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHz | SYSCTL_SYSDIV_4);//时钟设置50MHz
    
    PeripheralEnable (SYSCTL_Periph_GPIOF);//使能端口 F
    GPIOPINTypeOutput (GPIO_3_BUST_PIN_OUTPSIMP_1);// GPIO_OUTPSIMP_IN_OUTPSIMP_PIN_OUTPSIMP_1;/GPIO_OUTPSIMP_IN_OUTPSIMP_PIN_1;/GPIO_OUTPSIMP_PIN_OUTPSIMP
    

    如果它们不在主代码中、这将是您的问题。 您希望它们位于 main 内部、但在 while (1)之外。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢 Ralph 的快速回答、但这不是解决方案、因为我在复制代码行时误击了。 SysCtlClockSet、 SysCtlPeripheralEnable和 GPIOPinTypeGPIOOutput位于 main 中。

    我想说、当我在 while (1)中使用 GPIOPinWrite 时、一切都正常。 当我implementation Color_Output2放置 main.c 时,情况也是如此。 当我创建新的.c 和.h 文件、然后从 main 调用 Color_output2时、会出现问题。 我想问题出在 Color_output2的参数中。 我尝试了许多 不同的方法来调用 Color_output2、但没有成功。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、米兰、

    您能否在 zip 文件中导出不工作的项目并将其发布? 我怀疑这是一个链接问题、我最容易调试手头的项目。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Ralph、

    我将上传包含 GPTM 中断、2个 GPIO 中断和 Color_output2函数的 zip 文件。 所以 没有必要分析中断、因为中断正常、我对它们进行了测试。 e2e.ti.com/.../API_5F00_GPIOInterrupt_2B00_GPTMInterrupt.zip

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、米兰、

    现在它已加载到我的 CCS 中、我可以更轻松地看到问题。

    您要将其传递到您的函数中:

    char pom[30]="黄色";
    color_output2 (&pom);
    

    但是、您将尝试如下方式对其进行评估:

    否则、如果(PickColor ="黄色"){
    

    该语法不起作用。

    字符数组中将有多个 ASCII 字符用于黄色,但您不能只是说拾色="Yellow"。 您需要为此使用字符串。

    如果您使用断点和观察表达式、您将看到当您输入函数时、它存储了正确的颜色:

    但如果正确的话、它实际上不会评估其他器件。

    当我将该函数移植到主文件中时、它也不起作用、这意味着您在生成 color.c 和 color.h 文件后更改了该函数、这正是导致问题的原因。 您需要解决这些问题、然后一切都可以正常工作。