• slider image 442
  • slider image 477
  • slider image 479
  • slider image 480
  • slider image 481
  • slider image 482
:::


Browsing this Thread:   1 Anonymous Users




(1) 2 3 4 »


Re: 請教GPS To Uart Receive By PIC24F
#39
初級會員
初級會員


查看用戶資訊
本人以成功截取到GPS訊號
再次感謝所以觀看及回復我問題的人
將此檔案放在網路上供給需要的人做參考
GPS To Uart Receive By PIC24FJ218GB106

Attach file:


Link only for registered users

發表於: 2009/10/7 23:34
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教GPS To Uart Receive By PIC24F
#38
初級會員
初級會員


查看用戶資訊
首先 我要感謝所以觀看及回覆我的問題的前輩
因為你們,我才得以進步,找出問題,解決方法!!
目前我已經可以做到接收GPS訊號並顯示資料!!
但卻跑出顯示的資料為亂碼!!(像是'['、'^'、日文、奇形怪狀的文字)
距離成功只差臨門一腳!!!
各位前輩方便的話,請幫我看看哪邊出錯導致顯示資料的時候為亂碼!!
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Module Name : GPS Receiver *
//DATE : 2009.08.11 *

*****************************************************************************/

#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) ;
void RX_ArrayDisplay(unsigned char *data) ;

#define INPUT 1
#define OUTPUT 0

#define Ctrl_U1RX TRISFbits.TRISF5
#define Ctrl_U1TX TRISFbits.TRISF3

unsigned char LCDString[] = "GPS Receive";

unsigned int ADC_TempValue ;

short int RX_int,RX_intArray[16] ;
unsigned char RX_Test,RX_DATA,RX_ARRAY[16],LineCount = 0 ;
unsigned char cnt=0;

unsigned int Timer1Tick = 0,i = 0 ;
unsigned int RPM = 0 ;
unsigned UART_Timer = 0 ;
unsigned char UART_RX_Flag = 0 ;


void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void) // UART1接收資料中斷副程式
{
IFS0bits.U1RXIF = 0 ; // 清除中斷旗標
RX_DATA = ReadUART1(); // Get RS-232 data 將UART讀取資料暫存器的內容讀出
RX_ARRAY[cnt] = RX_DATA ;
if (cnt > 14)
UART_RX_Flag = 1 ; // 設定接收狀態旗標為1
else
{
cnt++ ;
UART_RX_Flag = 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() ;

LCD_SetCursor(2,0);
putsLCD(LCDString);

while(1)
{
if(UART_RX_Flag == 1) // 判斷資料傳送狀態旗標
{
RX_ArrayDisplay(RX_ARRAY) ; //顯示RX_Array
LCD_Delay200usX(500) ;

UART_RX_Flag = 0 ; // 設定接收狀態旗標為0
cnt = 0 ;
}
}
}

void RX_ArrayDisplay(unsigned char *data) //顯示RX_Array
{
LCD_Delay200usX(50) ;
LCD_SetCursor( 0,1);
putsLCD(data) ;
LCD_Delay200usX(1000) ;
}


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"

unsigned int U1MODEvalue;
unsigned int U1STAvalue;

// ****************************************************
// 設定 UART1 RX = RP10 -> Pin31
// 設定 UART1 TX = RP17 -> Pin32
// ****************************************************

PPSUnLock ;
CloseUART1();

ConfigIntUART1(UART_RX_INT_EN & UART_RX_INT_PR6 &
UART_TX_INT_DIS & UART_TX_INT_PR2);

iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP10);
iPPSOutput(OUT_PIN_PPS_RP17,OUT_FN_PPS_U1TX);

U1MODEvalue = UART_EN & UART_IDLE_STOP &
UART_EN_WAKE & UART_DIS_LOOPBACK &
UART_DIS_ABAUD & UART_NO_PAR_8BIT &
UART_1STOPBIT & UART_IrDA_DISABLE &
UART_UEN_00 & UART_BRGH_SIXTEEN;

U1STAvalue = 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 為 4800 bps
// CPU Fosc = 8 Mhz -> Fcy = 4Mhz
// **********************************************************
OpenUART1 ( U1MODEvalue , U1STAvalue , 51 ) ;
//ConfigIntUART1(UART_RX_INT_EN & UART_TX_INT_EN) ;

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 ;
}

Attach file:


Link only for registered users

發表於: 2009/10/7 15:20
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教GPS To Uart Receive By PIC24F
#37
資深會員
資深會員


