/*************************************************
$ y( Y1 h$ x! y! y- Z; V * Func
tion: RTC初始化函数
0 R) ^+ t8 w4 L: K' Z
* parameter
+ @& S3 }* w( [6 p' C& P
* Return
5 E/ n* n0 F- w8 l. g9 f ^/ g * Modify:
: w' f/ M6 j3 V**************************************************/
3 a% ]1 B3 X4 L a
void RTC_Time_Init(void)
) M# E/ Q- K, c0 U{
% \! ?9 Y: f: a( ~# w- ?% }
cur_time.year = 17; //设置时间
+ ^ _' p# G- C7 Q$ h7 p
cur_time.month = 3;
4 i1 @. y8 Q7 S* A9 n$ r; E0 l
cur_time.date = 23;
- M+ P8 e" j; A cur_time.weekday = 4;
+ Q% |% o* E+ M cur_time.hr = 23;
( Z2 G6 A+ S6 F& G
cur_time.min = 58;
, Z; I) R/ c, q- ^: w cur_time.sec = 0;
6 }$ M0 ?0 i2 V Time_Run.WeekDays_DATA =cur_time.weekday;
5 z& m' g' J( J! b" h. y+ F
MicoRtcSetTime(&cur_time); //初始化 RTC 时钟的时间
/ N/ \2 _* `4 o5 v& Z" H}
9 S+ H% G0 ?5 F+ W! ?, Q5 M8 ?( y
/*************************************************
}8 V2 a# h5 d2 G# c5 O1 O * Function: RTC时间允许读取函数
) n7 o& A9 |/ P9 X5 t8 y
* parameter
- h: \" i8 x. M7 ^7 c' ?: U * Return
# N3 S- q, s% h
* Modify:
( X3 _, R1 g+ P- v9 o0 ]1 D**************************************************/
5 x0 W& }1 v+ o% Q5 Fvoid RTC_Time_Run(unsigned int arg)
4 R/ x6 s# h$ r5 U2 D{
; d$ i$ ], J. ?4 q$ v* X* ]% o RTC_Time_Init();
4 C" p1 c* p+ K9 R2 [ ~4 D
while(1)
8 a2 T6 q" I; i9 O" S
{
8 T0 {( P) S2 ^" X* p
MicoRtcGetTime(&cur_time); //返回新的时间值
3 D/ n! F: ?& ]# G- U/ t }
7 a9 s' ~0 [& a# L( f+ }- A/ Z! y2 v}
: ]* f/ C* G0 d4 V; B# Q
int application_start( void )
( p) N. e+ a5 J% B( M
{
: A9 h/ q, Y3 s' V1 N- M5 ^
OSStatus err = kNoErr;
0 J6 A9 y2 P6 T( G6 T) r2 x4 v$ G" _. V8 |. ~" J% P( M Z5 v4 t
MicoInit();
% f* O6 g- A% w* M( f! }
* k; X* G3 ~9 o" G$ m$ o& v3 R
/* Start MiCO system functions according to mico_config.h,
1 f* h3 A% ~& G& y M
Define macro MICO_WLAN_CONNECTION_ENABLE to enable wlan connection function
% [5 v7 t% I) Q+ O2 h
Select wlan configuration mode: MICO_CONFIG_MODE
, f. [( X# V } @ Define EasyLink settings */
* l0 x- w& I5 D2 n# a
err = mico_system_init( mico_system_context_init( 0 ) );
, I9 ?- y, E$ X/ U: |* E; x) D
4 ~7 S- {: n3 |
/* Register user function when wlan connection status is changed */
7 K5 @7 i" K5 q
err = mico_system_notify_register( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler, NULL );
0 n! _# i% c! \( ^- f4 N+ v2 B! O1 q- G9 _
/* Register user function when wlan connection is faile in one attempt */
- c1 N9 ~7 w+ h. p6 V- z
err = mico_system_notify_register( mico_notify_WIFI_CONNECT_FAILED, (void *)micoNotify_ConnectFailedHandler, NULL );
. J7 M, m$ r2 [+ w0 }. x
4 R7 S9 e ^5 h1 m. o9 |
ext_rgb_led_log("rgb led conrtol demo(RGB_MODE)");
0 b! D" s- E1 f: Z. [ /*创建一个时间运行线程*/
, i8 j+ C; \- R/ l& k4 I err = mico_rtos_create_thread(NULL,MICO_APPLICATION_PRIORITY,"RTC Time Run",RTC_Time_Run,200,NULL);//创建并启动一个新的线程
1 i. ]. D* n. H8 R+ y: Q$ x J& w; S7 \8 n* n" O
/*初始化 RGB LED(P9813)*/
. ? p1 C4 o* A" ~# j5 H, c
rgb_led_init();
1 N8 y! K {, ? MicoGpioOutputHigh(MICO_RF_LED);
8 R" u G. i' h& R$ w //while(1) {
6 J% d9 Y' N7 A$ D) L' t2 X1 @
/*RGB LED亮红灯,#FF0000*/
8 x8 c) X% t; b: s // rgb_led_open(255, 0, 0);
; ^# X9 ]5 K) d Q' j
// mico_thread_sleep(1);
( }3 x7 B. {# Q /*RGB LED亮绿灯 #00FF00*/
0 `3 s _# r9 Y# ~ w9 F6 W+ x# j // rgb_led_open(0, 255, 0);
7 n+ |7 V. f8 P& p7 I# { // mico_thread_sleep(1);
$ z& s* v) b' M, Y- g" I9 I
/*RGB LED亮蓝灯,#0000FF*/
( G; H" u- r a# Q4 e9 ^ d
// rgb_led_open(0, 0, 255);
( ]! Y* i4 L Z. W3 f- ~5 u
// mico_thread_sleep(1);
; _; t/ q/ H3 e5 Z8 J4 D
// }*/
# O4 v7 b9 f+ _: l. E /*LED1初始化*/
* _/ o6 I1 i2 r* N3 T) Q0 R- J/ C: R& o err = RUN_LED_init();
0 {& z+ z2 e( r8 D" H+ v
! S" p3 b' ~' N: i) ]- n6 P/ H
/* 初始化 直流电机 */
+ A B: M8 @3 k. P err = dc_motor_init();
M0 s9 M; O b: D" c5 w1 P
' U L% a. Y" Y& S9 i* w$ \9 m8 g4 f9 K. Y8 f3 Y z& r$ f' N
/*初始化 温度 湿度*/
: i* }& {) a6 C( s& p+ L err = DHT11_Init();
) y& V* O7 E: Y4 S0 r V! f, d$ d4 E' }5 p8 B" f; _# c
* e- {5 M+ k' R8 y$ p
/*初始化 光发射二极管*/
% K0 }# D7 t# P$ m
OLED_Init();
. e; G$ t9 x8 {- V: n- F OLED_ShowString(0, 2, " Le Ju Le Yun");
8 H% A! P0 U, u/ N' A% S8 G% J" [" L, u' p) O6 b
/*初始化光强传感器*/
. P$ V, n) f# T l err = light_sensor_init();
* h) V$ Z2 P; @/ |0 Q/ w% a
3 t# V$ g$ A! _" U7 |
/*按键初始化*/
+ P5 i( K. [" L% y2 H# O GPIO_KEY_Init();
3 e0 M. s& k2 J1 K4 K, l* R
) |- t6 Q0 @% \. _9 ?) @
mico_rtos_delete_thread(NULL);
1 w2 s. Q; l* m3 f$ E% x/ u4 W return err;
+ C) J9 _& i& s! P
}
, f- I6 F( v% Z7 H( Y
6 f6 U2 N. n' T$ t" z9 x* A! R& E4 Q. c6 o3 N- K