Re: 數位輸出入阜 按鍵開關問題
|
||||
---|---|---|---|---|
初級會員
|
參照:
哈 按下去是Low 我現在遇到一個新的問題!! 我想要的是 按"一"下S1後 LCD 顯示 PUSH S1 接著回歸 NO PUSH 執行結果確實有顯示 PUSH S1 但 Delay 微小時間後 會變成 NO PUSH 形成 PUSH S1與NO PUSH 交互顯示 若再按"一"下S2 則變成 PUSH S2與NO PUSH 交互顯示 請問這會是甚麼原因?? 主程式我改成 int main(void) { LCD_Delay200usX(50) ; ADC_Initial() ; PMP_Initial() ; Timer1_Initial(); OC_Initial() ; LCD_Initial() ; IOInit() ; while(1) { LCD_SetCursor(0,0); putsLCD(LCDString); LCD_Delay200usX(500) ; LCD_SetCursor(0,1); putsLCD(LCDString); LCD_Delay200usX(500) ; ReadSwitch(); switch (Sw) { case 1: //S1 Pressed DisplayS1(); break ; case 2: //S2 Pressed DisplayS2(); break ; } PORTBbits.RB3 = 1 ; PORTBbits.RB5 = 1 ; } }
發表於: 2009/10/22 20:57
|
|||
|
Re: 數位輸出入阜 按鍵開關問題
|
||||
---|---|---|---|---|
版主
|
switch ( ) 可以中斷,哪只是代表程式可以執行到這裡,但下層的判斷式因條件不成立所以進不去。
看了一下你的程式 : if (PORTBbits.RB3 == 1) Sw = 1; if (PORTBbits.RB5 == 1) Sw = 2; 你的按鍵難不成按下去時是送 Hi 的嗎? 這跟一般的設計是不一樣的??? if (!PORTBbits.RB3) Sw = 1; if (!PORTBbits.RB5) Sw = 2; 加個 ! 的運算子吧!
發表於: 2009/10/21 11:21
|
|||
|
Re: 數位輸出入阜 按鍵開關問題
|
||||
---|---|---|---|---|
初級會員
|
nicecookie 你好
很抱歉我沒有詳細說明我的問題 Sorry debug -> Run 中 無按下任何按鍵 LCD螢幕顯示 NO PUSH 按下 S1 LCD螢幕顯示 NO PUSH 按下 S2 LCD螢幕顯示 NO PUSH 按下任何按鍵 LCD螢幕顯示 NO PUSH 用中斷檢查發現 switch (Sw) <==若在此設為中斷點,則可以中斷 。 { case 1: //S1 Pressed DisplayS1(); <==若在此設為中斷點,則不能中斷 。 break ; case 2: //S2 Pressed DisplayS2(); break ; } 用watch 觀看Sw的值 無論按下S1、S2等任何按鍵 Sw的值 均為0x00 並無變化 不曉得 這樣的資料夠不夠齊全? Attach file: (0.00 KB)
發表於: 2009/10/20 20:43
|
|||
|
Re: 數位輸出入阜 按鍵開關問題
|
||||
---|---|---|---|---|
資深會員
|
SORRY,其實我也看不懂那個程式
所以我不是來回答問題的 比較好奇的是 關於debug,大哥你進行了哪些? 或許可以提供想回答的人參考 這樣也節省您的寶貴時間 還是....不會動沒反應,就一股腦的上來發問呢?
發表於: 2009/10/20 13:31
|
|||
|
數位輸出入阜 按鍵開關問題
|
||||
---|---|---|---|---|
初級會員
|
使用PIC24FJ128GB106
按下按鍵開關SW1 ,LCD顯示 "PUSH S1" 按下按鍵開關SW2 ,LCD顯示 "PUSH S2" 編譯沒問題 但是當我按下任何按鍵開關 均無反應!! 請問有可能是哪邊出了問題?? 已參考過203_PRC 的 203Lab3 ========================================== #include <p24FXXXX.h> #include "lcd.h" #include <timer.h> #include <adc.h> #include <outcompare.h> #include <pps.h> #include <stdio.h> _CONFIG2(IESO_OFF & POSCMOD_HS & FNOSC_PRI& FCKSM_CSDCMD & PLLDIV_DIV2 ) _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & ICS_PGx2 & FWDTEN_OFF & WINDIS_OFF ) void PMP_Initial(void) ; void ADC_Initial(void) ; void Timer1_Initial(void) ; void OC_Initial(void) ; void DisplayS1(void) ; void DisplayS2(void) ; void IOInit(void) ; void ReadSwitch(void) ; #define INPUT 1 #define OUTPUT 0 #define Ctrl_U1RX TRISFbits.TRISF5 #define Ctrl_U1TX TRISFbits.TRISF3 #define S1 PORTBbit.RB3 #define S2 PORTBbit.RB5 unsigned char LCDString[] = "NO PUSH"; unsigned char LCDString1[] = "PUSH S1"; unsigned char LCDString2[] = "PUSH S2"; char Sw ; unsigned int Timer1Tick = 0,i = 0 ; unsigned int RPM = 0 ; unsigned UART_Timer = 0 ; void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void) { IFS0bits.T1IF = 0 ; Timer1Tick = 1 ; } int main(void) { LCD_Delay200usX(50) ; ADC_Initial() ; PMP_Initial() ; Timer1_Initial(); OC_Initial() ; LCD_Initial() ; IOInit() ; LCD_SetCursor(2,0); putsLCD(LCDString); LCD_Delay200usX(500) ; while(1) { ReadSwitch(); switch (Sw) { case 1: //S1 Pressed DisplayS1(); break ; case 2: //S2 Pressed DisplayS2(); break ; } } } void DisplayS1(void) //顯示PUSH S1 { LCD_Delay200usX(50) ; LCD_SetCursor(0,0); putsLCD(LCDString1) ; LCD_Delay200usX(1000) ; } void DisplayS2(void) //顯示PUSH S2 { LCD_Delay200usX(50) ; LCD_SetCursor(0,1); putsLCD(LCDString2) ; LCD_Delay200usX(1000) ; } void IOInit(void) { AD1PCFG=0xffff ; TRISB = 0xffff ; TRISBbits.TRISB3 = 1; // S1 TRISBbits.TRISB5 = 1; // S2 } void ReadSwitch(void) { if (PORTBbits.RB3 == 1) Sw = 1; if (PORTBbits.RB5 == 1) Sw = 2; } void OC_Initial(void) { PR2 = 4096 ; T2CON = 0x8000 ; OC1CON1 = 0x000e ; OC1CON2 = 0x001f ; OC1R = 0 ; OC1RS = 1023 ; // Set RP2 as OC1 output !! // RP2 @ RD8 TRISDbits.TRISD8 = OUTPUT ; iPPSOutput(OUT_PIN_PPS_RP2,OUT_FN_PPS_OC1); } void Timer1_Initial(void) { // To make a 10 ms Timer @ Fosc = 8 Mhz -> Fcy = 4Mhz // Select 1:8 prescaler , Freq to Timer1 = 500 K -> 2 us // 10ms = 10000 us , 10000 us / 2 us = 5000 // So, PR1 = 4999 for a 10 ms Timer OpenTimer1( T1_ON & T1_IDLE_CON & T1_PS_1_8 & T1_SYNC_EXT_OFF & T1_GATE_OFF & T1_SOURCE_INT , 4999 ); ConfigIntTimer1(T1_INT_PRIOR_4 & T1_INT_ON) ; } void ADC_Initial(void) { AD1CON1 = 0b0000000000000110 ; // Mode : Clear SAMP start conversion // ASAM = 1 --> SAMP auto set AD1CON2 = 0b0000000000000000 ; AD1CON3 = 0b1000001100001111 ; // Internal RC as AD Clock AD1CHS = 0x00 ; // Use AN0 temporary AD1PCFG = 0b1111111111111011 ; // AN2 enabled AD1CON1bits.ADON = 1 ; } void PMP_Initial(void) { //******************************************************************************** // STEP 1: // Configure PMPCON: PMP on, address/data not multiplexed, PMPBE active high, // PMPWR I/O, PMPRD I/O, 8-bit data, PMPENB and PMPRD/~PMPWR active high. //********************************************************************************/ // PMCON = ; // Exer1 PMCON = 0b1000001100000111; //******************************************************************************** // STEP 2: // Configure PMPMODE: Interrupts, stall, buffers, inc/dec off, 8 bit mode, // combined read/write with byte enable signals, and max the 3 wait delays. //********************************************************************************/ // PMMODE = ; // Exer1 PMMODE = 0x23FF; //******************************************************************************** // STEP 3: // Configure PMAEN: Enable A0 function to control RS and disable all other // PMP address pins. //********************************************************************************/ // PMAEN = ; // Exer1 PMAEN = 0x0001; //******************************************************************************** // STEP 4: // Configure PMPADDR: A0 selects type of instruction, either command or data. // This is a command so A0 should be low. //********************************************************************************/ // PMADDR = ; // Exer1 PMADDR = 0x0000; } Attach file: Link only for registered users
發表於: 2009/10/20 13:03
|
|||
|