2013-12-18 50 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;