📄 server.c
字号:
/*
* This rutine is composed two aspects: Radio monitor and RS232 communication
*
*/
#include <Nordic\reg24e1.h>
#include <STRING.H>
//------------------------FullField variants for RS232 Begin
unsigned char IDbuffer[50];
unsigned char RadioIndex;
unsigned char BufferFull;
//------------------------FullField variants for RS232 End
//------------------------FullField variants for Radio Begin
#define TICK 10e-3 // 10ms (100Hz) tick
static volatile unsigned short timer;
//------------------------Functions for RS232 Begin
void PutChar(unsigned char c)
{
TI = 0;
SBUF = c;
while(!TI)
;
}
void Delay100us(volatile unsigned char n)
{
unsigned char i;
while(n--)
for(i=0;i<35;i++)
;
}
void SerialInterrupt(void) interrupt 4
{
unsigned char buffer;
unsigned char i;
if(RI)
{
buffer=SBUF;
RI=0;
RadioIndex++;
if(RadioIndex<50)IDbuffer[RadioIndex-1] = buffer;
else
{
IDbuffer[RadioIndex-1] = buffer;
RadioIndex = 0;
P0 |= 0x08; //00001000
for(i=0;i<50;i++)PutChar(IDbuffer[i]);
P0 &= ~0x08;
memset(IDbuffer,0,50);
}
}
}
//------------------------Functions for RS232 End
//------------------------Functions for Radio Begin
//------------------------Functions for Radio End
//------------------------Init Functions Begin
void Init(void)
{
P0_DIR = 0x20; // P0.5 is input, the rest output
P0 = 0x82; // P0.3 = 0 and P0.6=0 for the rec/tran selection
// LED off
SPICLK = 1;
SPI_CTRL = 0x02; // Connect internal SPI controller to Radio
PWR_UP = 1; // Turn on Radio on 24E1
Delay100us(30); // Wait > 3ms
//interrupt all
// EA = 1;
}
void serialInit()
{
TH1 = 152; // 2400@16MHz (when T1M=1 and SMOD=1)
CKCON |= 0x10; // T1M=1 (/4 timer clock)
PCON = 0x80; // SMOD=1 (double baud rate)
SCON = 0x52; // Serial mode1, enable receiver 01010010
TMOD = 0x20; // Timer1 8bit auto reload
TR1 = 1; // Start timer1
P0_DIR |= 0x02; // P0.1 (RxD) is an input
P0_ALT |= 0x06; // Select alternate functions on pins P0.1 and P0.2
EA=1;
ES=1;
}
void WriteWatchDog(unsigned int w)
{
while(REGX_CTRL & 0x10) // Wait for the interface to be ready
;
REGX_MSB = w >> 8;
REGX_LSB = w & 0xff;
REGX_CTRL = 0x08;
while(REGX_CTRL & 0x10) // Wait for the interface to be ready
;
}
void FullFieldInit(void)
{
memset(IDbuffer,0,50);
RadioIndex=0;
}
//------------------------Init Functions End
void main(void)
{
unsigned char b;
Init();
serialInit();
FullFieldInit();
while(1)
{
WriteWatchDog(60/TICK);
b=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -