全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1006
推到 Plurk!
推到 Facebook!

8051加RF傳送資料

尚未結案
az3456789
一般會員


發表:5
回覆:4
積分:1
註冊:2012-07-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2012-07-14 15:46:42 IP:120.113.xxx.xxx 訂閱
RF作資料傳輸
不用HT-12E HT-12D作編碼以及解碼
而用兩個8051來作編碼以及解碼的工作
以下是我用課本範例改的程式碼
可是卻一直試不出來
可以請大大幫我看看有什麼問題嗎?

發射端程式
#include
typedef unsigned char tByte;
#define SYNC 0xAA// synchro signal
#define RADDR 0x44
void delayms(unsigned int time)
{
unsigned int n;
while(time>0)
{
n=120;
while(n>0) n--;
time--;
}
}
void send_byte(tByte const b)
{
SBUF = b;
while(!TI);
TI = 0;
}
void send_packs(tByte const radd, tByte const rcmd)
{
send_byte(SYNC);
send_byte(radd);
send_byte(rcmd);
send_byte((radd rcmd)); // check sum
}
main()
{
PCON |= 0x00;
TMOD=0x20;
TH1=230;
TL1=230;
TR1=1;
SCON=0x40;
while(1)
{
TI=0;
send_packs(RADDR, P1);
while(TI==0);
delayms(100);
}
}

接收端程式
#include
typedef unsigned char tByte;
#define SYNC 0xAA// synchro signal
#define RADDR 0x44
main()
{
PCON |= 0x00;
TMOD = 0X20;
TH1 = 230;
TL1 = 230;
TR1 = 1;
SCON = 0x70;
ES = 1;
EA = 1;
while(1)
{
RI = 0;
while(RI == 0);
}
}
tByte USART_vReceiveByte(void)
{
// Wait until a byte has been received
while(!RI);
RI = 0;
// Return received data
return SBUF;
}
void UART_ISR() interrupt 4
{
// a-lu remark: 2011.02.21
// No implemented SYNC check before receive the byte of RADDR
// Let's to wait and see the test result
//define variables
tByte raddress, cmd, chk;//transmitter address
// find TX or RX caused interrupt
if(TI)
{
// clear TI
TI = 0;
}
else
{
//receive destination address
raddress = USART_vReceiveByte();
//receive cmd
cmd = USART_vReceiveByte();
//receive checksum
chk = USART_vReceiveByte();
//compare received checksum with calculated
if(chk == (raddress cmd))//if match perform operations
{
//if transmitter address match
if(raddress == RADDR)
{
if(cmd == 0xfe)
{
P1 = 0x3f;
}
else if(cmd == 0xfd)
{
P1 = 0xcf;
}
else if(cmd == 0xfb)
{
P1 = 0x0f;
}
else if(cmd == 0xf7)
{
P1 = 0xff;
}
}
}
}
}


編輯記錄
az3456789 重新編輯於 2012-07-14 01:49:02, 註解 無‧
az3456789 重新編輯於 2012-07-14 01:51:11, 註解 無‧
az3456789 重新編輯於 2012-07-14 01:53:36, 註解 無‧
az3456789 重新編輯於 2012-07-14 02:02:41, 註解 無‧
az3456789 重新編輯於 2012-07-14 02:03:10, 註解 無‧
az3456789 重新編輯於 2012-07-14 02:13:40, 註解 無‧
az3456789 重新編輯於 2012-07-14 02:19:17, 註解 無‧
az3456789 重新編輯於 2012-07-14 02:27:34, 註解 無‧
az3456789 重新編輯於 2012-07-14 02:33:55, 註解 無‧
az3456789 重新編輯於 2012-07-14 07:42:28, 註解 無‧
系統時間:2017-10-24 1:04:50
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!