• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users




(1) 2 »


Re: 關於GPS TO USART RECEIVE
#12
資深會員
資深會員


查看用戶資訊
嗯,我了解您的意思,但是為何我送出一連串的字,照理來說,
應該就可以跑好幾次中斷了,為何還是只能收第一個字而已,
真苦惱!!

發表於: 2009/5/28 11:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於GPS TO USART RECEIVE
#11
資深會員
資深會員


查看用戶資訊
沒錯, 就是像master 大那樣寫就對了,
當然, 可能還需要加上 如何判斷起始byte的程式


你程式問題出在這裡

for(cnt=0;cnt<BuffLen;cnt++)
{
RxBuff[cnt]=ReadUSART(); // Get RS-232 data
}



結果是1次中斷裡, 連續讀了RX buffer 16次, 結果除第1byte 外, 其他都是 0 對吧


因為讀完第1byte後, 後面資料根本還沒進來,
可是迴圈還是繼續run, 繼續要去跟rx buffer 拿資料
資料都還沒進來, 你又再去拿, 能拿到甚麼?
當然只能讀到 "空的" 資料 (0)

一定是1次中斷, 才代表 有1個byte資料進來

換句話說, 你要讀16byte 資料, 就必定要中斷16次



如果baud rate是9600的話 , 傳1byte資料進來至少要1ms
而執行接收程式的時間, 可能不到5us
剩餘的 995us, 就是繼續等待中斷的來到

發表於: 2009/5/27 23:04

Edited by nicecookie on 2009年05月28日 01:05:03
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於GPS TO USART RECEIVE
#10
資深會員
資深會員


查看用戶資訊
沒測過,試試先....cnt是全域變數。

void RX_isr(void)
    {
    
PIR1bits.RCIF=0// 清除中斷旗標
    
RxBuff[cnt++]=ReadUSART(); // Get RS-232 data
    
if(cnt>BuffLen-1){cnt=0;}
    
FLAGbits.RxD=1// 設定旗標
    
}

發表於: 2009/5/27 22:44
不要問我哪裡來,我只是個流浪天涯的工程師
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於GPS TO USART RECEIVE
#9
資深會員
資深會員


查看用戶資訊
我大概了解您的意思,
只是我目前用1byte的方式來收,但只能收一次,
一直找不到哪邊有問題,為什麼收了一次之後就不能再收了!
不好意思,因為是新手,問的問題會很白癡,但很感謝您的回答!
謝謝!

發表於: 2009/5/27 22:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於GPS TO USART RECEIVE
#8
資深會員
資深會員


查看用戶資訊
這和你前面的問題不是一樣嗎

當然都是1byte接1byte 的接收進來

只是你收的時間點不對

要ˋ中斷一次,收1byte,
回主程式等待下一次中斷
然後又產生中斷,又收1byte
然後又回主程式

如此反覆,直到整串資料收完
收完後 才開始處理、分析資料

發表於: 2009/5/27 22:34
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於GPS TO USART RECEIVE
#7
資深會員
資深會員


查看用戶資訊
謝謝您~
還有請教您如果我在電腦上傳送一連串的字串,
如"123"的話要怎麼收進來?

發表於: 2009/5/27 22:15
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於GPS TO USART RECEIVE
#6
資深會員
資深會員


查看用戶資訊
參照:


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; // 設定旗標
}


一次USART中斷只能接收一個byte資料
不能一次中斷要收那麼多的

你這樣寫的話應該只有第一byte有資料, 後面都會是 0

發表於: 2009/5/27 21:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於GPS TO USART RECEIVE
#5
資深會員
資深會員


查看用戶資訊
程式如下,請各位高手指點
//***********************************************
//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
不怕苦...苦半輩子;怕苦...苦一輩子
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於GPS TO USART RECEIVE
#4
資深會員
資深會員


查看用戶資訊
要不要把程式貼上來看比較快

發表於: 2009/5/27 19:13
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於GPS TO USART RECEIVE
#3
資深會員
資深會員


查看用戶資訊
這些範例我有參考,但問題來了,因為我送的是不固定的字串,
我目前無法顯示一連串的字,只能顯示第一個字,而且收了一次後,就無法繼續收了,一直找不到原因為何?

發表於: 2009/5/27 18:23
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------