• 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: 關於兩pic18f452資料互傳問題
#2
版主
版主


查看用戶資訊
程式很長看的很辛苦,建議問題簡單化先用 Widows 所提供的超級終端機先測試發的部分,OK 後在測試收的部分,須注意超級終端機只會顯示 可視性的 ASCII Code 。

發表於: 2005/11/8 17:05
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


關於兩pic18f452資料互傳問題
#1
新會員
新會員


查看用戶資訊
各位先進大家好:
個人為初學者目前有一問題無法解決,尚請先進們能幫幫忙,我用兩18f452以rs232互傳資料,不知是否中斷設定有問題,有時正常有時不動作,還請各位能夠給予指點.謝謝!

#include <p18f452.h> //MASTER
#define BaudRate 25
void High_INT_SER(void);
void InitialUSART(void);
void PUTCHAR(char c);
char DATA[3];
char SEND[3]={0x40,0x31,0x2A};
char RI_PTR;
char sw;
//******** INTERRUPT PROGRAM *******
#pragma code High_Interrupt_Vector=0x0008
void High_INT_VEC(void)
{
_asm
goto High_INT_SER
_endasm
}
#pragma code
//**********接收中斷副程式 **************
#pragma interrupt High_INT_SER
void High_INT_SER(void)
{
if(PIR1bits.RCIF==1)
{
DATA[RI_PTR]=RCREG;
RI_PTR++;
if(RI_PTR==2) RI_PTR=0;
}
}
#pragma
//************ MAIN PROGRAM
void main(void)
{
char i;
TRISB=0xff;
TRISD=0x00;
ADCON1=0x06;
InitialUSART();
while(1)
{
if(PORTB!=sw) sw=PORTB;
for(i=0;i<3;i++)
PUTCHAR(SEND[i]);
}
}
//************** InitialUSART *****************
void InitialUSART(void)
{
RCONbits.IPEN=1;
INTCONbits.GIEH=1;
INTCONbits.PEIE=1;
RCSTAbits.SPEN=1;
RCSTAbits.CREN=1;
TXSTAbits.TXEN=1;
TXSTAbits.BRGH=1;
PIE1bits.RCIE=1;
PIR1bits.RCIF=0;
IPR1bits.RCIP=1;
SPBRG=BaudRate;
}
//*********** PUTCHAR 傳遞副程式
void PUTCHAR(char c)
{
TXREG=c;
while(TXSTAbits.TRMT!=1);
}




//***************SLAVE********************
#include <p18f452.h>
#define BaudRate 25
void High_INT_SER(void);
void InitialUSART(void);
void PUTCHAR(char c);
char DATA[3];
char SEND[3]={0x40,0x31,0};
char RI_PTR;
char SEND_FLAG=0;
char sw=0x00,i;
//************* INTERRUPT PROGRAM ****
#pragma code High_Interrupt_Vector=0x0008
void High_INT_VEC(void)
{
_asm
goto High_INT_SER
_endasm
}
#pragma code
//*****************************
#pragma interrupt High_INT_SER
void High_INT_SER(void)
{
if(PIR1bits.RCIF==1)
{
DATA[RI_PTR]=RCREG;
RI_PTR++;
if(RI_PTR==2) RI_PTR=0;
}
}
#pragma
//************ MAIN PROGRAM ******
void main(void)
{

TRISB=0xff;
ADCON1=0x06;
InitialUSART();
while(1)
{
while(PORTB==sw);
sw=PORTB;
SEND[2]=PORTB;
SEND_FLAG=0;
while(SEND_FLAG!=1);
for(i=0;i<3;i++)
PUTCHAR(SEND[i]);
SEND_FLAG=0;
}
}
//************** InitialUSART *****************
void InitialUSART(void)
{
RCONbits.IPEN=1;
INTCONbits.GIEH=1;
RCSTAbits.SPEN=1;
RCSTAbits.CREN=1;
TXSTAbits.TXEN=1;
TXSTAbits.BRGH=1;
PIE1bits.RCIE=1;
PIR1bits.RCIF=0;
IPR1bits.RCIP=1;
SPBRG=BaudRate;
}
//*********** PUTCHAR *********************
void PUTCHAR(char c)
{
if(PIR1bits.TXIF!=0) TXREG=c;
while(TXSTAbits.TRMT!=1);
}

發表於: 2005/11/7 17:54
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... ]

教育訓練中心

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