Re: 關於GPS TO USART RECEIVE
|
||||
---|---|---|---|---|
資深會員
|
嗯,我了解您的意思,但是為何我送出一連串的字,照理來說,
應該就可以跑好幾次中斷了,為何還是只能收第一個字而已, 真苦惱!!
發表於: 2009/5/28 11:48
|
|||
|
Re: 關於GPS TO USART RECEIVE
|
||||
---|---|---|---|---|
資深會員
|
沒測過,試試先....cnt是全域變數。
void RX_isr(void)
發表於: 2009/5/27 22:44
|
|||
不要問我哪裡來,我只是個流浪天涯的工程師
|
||||
|
Re: 關於GPS TO USART RECEIVE
|
||||
---|---|---|---|---|
資深會員
|
我大概了解您的意思,
只是我目前用1byte的方式來收,但只能收一次, 一直找不到哪邊有問題,為什麼收了一次之後就不能再收了! 不好意思,因為是新手,問的問題會很白癡,但很感謝您的回答! 謝謝!
發表於: 2009/5/27 22:37
|
|||
|
Re: 關於GPS TO USART RECEIVE
|
||||
---|---|---|---|---|
資深會員
|
這和你前面的問題不是一樣嗎
當然都是1byte接1byte 的接收進來 只是你收的時間點不對 要ˋ中斷一次,收1byte, 回主程式等待下一次中斷 然後又產生中斷,又收1byte 然後又回主程式 如此反覆,直到整串資料收完 收完後 才開始處理、分析資料
發表於: 2009/5/27 22:34
|
|||
|
Re: 關於GPS TO USART RECEIVE
|
||||
---|---|---|---|---|
資深會員
|
謝謝您~
還有請教您如果我在電腦上傳送一連串的字串, 如"123"的話要怎麼收進來?
發表於: 2009/5/27 22:15
|
|||
|
Re: 關於GPS TO USART RECEIVE
|
||||
---|---|---|---|---|
資深會員
|
參照:
一次USART中斷只能接收一個byte資料 不能一次中斷要收那麼多的 你這樣寫的話應該只有第一byte有資料, 後面都會是 0
發表於: 2009/5/27 21:56
|
|||
|
Re: 關於GPS TO USART RECEIVE
|
||||
---|---|---|---|---|
資深會員
|
程式如下,請各位高手指點
//*********************************************** //Module Name : GPS Receiver * //DATE : 2009.05.21 * //WRITER : Edison Yu * //Last modify : 2009.05.21 PM 23:00 * //*********************************************** //*********************************************** /* Include Header files */ //*********************************************** #include <p18f4520.h> #include <usart.h> #include <stdlib.h> #include <ctype.h> #include <timers.h> #include <delays.h> #include "evm_lcd.h" #pragma config OSC=HS,BOREN=OFF,BORV=2,PWRT=ON,WDT=OFF,LVP=OFF void InitializePORT(void); void InitializeUSART(void); void InitializeINTS(void); void high_interrupt(void); void RX_isr(void); void LcdDisplay(const rom char *data); void RXDisplay(const rom char *data); // 狀態旗標變數 struct Flag{ unsigned RxD :1; // USART Rx Flag } FLAGbits; /* define the LCD_MSG1[] in program memory at 0x1000 */ //***************************************************** #pragma romdata My_romdata=0x1000 const rom char Lcd_Msg1[]="HOLUX GPS RECEIVER"; #pragma romdata /* define following variable in data memory at Access Bank */ //*********************************************************** #pragma udata access My_RAM_2 #define BuffLen 16 // 定義緩衝區長度 unsigned char RxBuff[BuffLen]; unsigned char LineCount = 0; char Hex_ASCII_Code(char DATA); void main(void) { unsigned char cnt; InitializePORT(); InitializeINTS(); InitializeUSART(); OpenLCD(); LcdDisplay(Lcd_Msg1); Delay10KTCYx(1000); // 時間延遲 WriteCmdLCD(0x01); while(1) { if(FLAGbits.RxD==1) { for(cnt=0;cnt<32;cnt++) { RXDisplay( RxBuff[cnt]); Delay10KTCYx(1000); } } } } //************************************************ //* #pragma Interrupt Declarations * //************************************************ //************************************************ //* Function: isr_high_direct * //* - Direct execution to the actual * //* high-priority interrupt code. * //************************************************ #pragma code high_vector =0x08 void high_interrupt(void) { _asm //begin in-line assembly goto RX_isr //go to isr_high function _endasm //end in-line assembly } #pragma code //************************************************ //* Function: isr_high(void) * //* High priority interrupt will * //* - Received a serial data from RS-232 * //* Save the received data to buffer Rec_Data* //************************************************ #pragma interrupthigh RX_isr void RX_isr(void) { unsigned char cnt; PIR1bits.RCIF=0; // 清除中斷旗標 for(cnt=0;cnt<BuffLen;cnt++) { RxBuff[cnt]=ReadUSART(); // Get RS-232 data } FLAGbits.RxD=1; // 設定旗標 } //************************************************ //* Function: InitializePORT * //* - Make PORTD all outputs * //* - Turn 0ff all the LED's * //************************************************ void InitializePORT(void) { TRISD=0X00; PORTD=0X00; } //************************************************ //* Function: Initialize USART * //* - Initialize the RS-232 communication * //* - Disable Interrupr for TxD * //* - Enable Interrupt fro Rxd * //* - Format: 4800, N, 8, 1 * //************************************************ void InitializeUSART(void) { int j; OpenUSART( USART_TX_INT_OFF // Set TXSTA Reg. =0b00100100 & USART_RX_INT_ON // Set RCSTA Reg. =0b10010000 & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH // Set SPBRG=31, Baud Rate = 4800 ,64); RCSTAbits.SPEN=1; TRISCbits.TRISC7=1; // Set input for RXD TRISCbits.TRISC6=0; // Set output for TXD PIE1bits.TXIE=0; PIR1bits.RCIF=0; // 清除中斷旗標 IPR1bits.RCIP=1; // Set Receive of USART are High priority PIE1bits.RCIE=1; // Enable RxD Interrupt FLAGbits.RxD=0; for(j=0;j<BuffLen;j++) RxBuff[j]=0; //清空 RevBuf } //************************************************ //* Function: Initialize Interrupts * //* - Reset All Interrupr * //* - Enable HIgh Priority Interrupt * //* - Disable Low Priority Interrupt * //************************************************ void InitializeINTS(void) { PIR1=0; PIR2=0; INTCON=0; INTCON2=0; INTCON3=0; PIE1=0; PIE2=0; RCONbits.IPEN=1; // Enable priority interrupts INTCONbits.GIEL=0; // Disable Low priority Interrupt INTCONbits.GIEH=1; // Enable high priority Interrupt } //************************************************ //* Function: HEX to DEC's ASCII_Code * //************************************************ char Hex_ASCII_Code(char Data) { if(Data<0x0a) return(Data+0x30); else return(Data+0x37); } //************************************************ //* LcdDisplay * //************************************************ void LcdDisplay(const rom char *data) { WriteCmdLCD( 0x01 ); // 清除LCD顯示資料 LCD_Set_Cursor( 0, 0 ); // 顯示位置回至第0行第0格 Delay10KTCYx(10); // 時間延遲 putrsLCD(data); // 顯示資料 Delay10KTCYx(10); // 時間延遲 } void RXDisplay(const rom char *data) { WriteCmdLCD( 0x01 ); // 清除LCD顯示資料 LCD_Set_Cursor( 0, 0 ); // 顯示位置回至第0行第0格 Delay10KTCYx(10); // 時間延遲 putcLCD(data); // 顯示資料 Delay10KTCYx(10); // 時間延遲 }
發表於: 2009/5/27 21:20
|
|||
不怕苦...苦半輩子;怕苦...苦一輩子
|
||||
|
Re: 關於GPS TO USART RECEIVE
|
||||
---|---|---|---|---|
資深會員
|
要不要把程式貼上來看比較快
發表於: 2009/5/27 19:13
|
|||
|
Re: 關於GPS TO USART RECEIVE
|
||||
---|---|---|---|---|
資深會員
|
這些範例我有參考,但問題來了,因為我送的是不固定的字串,
我目前無法顯示一連串的字,只能顯示第一個字,而且收了一次後,就無法繼續收了,一直找不到原因為何?
發表於: 2009/5/27 18:23
|
|||
|