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

論壇索引


Board index » All Posts (黃金葛)




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


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
頂部


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


再請教一個問題....
我使用 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
頂部


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


經過我修改檢查後
已經可以接收到資料,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
頂部


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


參照:

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
頂部


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


今天在UART與GPS連接後,run程式
用watch看U1STA的Value為0xC544(若沒連接Value則為0xC550)
16近位轉換後為'1100 0101 0100 0100'(若沒連接則為'1100 0101 0101 0000')
發現
bit0 為'0',0 = Receive buffer is empty
bit0 為'1',1 = Receive buffer has data, at least one more character can be read
bit2 為'1',1 = Framing error has been detected for the current character (character at the top of the receive FIFO)
bit2 為'0',0 = Framing error has not been detected
bit4 為'0',0 = Receiver is active
bit4 為'1',1 = Receiver is Idle
我的包率明明有設對(4800),我還有用其他包率測試過2400、9600、19200
其他包率 用watch看U1STA的Value為0xC554(UART與GPS連接)
16近位轉換後為'1100 0101 0101 0100'
bit4 為'1',1 = Receiver is Idle
所以我的包率有設對!!
我想請問bit2 為'1'的可能性有哪些??有什麼解決方法??

發表於: 2009/9/25 19:09
頂部


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


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

發表於: 2009/9/24 23:18
頂部


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


我將程式改成
void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void) // UART1接收資料中斷副程式
{
IFS0bits.U1RXIF = 0 ; // 清除中斷旗標

RX_DATA = ReadUART1(); // Get RS-232 data 將UART讀取資料暫存器的內容讀出
UART_RX_Flag = 1 ;
}
int main(void)
{
while(1)
{
if(UART_RX_Flag == 1) // 判斷資料傳送狀態旗標
{
RX_ARRAY[cnt]=RX_DATA;
LCD_SetCursor(0,1);
putsLCD(RX_ARRAY);
UART_RX_Flag = 0 ;
cnt=0;
}
}
}

--------------------------------------------------------------------
結果 watch中 RX_DATA 最常出現的 Value = 0x00 or 0xF8
RX_ARRAY 的 Value 還是為 "." LCD上顯示"X"

至於你說的LooKRS232 我下載了
File -> Connection -> 設定好 com1,4800,8,1,None,None -> OK
結果
Serial port 'COM1' was successfully opened with selected settings
Serial port 'COM1' is accessible for using
接著就沒東西
Serial Satatus 中 每一個都是off ....
不曉得 lancer0498 兄願不願意留個e-mail or MSN 做個交流?

發表於: 2009/9/24 20:18
頂部


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


參照:

lancer0498 寫道:
以下是臨時寫的,沒經測試,可以參考看看
void RX_isr(void)
{
PIR1bits.RCIF=0;
RX_DATA=ReadUSART();
FLAGbits.RX=1;
}

void main()
{
unsigned char cnt=0;
...
...
.
.
.
.
while(1)
{
if(FLAGbits.RX==1)
{
RX_ARRAY[cnt]=RX_DATA;
if(RX_DATA=='*') //收到checksum前的*號
//checksum可不必理它,除了你一定要用到
{
putsLCD(RX_ARRAY[]);
FLAGbits.RX=0;
cnt=0;
}
else
{
cnt++;
FLAGbits.RX=0;
}
}
}
}

/*我是讀電機的,也沒人教,也是從microchip論壇問來的,
希望我們互相交流,可以讓我們這些能力不好的小朋友成長,加油*/


感謝lancer0498兄的意見~~!!
我編譯時 出現error在 putsLCD(RX_ARRAY[]);
我改成 putsLCD(RX_ARRAY[cnt]); 編譯通過
但實行結果 LCD沒顯使任何東西
將中斷點設在putsLCD(RX_ARRAY[cnt]); 不能中斷 因此判斷RX_DATA=='*' => false

會是我本身GPS有問題嗎??

發表於: 2009/9/24 16:24
頂部


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


非常感謝lancer0498兄給的意見,你的意見讓我學到不少!!再次感謝妳!!!
$GPRMC,171216.000,A,4139.6583,N,08336.5562,W,7.87,300.93,071207,,*1C == > 這應該是代表$是斷落的開始吧!?
經過我一天的修改 還是沒辦法....
我在
int main(void)
{
LCD_Delay200usX(50) ;

PMP_Initial() ;
ADC_Initial() ;
Timer1_Initial();
OC_Initial() ;
UART1_Initial() ;
LCD_Initial() ;

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

while(1)
{
if(UART_RX_Flag == 1) // 判斷資料傳送狀態旗標
{
RX_BuffDisplay(RX_Buff);

UART_RX_Flag = 0 ; ==>設中斷點
}
} ==> 中斷後 指標所指位置
}
第一次中斷 watch觀看結果是 cnt = 0x007,RX_Buff 全部都是.或x,UART_RX_Flag = 0x00
在執行一次後中斷 watch觀看結果是 cnt = 0x009,RX_Buff 全部都是.或x,UART_RX_Flag = 0x00
lancer0498兄可不可以請妳再詳細說明,我有點不太懂你的意思...很抱歉,我是學通訊網路出身的,對於這個不太懂,有勞你多多指點!!
=============主要程式============
void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void) // UART1接收資料中斷副程式
{
IFS0bits.U1RXIF = 0 ; // 清除中斷旗標

RX_Buff[cnt]=ReadUART1(); // Get RS-232 data 將UART讀取資料暫存器的內容讀出
if (cnt < 17)
{
cnt++ ;
}
else
{
cnt = 0 ;
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);
putrsLCD(LCDString);

while(1)
{
if(UART_RX_Flag == 1) // 判斷資料傳送狀態旗標
{
RX_BuffDisplay(RX_Buff);

UART_RX_Flag = 0 ;
}
}
}

void RX_BuffDisplay(unsigned char *buff)
{
LCD_SetCursor( 0,1);
LCD_Delay200usX(50) ;
putsLCD(buff) ;
LCD_Delay200usX(50) ;
}

Attach file:



jpg  (0.00 KB)

Link only for registered users

發表於: 2009/9/24 0:02
頂部


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


感謝各位前輩相助!!
本人已經成功的進行中斷
但是接收到的資料好像變成亂碼?!
從watch看不是"."就是"x" ....
請問這是甚麼問題??

Attach file:



jpg  (0.00 KB)


jpg  (0.00 KB)


jpg  (0.00 KB)

Link only for registered users

發表於: 2009/9/22 23:12
頂部



« 1 (2) 3 4 »



:::

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... ]

教育訓練中心

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