• 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傳送問題
#18
新會員
新會員


查看用戶資訊
感謝版主~我去研究參考看看~
有問題在上來發問
謝謝︿ ︿

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


Re: 詢問pic18f452 USART傳送問題
#17
版主
版主


查看用戶資訊
要不要參考 W410 and AQP002 的 Workshop 教材裡有關 UART 的說明與範例。

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


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


查看用戶資訊
感謝mechwe指正程式上的錯誤
可是我改正之後似乎仍然沒有反應
所以我簡述一下目前的狀況
引述Datasheet的內容
TXREG暫存器中的新數據(如果有的话)就會被裝入TSR。一但把TXREG 暫存器中的數據送入TSR暫存器(在一個TCY 周期内),TXREG暫存器就變為空,同時發送中斷旗標位TXIF(PIR1<4>)會置為1

但是我使用單步執行以及使用Watch觀看變數時發現我的TXREG的值會一直存在,似乎沒有傳送至TSR暫存器,才導致輸出沒有訊號
所以可能要朝這ㄍ方向研究才能知道問題出在哪裡
另外我使用的是APP001實驗版的擴充接腳,不曉得這是否對輸出有影響?

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


Re: 詢問pic18f452 USART傳送問題
#15
版主
版主


查看用戶資訊
mechwe 已經告訴你答案了,用判斷(==)而不是用指定運算(=)。

另外建議將傳送程式交給主程式做,在中斷裡傳送三個 Bytes 不太好吧!只要設個 Flag 其餘的傳送就交給主程式送就好了。

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


Re: 詢問pic18f452 USART傳送問題
#14
資深會員
資深會員


查看用戶資訊

你寫的
while(TXSTAbits.TRMT=0);

我寫的
while(TXSTAbits.TRMT==0);

有差嗎?

我的習慣是

putcUSART(0xA7);
while(TXSTAbits.TRMT==0);
putcUSART(0xA5);
while(TXSTAbits.TRMT==0);
putcUSART(0x5A);
while(TXSTAbits.TRMT==0);

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


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


查看用戶資訊
囧rz
還是不行~>"<

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


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


查看用戶資訊
關掉 ISR 呢 ?

順便加個 Time delay 再 polling

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


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


查看用戶資訊
關掉 ISR 呢 ?

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


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


查看用戶資訊
/* 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)
{
TXSTAbits.TXEN=1;
while(TXSTAbits.TRMT=0);
putcUSART(0xA7);
while(TXSTAbits.TRMT=0);
putcUSART(0xA5);
while(TXSTAbits.TRMT=0);
putcUSART(0x5A);
}
}

//************************************************
//* #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
}


這是我剛剛嘗試的結果~還是沒反應

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


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


查看用戶資訊
那既然硬體沒問題


五的意思是
直接在主程式內 傳送 char (就一行而已) 看看

發表於: 2007/3/21 12:41
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... ]

教育訓練中心

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