#include <reg52.h>
#include <intrins.h>
#include"lcd1602.h"
#include"nrf905.h"
#define uchar unsigned char
#define uint unsigned int
void convert();
uchar num_temp[5]={0};
uchar num_humi[5]={0};
void convert()
{ num_temp[0]=(int)Rxbuf[0]/10+'0';
num_temp[1]=(int)Rxbuf[0]%10+'0';
num_temp[2]=0x2e+'0';
num_temp[3]=(int)Rxbuf[1]/10+'0';
num_temp[4]=(int)Rxbuf[1]%10+'0';
num_humi[0]=(int)Rxbuf[2]/10+'0';
num_humi[1]=(int)Rxbuf[2]%10+'0';
num_humi[2]=0x2e+'0';
num_humi[3]=(int)Rxbuf[3]/10+'0';
num_humi[4]=(int)Rxbuf[3]%10+'0';
}
/*#define WC 0x00
#define RC 0x10
#define WTP 0x20
#define RTP 0x21
#define WTA 0x22
#define RTA 0x23
#define RRP 0x24
sbit TXEN=P3^5;
sbit TRX_CE=P3^4;
sbit PWR=P3^6;
sbit MISO=P3^0;
sbit MOSI=P1^2;
sbit SCK=P1^4;
sbit CSN=P1^3;
sbit DR=P1^1;
sbit CD=P1^0;
//sbit key1=P2^0;
//sbit key2=P2^1;
//sbit key3=P2^2;
//sbit led1=P2^3;
//s/bit led2=P2^5;
//sbit led3=P2^6;
//sbit led4=P2^7;
unsigned char Rxbuf[4]={0};
unsigned char Rfconfig[10]={0x4c,0x0e,0x44,0x04,0x04,0xe7,0xe7,0xe7,0xe7,0xde};
void delay(uint x)
{
uint i;
for(i=0;i<x;i++)
{
_nop_();
}
}
void Spiwrite(uchar dat)
{
uchar i=8;
while(i--)
{
delay(10);
SCK=0;
MOSI=(bit)(dat&0x80);
dat<<=1;
delay(10);
SCK=1;
delay(10);
SCK=0;
}
SCK=0;
}
unsigned char Spiread(void)
{
uchar i=8;
uchar ddat;
while(i--)
{
ddat<<=1;
SCK=0;
_nop_();
_nop_();
ddat|=MISO;
SCK=1;
_nop_();_nop_();
}
SCK=0;
return ddat;
}
void Rxpacket(void)
{
unsigned char j=0;
TRX_CE=0;
PWR=1;
CSN=0;
Spiwrite(RRP);
for(j=0;j<4;j++)
{
Rxbuf[j]=Spiread();
}
CSN=1;
}
void ini_system(void)
{
uchar i;
CSN=1;
SCK=0;
PWR=1; // PWR_UP | TRX_CE |TXEN | M O D E
TRX_CE=0; // 1 | 0 | 0 | SPI Programming
TXEN=0;
_nop_();
CSN=0;
Spiwrite(WC);
for(i=0;i<10;i++)
{
Spiwrite(Rfconfig[i]);
}
CSN=1;
}
void setmode()
{
PWR=1; // PWR_UP TRX_CE TXEN MODE
TRX_CE=1; // 1 1 0 SHOCKBURST RX
TXEN=0;
delay(300); //time must be >=650us
} */
/*void convert()
{
uint i;
for(i=0)
float com;
uint dat;
com=s->temperature;
com*=100;
dat=(uint)com;
s->num_temp[0]=dat/1000+0x30; //十位
s->num_temp[1]=dat%1000/100+0x30; //个位
s->num_temp[2]=0x2e;
s->num_temp[3]=dat%100/10+0x30; //小数点第一位
s->num_temp[4]=dat%10+0x30; //小数点第二位
com=s->humidity;
com*=100;
dat=(uint)com;
s->num_humi[0]=dat/1000+0x30; //十位
s->num_humi[1]=dat%1000/100+0x30; //个位
s->num_humi[2]=0x2e;
s->num_humi[3]=dat%100/10+0x30; //小数点第一位
s->num_humi[4]=dat%10+0x30; //小数点第二位
}*/
void display()
{
GotoXY(0,0);
Print("temp:");
GotoXY(0,1);
Print("humi: ");
GotoXY(4,0);
Print(num_temp);
GotoXY(4,1);
Print(num_humi);
}
/* led1=0;
led2=1;
led3=1;
led4=1;
led=Rxbuf[0];
delay(1);
led1=1;
led2=0;
led3=1;
led4=1;
led=Rxbuf[1];
delay(1);
led1=1;
led2=1;
led3=0;
led4=1;
led=Rxbuf[2];
delay(1);
led1=1;
led2=1;
led3=1;
led4=0;
led=Rxbuf[3];
delay(1);
} */
void main()
{
ini_system();
setmode();
LCD_Initial();
while(1)
{
Rxpacket();
while(!DR);
convert();
display();
}
}