新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51單片機+315M無線射頻模塊接受程序

51單片機+315M無線射頻模塊接受程序

作者: 時間:2016-11-30 來源:網(wǎng)絡(luò) 收藏

void Display_T()
{
DisplayOneChar(9,1,recv_buf[5]);
DisplayOneChar(8,1,recv_buf[4]);
DisplayOneChar(7,1,recv_buf[3]);
DisplayOneChar(6,1,recv_buf[2]);
DisplayOneChar(5,1,recv_buf[1]);
DisplayOneChar(0,0,0x54);
}

本文引用地址:http://butianyuan.cn/article/201611/323697.htm

#define SCMD_SET_PORT 0x51
#define SCMD_GET_PORT 0x52

#define SCMD_RESET 0x61

#define SCMD_LCD_OUTSTR 0x71
#define SCMD_LCD_RESET 0x72
#define SCMD_LCD_SETXY 0x73
#define SCMD_LCD_SETLINE 0x74
#define SCMD_LCD_CLEAR 0x75


#define SRESP_GET_PORT_ERROR 0x41
#define SRESP_SET_PORT_ERROR 0x42

#define HEART_BEAT_INTERVAL 200//心跳間隔 X / 1000 秒
unsigned int heart_beat_timer = HEART_BEAT_INTERVAL;
unsigned int last_jiffies=0;


void main(){
Delay400Ms(); //啟動等待,等LCM講入工作狀態(tài)
LCMInit(); //LCM初始化
Delay5Ms(); //延時片刻(可不要)
mychar(10,1); //顯示 自定義字符
init_serialcomm();
P0=0x0ff;
P2=0x00;
sys_init();


//send_string_com("ok",2);
//lcd_reset();
//lcd_power_on();
//lcd_self_test();

while(1){
if (jiffies - last_jiffies >= 20){//每次中斷為50us,所以要20次才為1ms
last_jiffies = jiffies;
heart_beat_timer--;
if (send_delay)
send_delay--;
}

if (heart_beat_timer == 0){
heart_beat_timer = HEART_BEAT_INTERVAL;

while(1) {recv();if (recv_stat == RECV_SUCCESS)
{
P0_0=~P0_0;
send_string_com(recv_buf,strlen(recv_buf));
Display_T();
recv_stat = 0;break;}
recv_stat = 0;
}
}

/*#if 0
if (send_stat == 0){
//碰撞測試
START_SEND(8);
send_buf[1]=T;
send_buf[2]=e;
send_buf[3]=s;
send_buf[4]=t;
send_buf[5]=O;
send_buf[6]=k;
send_buf[7]=!;

lcd_out_string("sending:");
//send_string_com(send_buf,strlen(send_buf));
printhex(send_buf[0]);
printhex(send_buf[1]);
}
#endif
*/
wirless();

if (send_stat == SEND_FAILED){


send_stat = 0;

}else if (send_stat == SEND_SUCCESS){
send_stat = 0;
P2_3=~P2_3;

}
//recv();
//send_string_com("start",5);
/*while(1) {recv();if (recv_stat == RECV_SUCCESS)
{
P0_0=~P0_0;
send_string_com(recv_buf,strlen(recv_buf));} }*/
/*if (recv_stat == RECV_SUCCESS){
//send_string_com("test1",5);
#if 1
//unsigned int i;
//for(i=0; i//serial_out(recv_buf[i]);//輸出接收到的字符
P0_0=~P0_0;
send_string_com(recv_buf,strlen(recv_buf));
#else
//if (recv_buf[1]==o)
//P0=0x00;
//lcd_out_string("data recived:");
//printhex(recv_buf[0]);
//printhex(recv_buf[1]);
//OutChar();
//send_string_com("test3",5);
#endif
recv_stat = 0;
}
*/
#if 0
if (RI){
unsigned char scmd[17];
heart_beat_timer = HEART_BEAT_INTERVAL;
wait_serial(scmd, 1, 0);
switch(scmd[0]){
case SCMD_RESET:
((void (code *) (void))0x0000) ();//軟件復(fù)位
case SCMD_SET_PORT:
if (wait_serial(scmd, 2, 200))
break;
switch(scmd[0]){
case 0:
P0 = scmd[1];
break;
case 1:
P1 = scmd[1];
break;
case 2:
P2 = scmd[1];
break;
case 3:
P3 = scmd[1];
break;
}
break;
case SCMD_GET_PORT:
if (wait_serial(scmd, 1, 200))
break;
switch(scmd[0]){
case 0:
serial_out(P0);
break;
case 1:
serial_out(P1);
break;
case 2:
serial_out(P2);
break;
case 3:
serial_out(P3);
break;
}
break;
case SCMD_LCD_OUTSTR:
if (wait_serial(scmd, 1, 200))
break;
scmd[scmd[0]] = 0;
if (wait_serial(scmd, scmd[0], 200))
break;
lcd_out_string(scmd);
break;
case SCMD_LCD_RESET:
lcd_reset();
break;
case SCMD_LCD_CLEAR:
lcd_clear();
break;
case SCMD_LCD_SETXY:
if (wait_serial(scmd, 2, 200))
break;
SetXY(scmd[0], scmd[1]);
break;
case SCMD_LCD_SETLINE:
if (wait_serial(scmd, 1, 200))
break;
SetLine(scmd[0]);
break;
default:
break;
}
}
#endif
}
}


上一頁 1 2 3 下一頁

關(guān)鍵詞: 51單片機315M無線射頻模

評論


技術(shù)專區(qū)

關(guān)閉