Re: 請教GPS To Uart Receive By PIC24F
|
||||
---|---|---|---|---|
初級會員
|
真的很不好意思...又來不恥下問
我閱讀過Microchip PIC24F Peripheral Library.chm之後再去更改,還是不能!! 用中斷來檢查,結果是不能中斷!! 在執行debugger run中 觀察 View -> watch -> RX_Buff 一直為Reserved Memory 方便幫我看看哪裡設定出錯嗎??感謝!! void UART1_Initial(void) { // Important system variable -> "__C30_UART" // 1 = UART1 // 2 = UART2 if using printf to output data to "stdout" int config1 , config2 ; // **************************************************** // 設定 UART1 RX = RP10 -> Pin31 // 設定 UART1 TX = RP17 -> Pin32 // **************************************************** PPSUnLock ; iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP10); iPPSOutput(OUT_PIN_PPS_RP17,OUT_FN_PPS_U1TX); config1 = UART_EN & UART_IDLE_CON \ & UART_DIS_WAKE & UART_EN_LOOPBACK \ & UART_EN_ABAUD & UART_NO_PAR_8BIT & UART_1STOPBIT \ & UART_IrDA_DISABLE & UART_MODE_SIMPLEX & UART_UEN_00 \ & UART_UXRX_IDLE_ONE & UART_BRGH_FOUR ; config2 = UART_INT_TX_BUF_EMPTY & UART_SYNC_BREAK_DISABLED & UART_TX_ENABLE \ & UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR \ & UART_IrDA_POL_INV_ZERO ; // ********************************************************** // 設定 UART 為 4800 bps // CPU Fosc = 8 Mhz -> Fcy = 4Mhz // ********************************************************** OpenUART1 ( config1 , config2 , 51 ) ; ConfigIntUART1(UART_RX_INT_EN & UART_TX_INT_EN) ; Ctrl_U1RX = INPUT ; Ctrl_U1TX = OUTPUT ; PPSLock ; } Attach file: Link only for registered users
發表於: 2009/9/16 22:47
|
|||
|
Re: 請教GPS To Uart Receive By PIC24F
|
||||
---|---|---|---|---|
版主
|
那就無關 LCD 的函數問題,兩種可能:
1. PPS腳位設定錯誤 2. UART 設定錯誤 參考一下網路學園的範例程式 : PPS & UART http://www.microchip.com.tw/modules/xoopsfaq/index.php?cat_id=10 PPS 的說明及使用範例 - 使用 UART 為範例: 但是 , PPS 功能超有彈性確對初學者有一些小難 ! 所以本教材將 PPS 的概念, 初步的使用範例以及 MPLAB C30 Peripheral Library 的 PPS support 一一的介紹. 希望能加快與簡化您在使用 PPS 的工作.
發表於: 2009/9/15 10:51
|
|||
|
Re: 請教GPS To Uart Receive By PIC24F
|
||||
---|---|---|---|---|
初級會員
|
參照:
putsLCD(LCDString); <== 執行到這裡有顯示嗎? ANS:有的 LCDString 有顯示出來!! 就是 if(UART_RX_Flag==1) // 判斷資料傳送狀態旗標 { LCD_SetCursor( 0,0); putsLCD(RX_Buff); UART_RX_Flag = 0 ; } 裡面沒執行出來,用中斷來檢查,結果是不能中斷!! 此外在執行debugger run中 觀察 View -> watch -> RX_Buff 一直為Reserved Memory 硬體方面 我有用示波器測量Pin31、DB2 確實有訊號進來 硬體接法: DB3 -> T1OUT , T1IN -> Pin32 DB2 -> R1IN , R1OUT -> Pin31 Attach file: (0.00 KB)
發表於: 2009/9/14 18:20
Edited by on 2009年09月14日 20:35:06
Edited by on 2009年09月14日 20:43:25 |
|||
|
Re: 請教GPS To Uart Receive By PIC24F
|
||||
---|---|---|---|---|
版主
|
參照:
while(1)
發表於: 2009/9/14 17:26
|
|||
|
Re: 請教GPS To Uart Receive By PIC24F
|
||||
---|---|---|---|---|
初級會員
|
懇求各位前輩指點....
經過小弟數次修正及檢查後 個人覺得LCD顯示不出資料是因為 UART資料沒有進來的樣子(有用中斷來檢查) 所以厚著臉皮...再次來請教各位前輩.. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Module Name : GPS Receiver * //DATE : 2009.08.11 * *****************************************************************************/ // 在程式內設定 Configuration Bits 的範例 // 需注意 : 要參考 Header file 中的可用定義 #include <p24FXXXX.h> #include "lcd.h" #include <timer.h> #include <adc.h> #include <outcompare.h> #include <pps.h> #include <uart.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 UART1_Initial(void) ; void ADC_Initial(void) ; void AD_Delay(void) ; void Timer1_Initial(void) ; void OC_Initial(void) ; #define INPUT 1 #define OUTPUT 0 #define Ctrl_U1RX TRISFbits.TRISF5 #define Ctrl_U1TX TRISFbits.TRISF3 char LCDString[] = "GPS Receive"; unsigned int ADC_TempValue ; unsigned char DataAvailable ; unsigned char RX_Temp,RX_Buff[90],LineCount = 0 ; char cnt=0,i ; int Timer1Tick = 0 ; unsigned int RPM = 0 ; unsigned UART_Timer = 0 ; unsigned UART_RX_Flag = 0; void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void) // UART1接收資料中斷副程式 { RX_Temp=RX_Buff[cnt]=ReadUART1(); // Get RS-232 data 將UART讀取資料暫存器的內容讀出 UART_RX_Flag = 1 ; IFS0bits.U1RXIF = 0 ; } void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void) { IFS0bits.T1IF = 0 ; Timer1Tick = 1 ; } int main(void) { LCD_Delay200usX(50) ; PMP_Initial() ; ADC_Initial() ; Timer1_Initial(); OC_Initial() ; UART1_Initial() ; LCD_Initial() ; while(1) { LCD_SetCursor( 0,0); putsLCD(LCDString); if(UART_RX_Flag==1) // 判斷資料傳送狀態旗標 { LCD_SetCursor( 0,0); putsLCD(RX_Buff); UART_RX_Flag = 0 ; } } } 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 UART1_Initial(void) { // Important system variable -> "__C30_UART" // 1 = UART1 // 2 = UART2 if using printf to output data to "stdout" int config1 , config2 ; // **************************************************** // 設定 UART1 RX = RP10 -> Pin31 // 設定 UART1 TX = RP17 -> Pin32 // **************************************************** PPSUnLock ; iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP10); iPPSOutput(OUT_PIN_PPS_RP17,OUT_FN_PPS_U1TX); config1 = UART_EN & UART_IDLE_CON & UART_DIS_WAKE & UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_NO_PAR_8BIT & UART_1STOPBIT; config2 = UART_INT_TX_BUF_EMPTY & UART_SYNC_BREAK_DISABLED & UART_TX_ENABLE & UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR & UART_IrDA_POL_INV_ZERO; // ********************************************************** // 設定 UART 為 4800 bps // CPU Fosc = 8 Mhz -> Fcy = 4Mhz // ********************************************************** OpenUART1 ( config1 , config2 , 51 ) ; ConfigIntUART1(UART_RX_INT_DIS & UART_TX_INT_DIS) ; Ctrl_U1RX = INPUT ; Ctrl_U1TX = OUTPUT ; PPSLock ; } 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 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; } 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 AD_Delay(void) { int LoopVar ; int LoopVar2 , LoopVar3 ; for ( LoopVar = 0 ; LoopVar < 100 ; LoopVar++ ) LoopVar2 = LoopVar3 + 1 ; } Attach file: (0.00 KB) Link only for registered users
發表於: 2009/9/13 21:49
|
|||
|
Re: 請教GPS To Uart Receive By PIC24F
|
||||
---|---|---|---|---|
版主
|
參照:
發表於: 2009/8/31 10:41
|
|||
|
Re: 請教GPS To Uart Receive By PIC24F
|
||||
---|---|---|---|---|
初級會員
|
不好意思...小弟愚昧...又失敗了
我使用 int main(void) { //省略 while(UART_RX_Flag) { LCD_SetCursor(0,1) ; LCD_PutChar(RxBuff[0]) ; // 先測一下 RxBuff[0], putrsLCD( ) 是送出 ROM 的字串,應該用 putLCD( ) 或 pursLCD( ) 才對 UART_RX_Flag=0; } } 結果並沒有顯示任何東西,且迴圈只做一次就停止 ==================================== 使用 int main(void) { //省略 while(1) { LCD_SetCursor(0,1) ; LCD_PutChar(RxBuff[0]) ; // 先測一下 RxBuff[0], putrsLCD( ) 是送出 ROM 的字串,應該用 putLCD( ) 或 pursLCD( ) 才對 UART_RX_Flag=0; } } 結果顯示1個黑色方塊(並非有8*5的黑色小點,而是8*5的黑色小點缺少2個黑色小點,也就是8*5的黑色方塊中有兩個白色的點) ==================================== 小弟想請教會是 void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void) // UART1接收資料中斷副程式 { RxBuff[0]=ReadUART1(); // Get RS-232 data 將UART讀取資料暫存器的內容讀出 UART_RX_Flag = 1; IFS0bits.U1RXIF = 0 ; } 出了問題嗎??我有用示波器量確實有訊號進來 另外Ryang版主所指點的 ==================================== LCD_SetCursor(0,1) ; putLCD(RxBuff[0]) ; // 先測一下 RxBuff[0], putrsLCD( ) 是送出 ROM 的字串,應該用 putLCD( ) 或 pursLCD( ) 才對 UART_RX_Flag=0; ==================================== 我在我的LCD.c檔沒看到putLCD( ) & pursLCD( ) 有LCD_PutChar()&putsLCD() 我使用putsLCD()在while(1)中並沒有顯示任何東西 使用LCD_PutChar()在while(1)中顯示黑色方塊 請問我使用LCD_PutChar()會是正確的嗎?
發表於: 2009/8/30 23:32
|
|||
|
Re: 請教GPS To Uart Receive By PIC24F
|
||||
---|---|---|---|---|
資深會員
|
一'
void U1RXInterrupt(void) void _ISR _T1Interrupt(void) 二' void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void) void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void) 請問中斷寫法一和二差在那裡?? 我都是用一的方式在寫中斷..用一的方式寫會造成什麼影響?? 以上..謝謝^^
發表於: 2009/8/28 23:46
|
|||
|
Re: 請教GPS To Uart Receive By PIC24F
|
||||
---|---|---|---|---|
資深會員
|
請教typhoon兄,如何以HEX模式來開起.RAR,我不懂你說的方式,想了解一下,請您指點!
發表於: 2009/8/25 15:49
|
|||
|