查看用戶資訊
以這個函式來看,這一行的寫法應該是錯的。
因為函式的原型是以字元指標為引數,但是您呼叫它時給它的卻是字元(不是字元陣列)
putsLCD(RX_ARRAY[0]);
我認為應該改成
putsLCD(RX_ARRAY);//<--這樣才是對的
另外這個函式是以判斷\0為停止條件
所以您傳給這個函式必需是字串(就是字元陣列後面要加\0)而不是字元陣列,不然如果這個字元陣列都以後的記憶體空間裡都沒有\0的話,那就沒完沒了了。

參照:

黃金葛 寫道:
TO : biko兄
很感謝妳回覆我的問題!!
putsLCD(RX_ARRAY[0]) ;<--這一行Compile可以過!!
putsLCD()函式
void putsLCD(unsigned char *TheString)
{
while( *TheString != 0x00 )
{
while ( LCD_IsBusy()) ;
LCD_PutChar(*TheString++ ) ;
}
}

發表於: 2009/10/7 9:01
我相信解決問題的方法不只一種,所以我在回答同好的問題時或者提出與主題不同的方案,
請不要以此做為攻擊的目標,畢竟我也只是想和大家討論如何解決問題而已…
解決問題最重要,.....
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教GPS To Uart Receive By PIC24F
#36
初級會員
初級會員


查看用戶資訊
TO : biko兄
很感謝妳回覆我的問題!!
putsLCD(RX_ARRAY[0]) ;<--這一行Compile可以過!!
putsLCD()函式
void putsLCD(unsigned char *TheString)
{
while( *TheString != 0x00 )
{
while ( LCD_IsBusy()) ;
LCD_PutChar(*TheString++ ) ;
}
}

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


Re: 請教GPS To Uart Receive By PIC24F
#35
資深會員
資深會員


查看用戶資訊
while(1)
{
if(UART_RX_Flag == 1) // 判斷資料傳送狀態旗標
{
RX_ARRAY[cnt] = RX_DATA ;
UART_RX_Flag = 0;//<--要放這裡
if(cnt = 15)
{
LCD_Delay200usX(50) ;
LCD_SetCursor( 0,1);
LCD_PutChar(RX_ARRAY[0]) ;
putsLCD(RX_ARRAY[0]) ;<--這一行Compile能過哦?
LCD_Delay200usX(300) ;
cnt = 0 ;
}
else
{
cnt++;
//UART_RX_Flag = 0;<--不應該放這裡
}
}
}

PS.字串是一種字元陣列,但是字元陣列不一定是字串,我不知道putsLCD()這個函式是怎麼寫的,但是您要注意一下…RX_ARRAY[]是否有'\0'

發表於: 2009/10/2 17:26
我相信解決問題的方法不只一種,所以我在回答同好的問題時或者提出與主題不同的方案,
請不要以此做為攻擊的目標,畢竟我也只是想和大家討論如何解決問題而已…
解決問題最重要,.....
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教GPS To Uart Receive By PIC24F
#34
初級會員
初級會員


查看用戶資訊
再請教一個問題....
我使用 ReadUART1 Function
This function returns the contents of Receive buffer (UxRxREG) register
我用watch 觀看 U1RXREG 值為 0x009D
但經過
unsigned char RX_DATA ;
RX_DATA = ReadUART1() ;
用watch 觀看 RX_DATA 值為 0x71
請問2個byte(U1RXREG)給到1個byte(char)這是如何換算解碼的??
若 U1RXREG 值為 0x009D
經過
short int RX_int ;
RX_int = ReadUART1() ;
用watch 觀看 RX_int 值為 0x0093
請問2個byte(U1RXREG)給到2個byte(short int)
照道理說 他們值應該會是一樣的不是嗎??

發表於: 2009/10/2 14:08
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教GPS To Uart Receive By PIC24F
#33
初級會員
初級會員


查看用戶資訊
經過我修改檢查後
已經可以接收到資料,U1STA的bit2 為'0',0 = Framing error has not been detected

我想請問
LCD_PutChar(RX_ARRAY[0]); 執行結果為亂碼一直變跟(但有規律)
putsLCD(RX_ARRAY[0]) ; 執行結果為DDdB 有時會變成DDDD
明明就是同一個value
為什麼顯示出來會差很多??

=============程式大致如下=================
#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 UART1_Initial(void) ;
void OC_Initial(void) ;

#define INPUT 1
#define OUTPUT 0

#define Ctrl_U1RX TRISFbits.TRISF5
#define Ctrl_U1TX TRISFbits.TRISF3

