본문 바로가기
개발

[Dummy]Microchip 전자시계 완성 소스

by 마스터누누 2017. 4. 18.
728x90
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/*폴링방식을 이용한 USART 실습*/
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
 
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = ON
#pragma config CP = OFF
#pragma config CPD = OFF
#pragma config BOREN = ON
#pragma config CLKOUTEN = OFF
#pragma config IESO = ON
#pragma config FCMEN = ON
 
// CONFIG2
#pragma config WRT = OFF
#pragma config VCAPEN = OFF
#pragma config PLLEN = OFF
#pragma config STVREN = ON
#pragma config BORV = LO
#pragma config LVP = ON
 
//Baud Rate 계산
#define BAUD_RATE 9600
#define FOSC 20000000
#define BRG_VALUE (FOSC/16 /BAUD_RATE - 1)
#define LED PORTDbits.RD7 //LED 출력, 비트별 설정 표현 가능
 
 
unsigned char rx_data; //UART 통신 수신 데이터 한 문자 저장
unsigned char tmr1_count;// 1초 인터럽트 회수 카운팅하는 변수
unsigned char timer_sec; // 전자 시계의 초를 카운팅하는변수
unsigned char timer_min; // 전자 시계의 분을 카운팅하는 변수
unsigned char timer_hour; // 전자 시계의 시간을 카운팅하는변수
 
unsigned char Temp_sec; // 전자 시계의 초를 수정하는 변수
unsigned char Temp_min; // 전자 시계의 분을 수정하는 변수
unsigned char Temp_hour; // 전자 시계의 시간을 수정하는 변수
unsigned char Temp_WEEK;
 
unsigned char Alarm_sec; // 전자 시계의 초를 수정하는 변수
unsigned char Alarm_min; // 전자 시계의 분을 수정하는 변수
unsigned char Alarm_hour; // 전자 시계의 시간을 수정하는 변수
unsigned char Alarm_APM; // 전자 시계의 시간을 수정하는 변수
 
unsigned char APM; // 오전 오후 카운트
unsigned char T_MODE; // MODE 설정 변수
unsigned char WEEK; // 요일 설정 변수
char check;
 
void uart_tx_string(const char *ptr_string)
{
    while(*ptr_string != 0 )
    {
        TXREG = *ptr_string++;
        while(!TRMT);
    }
}
void uart_putch(unsigned char data)
{
    TXREG = data;
    while(!TRMT);
}
 
void putch(unsigned char data) // printf를 사용하기 위한 함수
{
    TXREG = data;
    while(!TRMT);
}
 
void Init_Uart()  // USART 기본 설정 함수
{
    TRISD = 0x00//LED
    ANSELD = 0;
    //ANSELH = 0;
    SPBRG = BRG_VALUE;
    TRISCbits.TRISC7 = 1//송수신RC7(RX)핀 초기화
    TRISCbits.TRISC6 = 0//송수신RC6(TX)핀 초기화
    //UART 인터럽트 초기화
    RCIF = 0//수신 인터럽트 플래그
    TXIF = 0//송신 인터럽트 플래그
    RCIE = 0;//수신 인터럽트 설정 비트[0:Disable]
    TXIE = 0;//송신 인터럽트 설정 비트[0:Disable]
    //통신 보레이트 설정 : 9600 bps
    SPBRG = BRG_VALUE; //define문에서 설정됨
    //TXSTA 레지스터 송신 초기화
    TXEN = 1;//TX 송신 모듈 On [1:Enable]
    BRGH = 1;//고속 보오레이트 설정 On [1:Enable]
    TX9 = 0//9Bit 송신 설정 비트 [0:8Bit]
    SYNC = 0;//동기/비동기 통신 모드 [0:비동기]
    //RCSTA 레지스터 수신 초기화
    SPEN = 1;//시리얼포트 RX, TX 핀 사용[1:Enable]
    CREN =1//연속 수신 가능 On [1:Enable]
    RX9 = 0//9Bit 수신 설정 비트 [0:8Bit]
}
void Init_port()
{
    TRISD = 0x00//PORTD 출력설정
    ANSELD = 0;
    //ANSELH= 0;
 
}
 
