【问题标题】:C8051f312 microcontroller [closed]C8051f312微控制器[关闭]
【发布时间】:2013-12-18 09:13:14
【问题描述】:

我不太擅长 C 语言,但我已经为 C8051F312 微控制器编写了一个非常简单的代码。 我的代码不起作用。请帮助我做错了什么。

#include C8051F310.h
#include stdio.h

sbit LED_16 = P1^7; // green LED: 1 = ON; 0 = OFF

void init(void)
{   
    // XBRN registers_init
    XBR0 = 0x00; 
    XBR1 = 0x00; // Enable the crossbar
    PCA0MD  = 0X00;


    // port_init
    P0MDOUT = 0x00; // Output configuration for P0
    P1MDOUT = 0x40; // Output configuration for P1
    P2MDOUT = 0x00; // Output configuration for P2
    P3MDOUT = 0x00; // Output configuration for P3
}

void main(void)
{
    init();

    while (1)
    {
        LED_16 = 1; // LED continuously illuminated
    }
}

【问题讨论】:

  • 如何代码不起作用?预期的结果是什么?实际结果是什么?你确定要在LED_16的初始化中使用异或操作吗?
  • 请发布 实际 代码,而不是它的近似值 - 上面的代码甚至无法编译。
  • p1^7 不是 XOR 操作,它声明了 P1 端口(这是一个 LED)的 7. 位,我想打开 LED。及其实际代码...
  • 您是否声称这段代码实际上是编译?我严重怀疑这一点。只需查看#includes 即可。
  • @JoachimPileborg 这是Keil编译器的符号

标签: c debugging microcontroller 8051


【解决方案1】:

1.首先你应该为#include指令使用以下2个选项之一

#include  "path-spec"
#include  <path-spec>

,而不是 #include path-spec,就像你做的那样

2.配置P1通用I/O口的第7位工作在推挽模式下需要设置

P1MDOUT = 0x80;

,不是

P1MDOUT = 0x40;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-21
    • 2010-12-28
    相关资源
    最近更新 更多