![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
hi
Dependencies: mbed TM1636 RTC-DS1307
main.cpp@5:c1f6194ed8bd, 2018-12-18 (annotated)
- Committer:
- jobtanadol
- Date:
- Tue Dec 18 21:33:16 2018 +0000
- Revision:
- 5:c1f6194ed8bd
- Parent:
- 4:051852f988eb
job
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leihen | 0:431183c5b136 | 1 | #include "mbed.h" |
leihen | 0:431183c5b136 | 2 | #include "Rtc_Ds1307.h" |
jobtanadol | 4:051852f988eb | 3 | #include "TM1636.h" |
leihen | 0:431183c5b136 | 4 | |
jobtanadol | 5:c1f6194ed8bd | 5 | |
jobtanadol | 5:c1f6194ed8bd | 6 | Rtc_Ds1307 rtc(D3, D6);//sda/sci |
jobtanadol | 5:c1f6194ed8bd | 7 | DigitalIn button_K1(A5); |
jobtanadol | 5:c1f6194ed8bd | 8 | DigitalIn button_K2(A4); |
jobtanadol | 5:c1f6194ed8bd | 9 | DigitalIn button_K3(USER_BUTTON); |
jobtanadol | 5:c1f6194ed8bd | 10 | TM1636 tm1636(D7,D8); //clk/data |
leihen | 0:431183c5b136 | 11 | Serial pc(USBTX, USBRX, "pc"); |
leihen | 0:431183c5b136 | 12 | |
leihen | 1:6dbe51fe0737 | 13 | |
leihen | 0:431183c5b136 | 14 | int main() { |
jobtanadol | 4:051852f988eb | 15 | int8_t temp[4]; |
jobtanadol | 5:c1f6194ed8bd | 16 | int job[3]; |
jobtanadol | 5:c1f6194ed8bd | 17 | int total[3]; |
jobtanadol | 5:c1f6194ed8bd | 18 | int8_t run[4]; |
jobtanadol | 5:c1f6194ed8bd | 19 | button_K1.mode(PullUp); |
jobtanadol | 5:c1f6194ed8bd | 20 | button_K2.mode(PullUp); |
jobtanadol | 4:051852f988eb | 21 | tm1636.init(); |
leihen | 2:3be003301107 | 22 | Rtc_Ds1307::Time_rtc tm = {}; |
jobtanadol | 3:3d8968877eee | 23 | tm.date = 1 ; |
jobtanadol | 3:3d8968877eee | 24 | tm.mon = 1 ; |
jobtanadol | 3:3d8968877eee | 25 | tm.year = 12 ; |
jobtanadol | 3:3d8968877eee | 26 | tm.hour = 0; |
jobtanadol | 3:3d8968877eee | 27 | tm.min = 0; |
jobtanadol | 3:3d8968877eee | 28 | tm.sec = 0; |
jobtanadol | 3:3d8968877eee | 29 | rtc.setTime(tm, false, false); |
jobtanadol | 3:3d8968877eee | 30 | rtc.startClock(); |
leihen | 0:431183c5b136 | 31 | while(1) { |
jobtanadol | 5:c1f6194ed8bd | 32 | if(button_K2){ |
jobtanadol | 4:051852f988eb | 33 | rtc.getTime(tm); |
jobtanadol | 4:051852f988eb | 34 | pc.printf("%02d:%02d:%02d\n",tm.hour,tm.min,tm.sec); |
jobtanadol | 5:c1f6194ed8bd | 35 | temp[0] = tm.min / 10; |
jobtanadol | 5:c1f6194ed8bd | 36 | temp[1] = tm.min % 10; |
jobtanadol | 5:c1f6194ed8bd | 37 | temp[2] = tm.sec / 10; |
jobtanadol | 5:c1f6194ed8bd | 38 | temp[3] = tm.sec % 10; |
jobtanadol | 5:c1f6194ed8bd | 39 | tm1636.display(temp); |
jobtanadol | 5:c1f6194ed8bd | 40 | } |
jobtanadol | 5:c1f6194ed8bd | 41 | if (!button_K1){ |
jobtanadol | 5:c1f6194ed8bd | 42 | rtc.stopClock(); |
jobtanadol | 5:c1f6194ed8bd | 43 | pc.printf("%02d:%02d:%02d\n",tm.hour,tm.min,tm.sec); |
jobtanadol | 5:c1f6194ed8bd | 44 | wait(0.05); |
jobtanadol | 5:c1f6194ed8bd | 45 | rtc.getTime(tm); |
jobtanadol | 5:c1f6194ed8bd | 46 | job[0] = tm.hour; |
jobtanadol | 5:c1f6194ed8bd | 47 | job[1] = tm.min; |
jobtanadol | 5:c1f6194ed8bd | 48 | job[2] = tm.sec; |
jobtanadol | 5:c1f6194ed8bd | 49 | rtc.startClock(); |
jobtanadol | 5:c1f6194ed8bd | 50 | } |
jobtanadol | 5:c1f6194ed8bd | 51 | pc.printf("%02d:%02d:%02d++++++++++++++++++++++\n",job[0],job[1],job[2]); |
jobtanadol | 5:c1f6194ed8bd | 52 | if (!button_K2){ |
jobtanadol | 5:c1f6194ed8bd | 53 | total[0]=tm.hour-job[0]; |
jobtanadol | 5:c1f6194ed8bd | 54 | total[1]=tm.min-job[1]; |
jobtanadol | 5:c1f6194ed8bd | 55 | total[2]=tm.sec-job[2]; |
jobtanadol | 5:c1f6194ed8bd | 56 | run[0]=total[1]/10; |
jobtanadol | 5:c1f6194ed8bd | 57 | run[1]=total[1]%10; |
jobtanadol | 5:c1f6194ed8bd | 58 | run[2]=total[2]/10; |
jobtanadol | 5:c1f6194ed8bd | 59 | run[3]=total[2]%10 ; |
jobtanadol | 5:c1f6194ed8bd | 60 | tm1636.display(run); |
jobtanadol | 5:c1f6194ed8bd | 61 | wait(0.4); |
jobtanadol | 5:c1f6194ed8bd | 62 | |
jobtanadol | 5:c1f6194ed8bd | 63 | } |
jobtanadol | 5:c1f6194ed8bd | 64 | |
jobtanadol | 5:c1f6194ed8bd | 65 | if (button_K3==0){ |
jobtanadol | 5:c1f6194ed8bd | 66 | rtc.stopClock(); |
jobtanadol | 5:c1f6194ed8bd | 67 | |
jobtanadol | 5:c1f6194ed8bd | 68 | } |
jobtanadol | 4:051852f988eb | 69 | |
jobtanadol | 3:3d8968877eee | 70 | } |
jobtanadol | 3:3d8968877eee | 71 | } |
jobtanadol | 3:3d8968877eee | 72 |