unsigned char LCDString[] = "GPS Receive";

unsigned int ADC_TempValue ;

unsigned char RX_DATA,RX_ARRAY[16],LineCount = 0 ;
unsigned char cnt=0;

unsigned int Timer1Tick = 0,i = 0 ;
unsigned int RPM = 0 ;
unsigned UART_Timer = 0 ;
unsigned char UART_RX_Flag = 0 ;


void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void) // UART1接收資料中斷副程式
{
IFS0bits.U1RXIF = 0 ; // 清除中斷旗標
RX_DATA = ReadUART1(); // Get RS-232 data 將UART讀取資料暫存器的內容讀出

UART_RX_Flag = 1 ;
}

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() ;

LCD_SetCursor(2,0);
putsLCD(LCDString);

while(1)
{
if(UART_RX_Flag == 1) // 判斷資料傳送狀態旗標
{
RX_ARRAY[cnt] = RX_DATA ;
if(cnt = 15)
{
LCD_Delay200usX(50) ;
LCD_SetCursor( 0,1);
LCD_PutChar(RX_ARRAY[0]) ;
putsLCD(RX_ARRAY[0]) ;
LCD_Delay200usX(300) ;
cnt = 0 ;
}
else
{
cnt++;
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"

unsigned int U1MODEvalue;
unsigned int U1STAvalue;

// ****************************************************
// 設定 UART1 RX = RP10 -> Pin31
// 設定 UART1 TX = RP17 -> Pin32
// ****************************************************

PPSUnLock ;
CloseUART1();

ConfigIntUART1(UART_RX_INT_EN & UART_RX_INT_PR6 &
UART_TX_INT_DIS & UART_TX_INT_PR2);

iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP10);
iPPSOutput(OUT_PIN_PPS_RP17,OUT_FN_PPS_U1TX);

U1MODEvalue = UART_EN & UART_IDLE_STOP &
UART_EN_WAKE & UART_DIS_LOOPBACK &
UART_DIS_ABAUD & UART_NO_PAR_8BIT &
UART_1STOPBIT & UART_IrDA_DISABLE &
UART_UEN_00 & UART_BRGH_SIXTEEN;

U1STAvalue = 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 為 4800 bps
// CPU Fosc = 8 Mhz -> Fcy = 4Mhz
// **********************************************************
OpenUART1 ( U1MODEvalue , U1STAvalue , 51 ) ;
//ConfigIntUART1(UART_RX_INT_EN & UART_TX_INT_EN) ;

Ctrl_U1RX = INPUT ;
Ctrl_U1TX = OUTPUT ;

PPSLock ;

}

發表於: 2009/10/2 9:30
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教GPS To Uart Receive By PIC24F
#32
資深會員
資深會員


查看用戶資訊
其實要注意的是你的信號是跑TTL信號還是RS232信號
然後根據信號看是否須MAX232作處理

可參考五南書局 黃東正寫的書
裡面有介紹GPS的部份

發表於: 2009/9/26 11:08
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教GPS To Uart Receive By PIC24F
#31
初級會員
初級會員


查看用戶資訊
參照:

cct1210 寫道:
我有點困惑,理論上應該是GPS的TX有+5/-5V的訊號變化,然後經過Transceiver後,在PIC24的RX接腳有0/5V的訊號變化.
所以你的RX腳位有訊號,訊號是+5V/-5V 上下跳,有點奇怪,你要不要量一下PIC24的RX接腳呢?


cct1210兄 你是對的!!
我量DB-2的訊號是+5V/-5V 上下跳 但經過MAX232轉換後訊號為0/5V上下跳!!

發表於: 2009/9/26 9:38
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教GPS To Uart Receive By PIC24F
#30
資深會員
資深會員


查看用戶資訊
參照:

黃金葛 寫道:
TO cct1210兄:
我有用示波器測量,只有RX腳位有訊號
訊號是+5V/-5V 上下跳
應該就是你所說的 要先使用Transceiver轉換後才能與PIC24FJ溝通吧!? 是嗎??
非常感謝你的經驗相談~~讓我又學到東西!!再次感謝妳~


我有點困惑,理論上應該是GPS的TX有+5/-5V的訊號變化,然後經過Transceiver後,在PIC24的RX接腳有0/5V的訊號變化.
所以你的RX腳位有訊號,訊號是+5V/-5V 上下跳,有點奇怪,你要不要量一下PIC24的RX接腳呢?

發表於: 2009/9/25 20:44

Edited by cct1210 on 2009年09月25日 21:14:02
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... ]

教育訓練中心

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