【发布时间】: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