• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   3 Anonymous Users






Re: PIC18F_USART_RX問題(用C18)
#3
初級會員
初級會員


查看用戶資訊
感謝 master 前輩指導,剛試驗成功。
正在瞭解這種寫法。並從中瞭解自己錯在哪。

非常謝謝前輩指導

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


Re: PIC18F_USART_RX問題(用C18)
#2
資深會員
資深會員


查看用戶資訊
unsigned char rxbuf[3];
unsigned char rxbuf_index;

//somewhere let rxbuf_index = 0;

void Rx_isr (void)
{
    
unsigned char RX_Temp;
    
PIR1bits.RCIF 0;    
    
rxbuf[rxbuf_index] = ReadUSART();
        
rxbuf_index++;
       if(!(
rxbuf_index<3))  //表示三筆接收完了
       
{
             
PortB rxbuf[1];
             
rxbuf_index=0;
       }
}

發表於: 2008/10/17 0:45
不要問我哪裡來,我只是個流浪天涯的工程師
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC18F_USART_RX問題(用C18)
#1
初級會員
初級會員


查看用戶資訊
再次請教版上前輩問題,關於USART的RX問題。
傳送端會丟來3個BYTE(0xFF,0x55,0xAA)
我想判定第二個byte的資料,是否為0x55
可是我用下列寫法。我看我的PORTB會顯示出三種狀態。
想請教我在接收RX的資料做判別。是否有寫錯之處?
-----------------------------------------------------------------

#include <p18f2321.h>
#include <delays.h>
#include <adc.h>
#include <timers.h>
#include <usart.h>

#pragma config OSC=HS, BOR=OFF, BORV=2, PWRT=ON, WDT=OFF, LVP=OFF

struct Flag
{
unsigned TXD:1;
}FLAGbits;

void Rx_isr (void);

#pragma code low_vector=0x18
void low_interrupt (void)
{
_asm GOTO Rx_isr _endasm
}
#pragma code

#pragma interruptlow Rx_isr

void Rx_isr (void)
{
unsigned char RX_Temp[7];
unsigned char i;
PIR1bits.RCIF = 0;
for(i=0;i<3;i++)
{
RX_Temp[i]=ReadUSART();
}
PIR1bits.RCIF = 0;
PORTB = RX_Temp[1];
}

void main ()
{
PORTB = 0x00;
TRISB = 0;

OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
12 );

RCONbits.IPEN=1;
INTCONbits.GIEL = 1;
INTCONbits.GIEH = 1;


FLAGbits.TXD=0;
while(1)
{

}
}

發表於: 2008/10/16 16:27
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... ]

教育訓練中心

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