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


Browsing this Thread:   1 Anonymous Users






Re: 請教UART接收解碼問題
#2
新會員
新會員


查看用戶資訊
我也有類似的問題耶!

發表於: 2009/10/6 22:54
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請教UART接收解碼問題
#1
初級會員
初級會員


查看用戶資訊
我使用PIC24FJ128GB106
欲從PC上的超級終端機按字元,使PIC24FJ128GB106的LCD上顯示所接收到的字元
unsigned char RX_DATA ;
RX_Data= ReadUART1();
使用ReadUart1 Function
This function returns the content of UART receive buffer (UxRXREG) register.
接著丟給RX_Data這個參數
RX_Data的value是16進位這個沒錯吧!?
我想請教的是,我在PC上的超級終端機每次都按下a
我從watch上看U1RXREG、RX_Data的Value
第一次
U1RXREG的Value為0x004F
RX_Data的Value為0x00
第二次
U1RXREG的Value為0x000F
RX_Data的Value為0x4F
第三次
U1RXREG的Value為0x004F
RX_Data的Value為0x0F
第四次
U1RXREG的Value為0x000F
RX_Data的Value為0x4F
會是我中斷點設錯嗎??
還有為什麼我按下a,結果LCD顯示O
我程式哪邊寫錯??請各位前輩多多指教!!!
特別想請教我的U1MODEvalue這邊有沒有設錯??因為我之前就這邊設錯導致整個執行錯誤!!
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//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_BuffDisplay(void) ;

#define INPUT 1
#define OUTPUT 0
#define Test_Array[16]

unsigned char Test,*p ;

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

unsigned char LCDString[] = "UART Receive";

unsigned int ADC_TempValue ;

short int RX_int,RX_intArray[16] ;
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 ;
UART_RX_Flag = 0;
if(cnt = 15)
{
cnt = 0 ;
LCD_Delay200usX(50) ;
LCD_SetCursor( 0,1);
putsLCD(RX_ARRAY) ;
LCD_Delay200usX(1000) ;
}
else
{
cnt++;
}
}
}
}


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 ;

}

Attach file:


Link only for registered users

jpg  (0.00 KB)


jpg  (0.00 KB)


jpg  (0.00 KB)


發表於: 2009/10/5 20:24
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... ]

教育訓練中心

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