void initial_timer1_interrupt(void)
{
    TMR1H = 0//타이머1 값 설정
    TMR1L = 0;
    TMR1IE = 0//타이머1 인터럽트 설정 : 인터럽트 기능 Disable
    TMR1IF = 0//타이머1의 인터럽트 플래그 초기화 -> 0
    T1CON = 0b00110000//타이머1 프리스케일러 1:8
    TMR1L=(65536-62500)%256//0.1초 카운트값 초기화
    TMR1H=(65536-62500)/256;
    TMR1IE = 1//타이머1 인터럽트 설정 :Enable 설정
    PEIE = 1//타이머1의 주변장치 인터럽트 비트 : ON
    GIE =1//전체 인터럽트 비트 : ON
    TMR1ON = 1//타이머1 ON
}
 
void interrupt isr(void)
{
    if(TMR1IF == 1)
    {
        TMR1IF=0//타이머1 인터럽트 플래그 다시 0을만들어서시간 재기
        TMR1L=(65536-62500)%256//0.1초 카운트값 초기화
        TMR1H=(65536-62500)/256;
        tmr1_count++;
 
        if(tmr1_count==10//변수 값이 10번이므로 1초가 됨
        {
            LED ^= 1//RD7 LED Toggle
            tmr1_count = 0// 다시 10번 카운트하기 위해 리셋
            timer_sec++// 00 초에서 59 초까지 카운팅
 
            if(timer_sec>=60)  // 60초가 되었을 때
            {
                timer_sec=0// 초 초기화
                timer_min++// 분 증가
 
                if(timer_min>=60// 60분이 되었을 때
                {
                    timer_min=0// 초 초기화
                    timer_hour++// 시 증가
 
                    if(T_MODE==0// 12시간 모드(AM/PM) 사용시
                    {
                        if((timer_hour>=13)&&APM==0// 시간이 12를 넘고 AM일 때
                        {
                            timer_hour=0// 시 초기화
                            APM++// PM으로 증가
                        }
                        else if((timer_hour>=13)&&APM==1// 시간이 12를 넘고 PM일 때
                        {
                            timer_hour=0// 시 초기화
                            WEEK++// 요일 증가
                            if(WEEK==7// 일요일인 경우
                            {
                                WEEK=0// 요일 초기화
                            }
                            APM=0// AM으로 초기화
                        }
                    }
                    else  // 24시간 모드 사용시
                    {
                        if(timer_hour>=24// 시간이 24시를 넘어갈 때
                        {
                            WEEK++// 요일 증가
                            if(WEEK==7// 일요일인 경우
                            {
                                WEEK=0// 요일 초기화
                            }
                            timer_hour=0// 시 초기화
                        }
                    }
                    
                }
            }
        }
     }
}
 
 
 main()
{
    //전역 변수
    rx_data=0//UART 통신 수신 데이터 한 문자 저장 초기화
    tmr1_count=0//1초 인터럽트 회수 카운팅하는 전역 변수 초기화
    timer_sec=0// 전자 시계의 초를 카운팅하는 전역 변수 초기화
    timer_min=0// 전자 시계의 분을 카운팅하는 전역 변수 초기화
    timer_hour=0// 전자 시계의 시간을 카운팅하는 전역 변수 초기화
 
    Temp_sec=0// 전자 시계의 초를 수정하는 변수 초기화
    Temp_min=0// 전자 시계의 분을 수정하는 변수 초기화
    Temp_hour=0// 전자 시계의 시간을 수정하는 변수 초기화
 
    Alarm_sec=0// 알람의 초를 수정하는 변수 초기화
    Alarm_min=59// 알람의 분을 수정하는 변수 초기화 - 시작과 동시에 알람 울리지 않게 세팅
    Alarm_hour=12// 알람의 시간을 수정하는 변수 초기화 - 시작과 동시에 알람 울리지 않게 세팅
    Alarm_APM=0// 알람의 A/PM을 수정하는 변수 초기화
 
    APM=0// A/PM을 수정하는 변수 초기화
    initial_timer1_interrupt(); // timer interrupt의 초기값 함수
    Init_Uart(); // UART의 초기값 함수
 
     while(1)
     {
        switch(T_MODE)
        {
            case 1 :  // 12시간 모드(AM/PM)
                if(WEEK==0// 월요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Mon. %2d : %2d : %2d AM\r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Mon. %2d : %2d : %2d PM\r", timer_hour, timer_min, timer_sec);
                    }
                }
                else if(WEEK==1// 화요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Thu. %2d : %2d : %2d AM\r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Thu. %2d : %2d : %2d PM\r", timer_hour, timer_min, timer_sec);
                    }
                }
                else if(WEEK==2// 수요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Wed. %2d : %2d : %2d AM\r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Wed. %2d : %2d : %2d PM\r", timer_hour, timer_min, timer_sec);
                    }
                }
                else if(WEEK==3// 목요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Thu. %2d : %2d : %2d AM\r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Thu. %2d : %2d : %2d PM\r", timer_hour, timer_min, timer_sec);
                    }
                }
                else if(WEEK==4// 금요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Fri. %2d : %2d : %2d AM\r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Fri. %2d : %2d : %2d PM\r", timer_hour, timer_min, timer_sec);
                    }
                }
                else if(WEEK==5// 토요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Sat. %2d : %2d : %2d AM\r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Sat. %2d : %2d : %2d PM\r", timer_hour, timer_min, timer_sec);
                    }
                }
                else if(WEEK==6// 일요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Sun. %2d : %2d : %2d AM\r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Sun. %2d : %2d : %2d PM\r", timer_hour, timer_min, timer_sec);
                    }
                }
                
 
                if((timer_hour==Alarm_hour)&&(timer_min==Alarm_min)&&(APM==Alarm_APM)) // 알람 변수와 시간변수가 같을 때
                {
                printf("Wake up Bro!"); // 알람 문구 출력
                }
                Temp_sec=0// 전자 시계의 초를 수정하는 변수 초기화
                Temp_min=0// 전자 시계의 분을 수정하는 변수 초기화
                Temp_hour=0// 전자 시계의 시간을 수정하는 변수 초기화
                Temp_WEEK=0// 전자 시계의 요일을 수정하는 변수 초기화
                break;
 
            case 2 : // 24시간 모드
                if(WEEK==0// 월요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Mon. %2d : %2d : %2d \r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Mon. %2d : %2d : %2d \r", timer_hour+12, timer_min, timer_sec);
                    }
                }
                else if(WEEK==1// 화요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Tue. %2d : %2d : %2d \r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Tue. %2d : %2d : %2d \r", timer_hour+12, timer_min, timer_sec);
                    }
                }
                else if(WEEK==2// 수요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Wed. %2d : %2d : %2d \r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Wed. %2d : %2d : %2d \r", timer_hour+12, timer_min, timer_sec);
                    }
                }
                else if(WEEK==3)  // 목요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Thu. %2d : %2d : %2d \r", timer_hour, timer_min, timer_sec);
                    }
                    else //PM
                    {
                        printf("UART Timer Thu. %2d : %2d : %2d \r", timer_hour+12, timer_min, timer_sec);
                    }
                }
                else if(WEEK==4// 금요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Fri. %2d : %2d : %2d \r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Fri. %2d : %2d : %2d \r", timer_hour+12, timer_min, timer_sec);
                    }
                }
                else if(WEEK==5// 토요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Sat. %2d : %2d : %2d \r", timer_hour, timer_min, timer_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Sat. %2d : %2d : %2d \r", timer_hour+12, timer_min, timer_sec);
                    }
                }
                else if(WEEK==6// 일요일
                {
                    if(APM==0)  // AM
                    {
                        printf("UART Timer Sun. %2d : %2d : %2d \r", timer_hour, timer_min, timer_sec);
                    }
                    else  // PM
                    {
                        printf("UART Timer Sun. %2d : %2d : %2d \r", timer_hour+12, timer_min, timer_sec);
                    }
                }
 
                
 
                if((timer_hour==Alarm_hour)&&(timer_min==Alarm_min)&&(APM==Alarm_APM)) // 알람 변수와 시간변수가 같을 때
                {
                printf("Wake up Bro!"); // 알람 문구 출력
                }
                Temp_sec=0// 전자 시계의 초를 수정하는 변수 초기화
                Temp_min=0// 전자 시계의 분을 수정하는 변수 초기화
                Temp_hour=0// 전자 시계의 시간을 수정하는 변수 초기화
                Temp_WEEK=0// 전자 시계의 요일을 수정하는 변수 초기화
                break;
 
            case 3 : // RESET 모드
                if(check==1)
                {
                    timer_sec=0// 전자 시계의 초를 카운팅하는 전역 변수 초기화
                    timer_min=0// 전자 시계의 분을 카운팅하는 전역 변수 초기화
                    timer_hour=0// 전자 시계의 시간을 카운팅하는 전역 변수 초기
                    check=0;
                }
                printf("UART Timer %2d : %2d : %2d \r", timer_hour, timer_min, timer_sec); // 시간 출력
                break;
            
            case 4 : // 시간 수정 모드
                if(Temp_WEEK==0// 월요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Mon. %2d : %2d : %2d AM\r", Temp_hour, Temp_min, Temp_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Mon. %2d : %2d : %2d PM \r", Temp_hour, Temp_min, Temp_sec);
                    }
                }
                else if(Temp_WEEK==1// 화요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Tue. %2d : %2d : %2d AM\r", Temp_hour, Temp_min, Temp_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Tue. %2d : %2d : %2d PM \r", Temp_hour, Temp_min, Temp_sec);
                    }
                }
                else if(Temp_WEEK==2// 수요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Wed. %2d : %2d : %2d AM\r", Temp_hour, Temp_min, Temp_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Wed. %2d : %2d : %2d PM \r", Temp_hour, Temp_min, Temp_sec);
                    }
                }
                else if(Temp_WEEK==3// 목요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Thu. %2d : %2d : %2d AM\r", Temp_hour, Temp_min, Temp_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Thu. %2d : %2d : %2d PM \r", Temp_hour, Temp_min, Temp_sec);
                    }
                }
                else if(Temp_WEEK==4// 금요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Fri. %2d : %2d : %2d AM\r", Temp_hour, Temp_min, Temp_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Fri. %2d : %2d : %2d PM \r", Temp_hour, Temp_min, Temp_sec);
                    }
                }
                else if(Temp_WEEK==5// 토요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Sat. %2d : %2d : %2d AM\r", Temp_hour, Temp_min, Temp_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Sat. %2d : %2d : %2d PM \r", Temp_hour, Temp_min, Temp_sec);
                    }
                }
                else if(Temp_WEEK==6// 일요일
                {
                    if(APM==0// AM
                    {
                        printf("UART Timer Sun. %2d : %2d : %2d AM\r", Temp_hour, Temp_min, Temp_sec);
                    }
                    else // PM
                    {
                        printf("UART Timer Sun. %2d : %2d : %2d PM \r", Temp_hour, Temp_min, Temp_sec);
                    }
                }
                
                WEEK=Temp_WEEK; // 설정한 값을 요일에 대입
                timer_hour=Temp_hour;// 설정한 값을 시간에 대입
                timer_min=Temp_min;// 설정한 값을 분에 대입
                timer_sec=Temp_sec;// 설정한 값을 초에 대입
                break;
 
            case 5 :
                if(Alarm_APM==0// 알람의 설정이 AM일 때
                {
                    printf("UART Timer %2d : %2d : %2d AM\r", Alarm_hour, Alarm_min, Alarm_sec);
                }
                else  // 알람의 설정이 PM일 때
                {
                    printf("UART Timer %2d : %2d : %2d PM\r", Alarm_hour, Alarm_min, Alarm_sec);
                }
                break;
            
            case 6 :
                printf("1: 12T_MODE 2: 24T_MODE 3: RESET 4: MODIFY 5: ALARM SET 6:Menu \r"); // 디폴트 출력문구
                break;
 
            default:
                printf("1: 12T_MODE 2: 24T_MODE 3: RESET 4: MODIFY 5: ALARM SET 6:Menu \r"); // 디폴트 출력문구
                break;
        }
 
        
        
 
         if(RCIF==1)//
         {
             if(RCREG =='1')//수신 Register에 1 값이 들어갔을때
             {
                 printf("\n"); // 개행
                 T_MODE=1// MODE 1로 설정
             }
             else if(RCREG =='2')//수신 Register에 2 값이 들어갔을때
             {
                 printf("\n"); // 개행
                 T_MODE=2;// MODE 2로 설정
             }
             else if(RCREG =='3')//수신 Register에 3 값이 들어갔을때
             {
                 printf("\n"); // 개행
                 check=1;
                 Alarm_sec=0// 알람의 초를 수정하는 변수 초기화
                 Alarm_min=59// 알람의 분을 수정하는 변수 초기화
                 Alarm_hour=12;// 알람의 시간을 수정하는 변수 초기화
                 Alarm_APM=0// 알람의 A/PM을 수정하는 변수 초기화
                 T_MODE=3// MODE 3으로 설정
             }
             else if(RCREG =='4')//수신 Register에 4 값이 들어갔을때
             {
                 printf("\n"); // 개행
                 printf("q: hour increase w: min increase e: am set r: pm set t: Day set \r\n");
                 // MODE 4의 입력 키 안내 문구 출력
                 T_MODE=4// MODE 4로 설정
             }
             else if(RCREG =='5')//수신 Register에 5 값이 들어갔을때
             {
                 printf("\n"); // 개행
                 printf("a: hour increase s: min increase d: am set f: pm set\r\n");
                 // MODE 5의 입력 키 안내 문구 출력
                 T_MODE=5// MODE 5로 설정
             }
             else if(RCREG =='6')//수신 Register에 6 값이 들어갔을때
             {
                 printf("\n"); // 개행
                 T_MODE=6// MODE 6으로 설정
             }
             else if(RCREG =='q')//수신 Register에 q 값이 들어갔을때
             {
                 Temp_hour++// 수정 시간 값 증가
                 if(Temp_hour>=13// 시간이 12를 넘어 갔을때
                 {
                 Temp_hour=0;  // 초기화
                 }
             }
             else if(RCREG =='w')//수신 Register에 w 값이 들어갔을때
             {
                 Temp_min++// 수정 분 값 증가
                 if(Temp_min>=60// 분이 59를 넘어갔을 때
                 {
                 Temp_min=0// 초기화
                 }
             }
             else if(RCREG =='e')//수신 Register에 e 값이 들어갔을때
             {
                 APM=0// AM으로 설정
             }
             else if(RCREG =='r')//수신 Register에 r 값이 들어갔을때
             {
                 APM=1// PM으로 설정
             }
             else if(RCREG =='t')//수신 Register에 t 값이 들어갔을때
             {
                 Temp_WEEK++;  // 수정 요일 값 증가
                 if(Temp_WEEK==7// 일요일을 넘어갔을 때
                 {
                     Temp_WEEK=0// 월요일로 초기화
                 }
             }
             else if(RCREG =='a')//수신 Register에 a 값이 들어갔을때
             {
                 Alarm_hour++// 알람 시간 값 증가
                 if(Alarm_hour>=13// 알람 시간이 12를 넘어갔을 때
                 {
                 Alarm_hour=0// 초기화
                 }
             }
             else if(RCREG =='s')//수신 Register에 s 값이 들어갔을때
             {
                 Alarm_min++// 알람 분값 증가
                 if(Alarm_min>=60// 알람 시간이 59를 넘어 갔을 때
                 {
                 Alarm_min=0// 초기화
                 }
             }
             else if(RCREG =='d')//수신 Register에 d 값이 들어갔을때
             {
                 Alarm_APM=0// 알람 시간 AM으로 설정
             }
             else if(RCREG =='f')//수신 Register에 f 값이 들어갔을때
             {
                 Alarm_APM=1// 알람 시간 PM으로 설정
             }
             else if(RCREG =']')//수신 Register에 ] 값이 들어갔을때
             {
                 T_MODE=6;
             }
             else
             { 
                 printf("\n"); // 개행
                 printf("1: 12T_MODE 2: 24T_MODE 3: RESET 4: MODIFY 5: ALARM SET  6:Menu\r");
                 // 디폴트 출력 문구
                 T_MODE=0// 디폴트 모드
             }
             RCIF=0// 플래그 초기화
         }
     }
 }
cs


반응형

'개발' 카테고리의 다른 글

[STM32] GPIO 사용방법  (0) 2017.04.18
[STM32] keil설정 및 다운로드  (0) 2017.04.18
[꿀팁] Git log 예쁘게 출력해서 보기  (0) 2017.04.18
[꿀팁] mac osx MYSQL 설치  (0) 2017.04.18
[GIT]How to write good git message  (1) 2017.04.18

댓글