-
这是
init.c
文件
#include
#define
uchar
unsigned char
#define
uint
unsigned int
uchar xdata date_time[6];
uchar xdata i2c_buf[8];
uchar
xdata result;
uchar xdata re_buf[16];
uchar xdata re_cnt;
uchar check_sum;
uchar flag_init;
uchar xdata flag_end;
uchar xdata flag_uart_busy;
uint
r_cnt;
uchar flag_ex0_isr;
//uchar xdata year ,month ,day0;
uchar xdata c_year,c_month,c_day0;
uchar xdata tx_buf1[20];
uchar xdata tx_buf2[20];
uchar xdata tx_buf3[20];
uchar xdata tx_buf4[20];
uint
run_cnt;
/*
=
==================================================
============================
=
* Name
: DelayMs( )
*
Description : delay some times
* Input
: None
* Output
:
None
* Note
: None
=========
==================================================
====================
=
*/
void init_uart(void)
{
u
char i;
TMOD|=0x20;
T
H1=0Xfd;
T
L1=0Xfd;
S
CON=0X50;
T
R1=1;
E
S=1;
I
T0
=1;
//
低电平触发外部中断
E
X0 =1;
//
允许外部中断
/
/--------------
---------------------------
f
or(i=0;i<20;i++)
{
tx_buf1[i]=1;
tx_buf2[i]=2;
tx_buf3[i]=2;
tx_buf4[i]=2;
}
}
/*
==================================================
=============================
=
* Name
: DelayMs( )
*
Description : delay some times
* Input
: None
* Output
:
None
* Note
: None
=========
==================================================
====================
=
*/
//////////////////////////////////////////
//////////////////////////////////////////////////
////
void send_one_byte(unsigned char
tad )
{
u
char temp;
i
f(ES==1)
{
E
S=0;
temp=1;
}
T
I=0;
S
BUF=tad;
//
发送数据
os_wait2(K_TMO,1);
w
hile(TI==0);
T
I=0;
f
lag_uart_busy=1;
i
f(temp==1)
{
ES=1;
}
}
/*
=======================================
========================================
=
* Name
: DelayMs( )
*
Description : delay some times
* Input
: None
* Output
:
None
* Note
: None
=========
==================================================
====================
=
*/
void job0(void) // _TASK_ 0
{
u
char temp;
u
char i;
r
un_led=0;
t
emp=0x10;
f
lag_init =0;
i
nit_uart();
f
lag_uart_busy=1;
P
0 =0xff;
r
ed_led=1;
r
un_led=1;
i
=1;
i
f(i==2)
{
RX_Mode();
TX_Mode();
}
i
nit_io();
d
elay_ms(550);
d
elay100();
T
X_Mode();
s
end_one_byte(0);
f
lag_ex0_isr=0;
}
//-------------
--------------------------------------
void task1(void) //_task_ 1
{
u
char i;
run_cnt++;
if(run_cnt>20)
{
run_cnt=0;
flag_init=1;
for(i=0;i<7;i++)
{
tx_buf1[i]=i2c_buf[6-i];
}
check_sum=0;
for( i=0;i<19;i++)
{
check_sum+=
tx_buf1[i];
}
tx_buf1[19]= check_sum;
nRF24L01_TxPacket(tx_buf1);
for(i=0;i<7;i++)
{
tx_buf1[i]=i2c_buf[6-i];
send_one_byte(i2c_buf[i]);
}
for(i=0;i<4;i++)
{
send_one_byte(0xff);
}
send_one_byte(check_sum);
}
}
这是
m
ain.c
文件
#include
#define
uchar unsigned char
#define
uint
unsigned
int
//---------------------------------
------------------
uchar t0_isr_cnt;
uint
t2_isr_cnt;
uchar temp;
sbit
EXT0=
P3^2;
//
外部中断管脚
uchar
bdata sta;
sbit
RX_DR
=sta^6;
sbit
TX_DS
=sta^5;
sbit
MAX_RT
=sta^4;
//
--------------------------------------------------
-
void main(void )
{
//
uchar i;
j
ob0();
f
lag_end=0;
t
2_isr_cnt=0;
E
A=1;
//
check_sum=0;
/
/--------------------------
----
w
hile(1)
{
task1();
if(flag_ex0_isr==1)
{
flag_ex0_isr=0;
}
sta=SPI_Read(STATUS);
if(RX_DR==1 ||
TX_DS==1 || MAX_RT==1)
{
IE0=1;
//
请求中断
}
if(sta!=0x0e && sta!=0x1e)
{
send_one_byte(sta);
}
if(flag_end
==1)
{
red_led=1;
re_cnt=0;
}
}
} <
/p>
//--------------------------------------
-------------
//-----------
----------------------------------------
void int_ext0(void ) interrupt 0
{
r
ed_led=0;
s
ta=SPI_Read(STATUS);
i
f(RX_DR==1)
{
p>
SPI_Read_Buf(RD_RX_PLOAD,rx_buf,TX_PLOAD_
WIDTH);
SPI_RW_Reg(WRITE_REG +
STA
TUS,
sta);
//
清除中断
temp=0x55;
}
i
f(TX_DS==1)
{
SPI_RW_Reg(WRITE_REG +
STA
TUS,
sta);
//
清除中断
temp=0x66;
}
e
lse if(MAX_RT==1)
{
SPI_RW_Reg(FLUSH_TX,0
);
SPI_RW_Reg(WRITE_REG +
STA
TUS,
sta);
//
清除中断
temp=0x77;