首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在TM4C123G上闪烁发光二极管?

无法在TM4C123G上闪烁发光二极管?
EN

Stack Overflow用户
提问于 2021-12-29 03:10:11
回答 2查看 160关注 0票数 0

我的TI Tiva ARM程序不适用于TM4C123G。使用板EK TM4C123GXL。程序不会在RGB LED上闪烁。我可以运行其他的例子程序来检查LED,这个程序是从教科书TI TIVA ARM编程为嵌入式系统。需要帮助来调试这个程序。谢谢

代码:

代码语言:javascript
复制
/*  p2.4.c: Toggling a single LED

/*  This program turns on the red LED and toggles the blue LED 0.5 sec on and 0.5 sec off. */

#include "TM4C123GH6PM.h"

void delayMs(int n);

int main(void)
{

    /* enable clock to GPIOF at clock gating control register */
    SYSCTL->RCGCGPIO |= 0x20;
    /* enable the GPIO pins for the LED (PF3, 2 1) as output */
    GPIOF->DIR = 0x0E;
    /* enable the GPIO pins for digital function */
    GPIOF->DEN = 0x0E;
    /* turn on red LED only and leave it on */
    GPIOF->DATA = 0x02;
    
    while(1)
    {      
        GPIOF->DATA |= 4;    /* turn on blue LED */
        delayMs(500);

        GPIOF->DATA &= ~4;   /* turn off blue LED */
        delayMs(500); 
    }
}

/* delay n milliseconds (16 MHz CPU clock) */
void delayMs(int n)
{
    int i, j;
    for(i = 0 ; i < n; i++)
        for(j = 0; j < 3180; j++)
        {}  /* do nothing for 1 ms */
}

我正在使用Vision版本:VisionV5.36.0.0

代码语言:javascript
复制
Tool Version Numbers:
Toolchain:        MDK-Lite  Version: 5.36.0.0
Toolchain Path:    G:\Keil_v5\ARM\ARMCLANG\Bin
C Compiler:         ArmClang.exe        V6.16
Assembler:          Armasm.exe        V6.16
Linker/Locator:     ArmLink.exe        V6.16
Library Manager:    ArmAr.exe        V6.16
Hex Converter:      FromElf.exe        V6.16
CPU DLL:               SARMCM3.DLL          V5.36.0.0
Dialog DLL:         TCM.DLL              V1.53.0.0
Target DLL:             lmidk-agdi.dll       V???
Dialog DLL:         TCM.DLL              V1.53.0.0
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-12-30 01:08:41

它看起来像是编译器版本优化的一些问题。返回到v5。

票数 0
EN

Stack Overflow用户

发布于 2021-12-29 16:28:04

如果必须使用计数循环延迟,则至少必须声明控制变量volatile,以确保它们不会是最佳化

代码语言:javascript
复制
volatile int i, j;

但是,最好避免实现依赖于指令周期和编译器代码生成的延迟。Cortex-M核心有一个SYSTICK时钟,它提供不依赖编译器的代码生成、对系统时钟的更改或移植到不同的Cortex-M设备的精确计时。

例如:

代码语言:javascript
复制
volatile uint32_t msTicks = 0 ;
  
void SysTick_Handler(void)  
{
    msTicks++; 
}

void delayMs( uint32_t n )
{
    uint32_t start = msTicks ;
    while( msTicks - start < n )
    {
        // wait
    }
}
  
int main (void)  
{
    // Init SYSTICK interrupt interval to 1ms
    SysTick_Config( SystemCoreClock / 1000 ) ;

    ...  
  
}

忙-等待延迟有一些限制,使它不适合所有的程序,除了最琐碎的程序。在延迟期间,处理器被占用了--没有什么有用的东西。使用上面定义的SYSTICK和msTicks,一个更好的解决方案可能是:

代码语言:javascript
复制
uint32_t blink_interval = 1000u ;
uint32_t next_toggle = msTicks + blink_interval ;

for(;;)
{
    // If time to toggle LED ...
    if( (int32_t)(msTicks - next_toggle) <= 0 )
    {
        // Toggle LED and advance toggle time
        GPIOF->DATA ^= 4 ; 
        next_toggle += blink_interval ;
    }

    // Do other work while blinking LED
    ...
        
}

还请注意,使用位-异或运算符切换LED.可以用来简化原始循环:

代码语言:javascript
复制
while(1)
{      
    GPIOF->DATA ^= 4 ;
    delayMs( 500 ) ;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70514774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档