TA的每日心情 | 开心 2019-11-20 15:00 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
5 r! f' p. m, N. I- p: j
/******************************************************************************/1 J" f1 q7 u7 P) v# W6 f
/*
: \6 N- j6 F7 C0 ^' T// 文件名:main.c
( w, [. C E* ~// 说明:供客户测试模块通信使用程序 4 o% ^8 Q5 u- j; ]; q, V
// 编写人员:
" m T+ ]3 O% P0 l// 编写日期:
7 b, k* w% G/ {" p0 v2 w4 B- ]0 L// 程序维护:
, W. P0 c# Y0 @' y/ Z$ v5 s// 维护记录:
" P+ n% q# v& V& v8 t//
3 z: I% V- F7 B; ?//
, J; X3 g' u$ d6 k7 a+ s) h*/ & R+ {7 F$ Q" ` b6 _7 S
// 免责声明:该程序仅用于学习与交流
# k; H- u. M- h1 k// (c) Anxinke Corporation. All rights reserved.
9 c0 O* u' m% g! t: L5 E. x- Q4 d7 |/******************************************************************************/0 h& Q! w# C. D0 h
#include "typedef.h"7 M# ~9 f, v% A. n
#include "gpio.h"
! M, `; e; v+ O9 V5 N#include "uart.h"
$ g( ^4 h$ w' O/ R#include "nRF24l01p.h"
6 O" T2 q" f+ y: i% y9 S) Q, V#include "delay.h"
+ b2 x; k2 E7 b+ m. J
! [% |" V% G6 v0 p! [+ S% xuchar txData[32] = {0x00};! b1 B$ ~ {* v
uchar rxData[32] = {0x00};
2 a% G6 n) O& C
& L' d! C- _8 E- B$ X2 W2 c: R/******************************************************************************/& }/ e" c' {2 @5 \9 V e* u- [" ]$ s
// 函数名称:main
9 @2 m$ D% h/ D// 输入参数:
. c9 c) r6 L5 L# ^- O( X& n U" n3 A// 输出参数: & h7 d+ o/ E& H0 [0 Z( D5 r
// 函数功能:
$ h2 |* f7 N( L% h. b2 F# U5 H/******************************************************************************/1 L+ N3 I7 I1 E5 T3 Q% \
void main(void)
% T3 d- t! I5 O$ O{0 o, }; _8 F. F$ d+ i- @
unsigned char i=0;
+ M5 v+ L0 ^7 c& I uartInit(); 3 |2 P) a# A( _9 H( k4 Z$ h
Delay100ms();0 J" v8 m' c7 i! Y' w
init_nrf24l01_io();4 ?5 A3 Y: S! R/ f7 }1 R0 i
led1ON();+ A+ R- \) o* w+ X( b
Delay100ms();% H! T6 [: c' X" h
led1OFF();& V; c8 t$ X2 d, f1 Z) I4 p
Delay100ms();
) |5 F* N) ^% Z& ]7 j led1ON();
0 c7 p/ \: d' [( U3 ` Delay100ms();2 ?! J& J$ N2 s7 H: A% S
led1OFF();
* ~- ^: x ]1 f! x# w: R5 T# T& l
/ a }# C5 R8 i, b9 b! { Delay100ms();# `9 j% Z7 e3 | j
uartSendString("System initialization is complete!\r\n");
9 [$ v: K8 G" \ K( O receive_mode_init();1 p2 |: V+ w; r
+ m Y2 @* _# J& W while(1)8 ], I+ N1 h8 ]% y( `3 ]6 o9 {8 M9 p" l0 u
{
; I, m# `) D* [$ d. W1 N6 J KEY1 = 1;1 J5 e5 x x# D6 G i6 C- k
KEY2 = 1; D8 b/ k0 B( p7 b+ F
/*
' G* [/ A9 X3 v * 判断是否按下KEY( [' h% ?0 o$ ~5 g3 F2 D7 f
*/
R2 C& i) M+ y9 ~, z) p, e if (key1ON() || key2ON()) {
/ R; }# g4 H J1 M$ X( I _delay_us(500);
/ D; |- l6 t! G1 M" j' \ txData[0] = 0;" E! r9 e- N P: u' d5 a
if (key1ON()) {
3 _1 {& G0 y: n txData[0] = 0xAA; // 如果按下K1 则将数据置为0xAA 8 w/ O j6 G2 X& G( W6 N- J
uartSendString("You press the left button\r\n");
) {# V2 z9 ?* `6 ?/ f } else if (key2ON()){$ N6 o& E8 r+ r) U# ]- M
txData[0] = 0x55; // 如果按下K2 则将数据置为0x554 l# j5 h0 z. C2 f3 [3 b
uartSendString("You press the Right button\r\n");
6 y3 |) ?( G* ~+ Z" h- a }5 e& z; a( N! A
/*
: s8 p" M/ g% n' _& T/ a8 f * 根据不同的数据LED提示
2 k# O0 l! Z7 |+ ? */7 m/ @1 e, C8 p) M! v
if (send_data(txData) == 1) {
9 @ U; l6 d: M uartSendString("Success of sending data\r\n");8 X' i, ~6 K7 l6 C. {: Q
if (txData[0] == 0xAA) {0 G' k0 \" W, e( \
led1ON();
+ n3 C; X0 G4 T q3 n9 ]4 ] } else if (txData[0] == 0x55) {- `9 v- X# r+ w4 c) E7 R5 u
led2ON();
! K6 c$ t. |/ B* x+ f+ P7 G) [ }
% m! [& b* Y; G8 Z Delay100ms(); 4 p8 |; I# D( `6 ~4 a# I
led1OFF();
1 i4 G7 ?' A n5 k& I, a0 _- d/ h led2OFF();
" Q" Q8 _$ q1 g" s7 ~ } else {
# X: V$ m$ Y1 m3 D uartSendString("Failed to send data\r\n");" S- \1 }: i' J
}
& g7 U, E3 u5 G4 @+ O receive_mode_init();
1 s1 I+ k6 i1 u1 @, H: ?; H }
# N1 c1 q/ T, s rxData[0] = 0;: o/ E/ \; @4 o: o" Z3 f+ z
led1OFF();
8 d% b+ Y, W) H9 a7 Q led2OFF();
" |! y D' w+ Z1 l3 h( |/ C if (receive_data(rxData)) {+ q5 ]! M8 A U. K8 z0 l+ b
if (rxData[0] == 0xAA) {, @7 ~7 ` }6 S" Y+ l: Y
led1ON();
6 |1 @7 ?( Q @( y4 q" J# S5 A uartSendString("Receiving the data, from the Left\r\n");
# t$ u5 w& ]" \- y } else if (rxData[0] == 0x55) {
# x \* X. z: J8 K; l3 |/ `( c( B led2ON();+ \+ c/ U3 w# _6 ~+ H8 c2 Q
uartSendString("Receiving the data, from the Right\r\n");
6 G8 D$ X! F+ ?7 b- r) S }3 U2 v s' ^9 y/ f4 ]- H+ G
Delay100ms();
2 q# a4 [& k- }, t* h- x4 V" O7 y }
3 W3 ~* P* \$ _9 x+ y, P! n! @5 v* t
( E$ w5 |. p Q$ V- q2 J! ` }
* K* v$ K3 n! d! l, h- M}1 ]* m7 O! d6 n
' i. L2 Y( T( b& R' G' D |/ A
+ o: s! l4 {# `9 K6 w
|
|