2013-12-18 117 views
-1

我不是很擅长C语言,但我写了一个非常简单的代码给C8051F312微控制器。 我的代码无法使用。请帮助我,我错了什么。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 
    } 
} 
+2

*如何*不代码工作?预期的结果是什么?什么是实际结果?您确定要在'LED_16'的初始化中使用XOR操作吗? –

+0

请发布*实际*代码,而不是近似值 - 上面的代码甚至没有编译。 –

+0

p1^7不是XOR操作,它声明了P1端口(它是一个led)的7.位,我想打开led。和它的实际代码... – user3114492

回答

2

所有1.首先,你应该使用的2个下列选项之一#include指令

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

,不#include path-spec,像你一样

2.To configuire P1一般的第7位I/O端口在推挽模式下工作,您应该设置为

P1MDOUT = 0x80;

,不

P1MDOUT = 0x40;