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


Browsing this Thread:   1 Anonymous Users




« 1 (2)


Re: 詢問pic18f452 USART傳送問題
#8
新會員
新會員


查看用戶資訊
一樣也是在邏輯分析儀上仍然是沒有收到訊號
我使用的是APP001實驗版
但是我是直接使用擴充PIN上的RC6和RC7
而沒有去使用RS232接頭
這對結果會有影響嗎?
但是我有試過如果跑MCC的範例程式經由rs232接頭來傳輸的話是正常可以使用的
所以真的是搞的一個頭兩ㄍ大

發表於: 2007/3/21 12:30
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 詢問pic18f452 USART傳送問題
#7
中級會員
中級會員


查看用戶資訊
那如果只單作傳送呢 ? (暫不接收)

發表於: 2007/3/21 12:06
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 詢問pic18f452 USART傳送問題
#6
新會員
新會員


查看用戶資訊
有確定收到~而且有跳到傳送資料的if迴圈內
也有跳到USART的WriteUSART的函式中
可是當值傳到TXREG的時候就沒下文了
我使用邏輯分析儀去量測都沒有接收到傳送出去的數值

發表於: 2007/3/21 12:00
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 詢問pic18f452 USART傳送問題
#5
中級會員
中級會員


查看用戶資訊
可以先確認 接收的 array 0~14都是正確的 再做判斷的部分

發表於: 2007/3/21 11:17
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 詢問pic18f452 USART傳送問題
#4
新會員
新會員


查看用戶資訊
/* Include Header files */

#include <p18f452.h>
#include <timers.h>
#include <delays.h>
#include <usart.h>
#include <stdlib.h>
#include "P18F_LCD.h"

/* Declare the Function Prototype */
void InitializeUSART(void);
void InitializeINTs(void);
void InitializePORT(void);
void isr_high_direct(void);
void isr_high(void);

//*****************************************************
#pragma romdata My_romdata=0x1000
const rom char LCD_MSG1[]=" Power On";
const rom char LCD_MSG2[]=" Pumping Up";

#pragma romdata

//*****************************************************
#pragma udata access My_RAM_2
near unsigned char Rec_Data;
near unsigned char Data_Buffer[3];
near unsigned char Data_Temp[30];
#pragma udata

int i=0;
int j=0;

//***********************************************************
/* */
/* Main Program */
/* */
//***********************************************************

void main(void)
{
InitializePORT( );
OpenLCD( );
InitializeINTs( );
InitializeUSART( );
Rec_Data=0x00;
while(1)
{

}
}

//************************************************
//* #pragma Interrupt Declarations *
//************************************************
//************************************************
//* Function: isr_high_direct *
//* - Direct execution to the actual *
//* high-priority interrupt code. *
//************************************************
#pragma code isrhighcode = 0x0008

void isr_high_direct(void)
{
_asm //begin in-line assembly
goto isr_high //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 interrupt isr_high

void isr_high(void)
{
Rec_Data=ReadUSART(); // Get RS-232 data; clear RCIF
Data_Buffer[i]=Rec_Data;
Data_Temp[j]=Data_Buffer[i];
if(Data_Temp[12]==0xA7 && Data_Temp[13]==0xA5 && Data_Temp[14]==0x5A )
{
while(TXSTAbits.TRMT=0);
putcUSART(0xA7);
while(TXSTAbits.TRMT=0);
putcUSART(0xA5);
while(TXSTAbits.TRMT=0);
putcUSART(0x5A);
}
if (i<3)
{
i++;
}
else
{
i=0;
}
j++;
}
#pragma code

//************************************************
//* Function: Initialize Interrupts *
//* - Reset All Interrupr *
//* - Enable HIgh Priority Interrupt *
//* - Disable Low Priority Interrupt *
//************************************************
void InitializeINTs(void)
{
PIR1=0; //Clear all Interrupt setting & Flag
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; // Enalbe high priority Interrupt
}
//************************************************
//* Function: Initialize USART *
//* - Initialize the RS-232 communication *
//* - Disable Interrupr for TxD *
//* - Enable Interrupt fro Rxd *
//* - Format: 9600, N, 8, 1 *
//************************************************
void InitializeUSART(void)
{
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
,103); // Set SPBRG=103, Baud Rate = 9600

RCSTAbits.SPEN=1;
TRISCbits.TRISC7=1; // Set input for RXD
TRISCbits.TRISC6=0; // Set output for TXD
TXSTA=0b00100100;
PIR1bits.RCIF=0;
PIR1bits.TXIF=0;
IPR1bits.RCIP=1; // Set Receive of USART are High priority
}

//************************************************
//* Function: InitializePORT *
//* - Make PORTD all outputs *
//* - Turn 0ff all the LED's *
//************************************************
void InitializePORT(void)
{
PORTA=0x00;
TRISA=0b11011011; // RA2 as LCD-E control, RA5 as CS Control for SPI
PORTD=0x00;
TRISD=0x00; // Set PORTD as Output port
}


附上全部的程式
但是目前遇到的問題在接收方面是完全正常的
可以收到我每一筆傳送的資料
但是當我要傳送的時候卻一直沒有收到傳出的Data

發表於: 2007/3/21 10:02
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 詢問pic18f452 USART傳送問題
#3
中級會員
中級會員


查看用戶資訊
GIEH , TXIE , RCIE
相關設定沒看到

http://homelf.kimo.com.tw/coyyhw/MidGirder/Doc1.doc

發表於: 2007/3/21 9:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 詢問pic18f452 USART傳送問題
#2
中級會員
中級會員


查看用戶資訊
沒有看到 Interrupt enable 的相關設定

RCIE & TXIE

發表於: 2007/3/21 9:29
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


詢問pic18f452 USART傳送問題
#1
新會員
新會員


查看用戶資訊
void isr_high(void)
{
Rec_Data=ReadUSART(); Data_Buffer[i]=Rec_Data;
Data_Temp[j]=Data_Buffer[i];
if(Data_Temp[12]==0xA7 && Data_Temp[13]==0xA5 && Data_Temp[14]==0x5A )
{
while(TXSTAbits.TRMT=0);
putcUSART(0xA7);
while(TXSTAbits.TRMT=0);
putcUSART(0xA5);
while(TXSTAbits.TRMT=0);
putcUSART(0x5A);
}
if (i<3)
{
i++;
}
else
{
i=0;
}
j++;
}

這是我進入中斷後的副程式,當我判斷得知收到的資料為A7A55A時
我必須接著回傳A7A55A給傳輸端
但是當我使用MPLAB IDE的Watch來觀看TXREG這個變數時
雖然都有跟隨我的指令動作
可是在我使用邏輯分析儀實際測量USART的TX腳位時卻遲遲收不到訊號
所以想要請問各位大大這是那邊出了問題
還請麻煩一解迷津
下面是我USART的Initialize的Code
void InitializeUSART(void)
{
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
,103); // Set SPBRG=103, Baud Rate = 9600

RCSTAbits.SPEN=1;
TRISCbits.TRISC7=1; // Set input for RXD
TRISCbits.TRISC6=0; // Set output for TXD
TXSTA=0b00100100;
PIR1bits.RCIF=0;
PIR1bits.TXIF=0;
IPR1bits.RCIP=1; // Set Receive of USART are High priority
}

發表於: 2007/3/20 22: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... ]

教育訓練中心

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