2014-01-14 23 views
1

希望我可以在這裏問我的問題。 我從這個網站建立了一個拍手http://embedded-lab.com/blog/?p=6439 他使用了PIC12F683,但是我使用了PIC16F628,所以我使用了它。 我不知道是否有人可以幫助醫學的C代碼?如果我將電線連接到正確的引腳,請糾正我。 我試圖讀取PIC,引腳上的數據表以及如何更改配置位,但我很難完全理解它。克拉珀,改變配置位C

我從網站上連接了這樣的引腳。

T1和R10K連接到RA2, GND連接到Vss, + 5V被連接到Vdd, LED和R330連接到RB6。

這是我的更改的代碼。

//sbit Output_LED at GP5_bit; on the original code 
#define Output_LED PORTD.F3; 

//sbit led_led at PORTc.c2; 
unsigned short i, TIME_UP; 

void interrupt(void){ 
if(PIR1.TMR1IF){ 
    i ++; 
    if(i == 3) TIME_UP = 1; // Time Up in 1.5 sec 
    PIR1.TMR1IF = 0; 
    } 
} 

void main() { 
    TRISIO = 0b00000011 ; 
    //ANSEL = 0x00; on the original code 
    INTCON = 0b11000000 ; // Enable GIE and PEIE for Timer1 overflow interrpt 
    PIE1 = 0b00000001 ; // Enable TMR1IE 

    // Configure Comparator module 
    // CIN- pin is configured as analog, 
    // CIN+ pin is configured as I/O, 
    // COUT pin is configured as I/O, 
    // Comparator output available internally, 
    // CVREF is non-inverting input 
    // CINV is set to 1 

    COMCON = 0b00010100; 
    VRCON = 0b10100011; // Vref is set to VDD/8 
    Output_LED = 0; 
    do{ TMR1H = 0x00; 
    TMR1L = 0x00; 
    TIME_UP = 0; 
    i = 0; 
    T1CON = 0b00110000; // Configure Timer 1 
    if(CMCON0.COUT){ // First clap detected 
     Delay_ms(100); 
     T1CON.TMR1ON = 1; // Start Timer1 
     while(!COMCON.COUT && !TIME_UP); // Wait until second clap is 
     T1CON.TMR1ON = 0; // detected or Timer1 overflows 
     if(COMCON.COUT && !TIME_UP) Output_LED = ~Output_LED; 
     Delay_ms(100); 
    } 
    } while(1); 
} 




//- See more at: http://embedded-lab.com/blog/?p=6439#sthash.YHvZk7SY.dpuf 

該錯誤消息時,我建我得到的是:

Clean: Deleting intermediary and output files. 
Clean: Done. 
Executing: "C:\Program Files (x86)\PK2proj\Cc5x\CC5X.EXE" clapper.c -CC -fINHX8M -p16F628 -a -L -Q -V -FM 
CC5X Version 3.3A, Copyright (c) B Knudsen Data, Norway 1992-2007 
--> FREE edition, 8-16 bit int, 24 bit float, 1k code, reduced optim. 
clapper.c: 

void first_interrupt(void){ 
    if(PIR1.TMR2IF){ 
       ^------ 
Error[1] C:\Program Files (x86)\PK2proj\Work\clapper.c 31 : Syntax error 
(The expression must be corrected. The marker ^------ shows 
the approximate position where CC5X gives up. The documentation 
should be checked if the cause is not obvious) 

Error options: -ew: no warning details -ed: no error details -eL: list details 
BUILD FAILED: Wed Jan 15 01:36:50 2014 

(我使用的MPLAB IDE 8.92,的PICkit 3,B克努森數據CC5X)

我會真的心存感激。如果有人可以幫助我:)

+0

我們需要更多信息。究竟是什麼失敗?輸出始終打開,始終關閉?你是否能夠在代碼上使用調試器並確定它是否檢測到拍子?同樣,改進縮進和換行(就像在原始代碼中一樣)會使它更容易理解。 –

+0

感謝您的回覆。 我已修復代碼並添加了我的錯誤消息。我無法調試它(因爲代碼是錯誤的,所以我不知道)。 我是新的編程和它會很有趣和這個項目的教育:) – Nojman

+0

對不起,我不能幫你太多。我見過的PIC代碼是在彙編中,這是一個編譯器問題。它看起來就像它失敗的行上的例子,但他使用MikroC Pro編譯器,而您使用的是Knudsen Data編譯器。這可能是不同之處。打開Knudsen的網站,看看你能找到什麼中斷。順便說一句,我希望你熟悉電子學,因爲一起學習硬件和軟件可能會很艱難。如果你只想學習軟件,VS Express的一些C#例子可能是一個選擇。 –

回答

0

我相信你需要使用PIR1bits.TMR2IF而不是PIR1.TMR2IF

我不熟悉Knudsen編譯器。如果這不起作用,請讓我知道這裏,我會包括其他方法。