为什么我的 PIC 的 LED 不闪烁?

发布于 2024-10-03 12:57:17 字数 989 浏览 2 评论 0原文

我正在尝试开始使用 pic24,特别是 PIC24FJ64GA002,并且我查看了寄存器等数据表,但我仍然无法让它闪烁 LED。当我通过调试运行它时,它运行正确,但是当我尝试在图片上实际运行它时,它似乎根本无法运行。

我正在使用外部振荡器,特别是 8MHZ 振荡器,连接到引脚 9(OSCI) 和 10 (OSCO)。 Mplab 中的编译器是 C30。

数据表链接为:http://ww1.microchip.com/downloads/en/DeviceDoc /39881D.pdf

代码如下

//include basic header definition
#include <p24FJ64GA002.h>

//config
_CONFIG2(0x0200);
_CONFIG1(0x0800);

int i;

//main loop
int main(void)
{

   OSCCON = 0x2280;  //select external OSC, no PLL
   AD1PCFG      = 0xFFFF;  //set to all digital I/O
   TRISA = 0x0000;  //configure all PortA as output

   while(1)    //Loop forever
   {
  LATAbits.LATA0 = 1; //RA0 = 1
  Wait();
  LATAbits.LATA0 = 1; //RA0 = 1
  Wait(); 
   }

}


int Wait(void) // gives me a nice delay of 1/3rd a second or so
{
for (int i = 0; i < 30000; i++)
 { 
  for (int i = 0; i < 30; i++);
    }

}

I am trying to get started with pic24's, specifically the PIC24FJ64GA002, and I have looked in the datasheet at the registers and whatnot, but I still cannot get it to blink the leds. When I run it via debug it runs correctly, but when I try to actually run it on the pic it seems to not run at all.

I am using an external Oscillator, a 8MHZ Oscillator specifically, connected to pins 9(OSCI) and 10 (OSCO). Compiler is C30 in Mplab.

Datasheet link is: http://ww1.microchip.com/downloads/en/DeviceDoc/39881D.pdf

The code is below

//include basic header definition
#include <p24FJ64GA002.h>

//config
_CONFIG2(0x0200);
_CONFIG1(0x0800);

int i;

//main loop
int main(void)
{

   OSCCON = 0x2280;  //select external OSC, no PLL
   AD1PCFG      = 0xFFFF;  //set to all digital I/O
   TRISA = 0x0000;  //configure all PortA as output

   while(1)    //Loop forever
   {
  LATAbits.LATA0 = 1; //RA0 = 1
  Wait();
  LATAbits.LATA0 = 1; //RA0 = 1
  Wait(); 
   }

}


int Wait(void) // gives me a nice delay of 1/3rd a second or so
{
for (int i = 0; i < 30000; i++)
 { 
  for (int i = 0; i < 30; i++);
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

过期以后 2024-10-10 12:57:17

你需要去嗨,等等,然后瞧,等等……你只是去嗨,等等,嗨,等等。

   while(1)    //Loop forever
   {
  LATAbits.LATA0 = 1; //RA0 = 1
  Wait();
  LATAbits.LATA0 = 0; //RA0 = 1
  Wait(); 
   }

You need to go hi, wait, then lo, wait... you are just going hi, wait, hi, wait.

   while(1)    //Loop forever
   {
  LATAbits.LATA0 = 1; //RA0 = 1
  Wait();
  LATAbits.LATA0 = 0; //RA0 = 1
  Wait(); 
   }
作业与我同在 2024-10-10 12:57:17

您使用什么优化级别进行编译?如果它仅在调试中工作,则优化器可能会将整个 Wait() 函数减少为无操作。尝试声明“volatile int i”。

What optimization level are you compiling with? If it's only working in debug, it's possible the optimizer is reducing the whole Wait() function to a no-op. Try declaring `volatile int i'.

难以启齿的温柔 2024-10-10 12:57:17

谢谢大家的帮助,但我设置的配置位错误,当我在 mplab 的配置编辑器中设置它们时一切正常。

感谢您的帮助!

Thank you guys for all your help, but it was that I set the config bits wrong, when I set them in the config editor in mplab all works well.

Thank you for all your help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文