51单片机+315M无线射频模块发射程序
#define TEST_PULS(puls_in, puls_type) (puls_in >
=====================
//接收程序 结束
//=============================================================
#define SEND_DELAY_TIME 20//防碰撞延迟(单位:毫秒)
unsigned char send_delay = SEND_DELAY_TIME;
#define VALID_PULS_COUNT 10
unsigned char valid_puls_counts = VALID_PULS_COUNT;
//碰撞检测在该函数中实现.由于无线模块本身的限制,碰撞检测为非完全检测,只能在发送前
//检测是否有其它单元在使用信道,在发送过程中受到的碰撞干扰是无法检测到的.经测试,效果还行
void wirless(){
if (send_stat == SEND_PROGRESSING && send_delay == 0){
send();
if (send_stat == SEND_SUCCESS)
send_delay = SEND_DELAY_TIME;
}else{
recv();
if (recv_step > HEAD_NEED_RECIVED)//如果检测到当前有其它单元正在发送,继续等待
send_delay = SEND_DELAY_TIME;
else{
if(TEST_PULS(w_data, PULS_0_WIDTH)//如果检测到当前有其它单元正在发送,继续等待
|| TEST_PULS(w_data, PULS_1_WIDTH)
//|| TEST_PULS(w_data, PULS_HEAD_WIDTH)
|| TEST_PULS(w_data, PULS_START_WIDTH)
//|| TEST_PULS(w_data, PULS_STOP_WIDTH)
){
if (valid_puls_counts)
valid_puls_counts--;
else
send_delay = SEND_DELAY_TIME;
}else{
valid_puls_counts = VALID_PULS_COUNT;
}
}
}
}
#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 100//心跳间隔 X / 1000 秒
unsigned int heart_beat_timer = HEART_BEAT_INTERVAL;
unsigned int last_jiffies=0;
void main(){
init_serialcomm();
//P0=0xff;
//P2=0x00; ;
sys_init();
LED1 = 0;
LED2 = 1;
//send_string_com("ok",2);
//lcd_reset();
//lcd_power_on();
//lcd_self_test();
while(1){
if (jiffies - last_jiffies >= 50){//每次中断为50us,所以要20次才为1ms
last_jiffies = jiffies;
heart_beat_timer--;
if (send_stat == 0 ){//碰撞测试
ET0=0;
ReadTemperature();
clock_init_again();
START_SEND(8);
send_buf[1]=Te/10+0x30;
send_buf[2]=Te%10+0x30;
send_buf[3]=.;
send_buf[4]=Te_D/10+0x30;
send_buf[5]=(Te_D%10)+0x30;
send_buf[6]=D;
send_buf[7]=;
//wirless();
//send_string_com(send_buf,strlen(send_buf));
}
if (send_delay)
send_delay--;
}
if (heart_beat_timer == 0){
heart_beat_timer = HEART_BEAT_INTERVAL;
LED1 = ~LED1;
LED2 = ~LED2;
}
wirless();
if (send_stat == SEND_FAILED){
send_stat = 0;break;
}else if (send_stat == SEND_SUCCESS){
send_stat = 0;
P2_3=~P2_3;break;
}
}
}
51单片机315M无线射频模块发射程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)