⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clock_app.c

📁 MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis的0.9.5版本的源码。
💻 C
字号:
//  This file is part of MANTIS OS, Operating System//  See http://mantis.cs.colorado.edu/////  Copyright (C) 2003,2004,2005 University of Colorado, Boulder////  This program is free software; you can redistribute it and/or//  modify it under the terms of the mos license (see file LICENSE)/*   file:  clock_app.c   * edited:  Charles Gruenwald III *   date:  02/23/04 * */#include "mos.h"#include "clock.h"#include "clock_app.h"#include "led.h"#include "command_daemon.h"#include "msched.h"#include "printf.h"// time registersATimer atimes;static mos_alarm_t timer;bool constant_update = false;void lprintf(uint8_t in_int);//print the time in MM/DD/YYYY HH:MM:SS formatvoid print_time(void){   lprintf(atimes.month);   printf("/");   lprintf(atimes.day);   printf("/%l ",atimes.year);     lprintf(atimes.hours);   printf (":");   lprintf(atimes.minutes);   printf (":");   lprintf(atimes.seconds);   printf("\r");}//this function prints leading zeroesvoid lprintf(uint8_t in_int){   if(in_int <= 9)      printf("0%d",in_int);   else      printf("%d" ,in_int);}void set_time(void){   atimes.year = prompt_uint8("");   atimes.month = prompt_uint8("");   atimes.day = prompt_uint8("");   atimes.hours = prompt_uint8("");   atimes.minutes = prompt_uint8("");   atimes.seconds = prompt_uint8("");}void set_constant_update(void){   constant_update = true;}void stop_constant_update(void){   constant_update = false;}void start(void){   clock_app_init();   //start the command daemon..   mos_thread_new(mos_command_daemon, 128, PRIORITY_NORMAL);   mos_register_function("set_time", set_time);   mos_register_function("show_time", print_time);   mos_register_function("constant", set_constant_update);   mos_register_function("stop", stop_constant_update);}void clock_app_init(void){   atimes.mtics = 0;   atimes.seconds = 0;   atimes.minutes = 5;   atimes.hours = 9;   atimes.day = 22;   atimes.month = 2;   atimes.year = 2004;   timer.func = clock_service;   constant_update = false;   mos_alarm(&timer, 1, 0); //every second}/** Clock service, couting the time from the initialization */void clock_service(void *p){   mos_alarm (&timer, 1 ,0);   atimes.seconds++;	  //increment total secs   mos_led_display(atimes.seconds);   print_time();   if(atimes.seconds > 59) {      atimes.seconds -= 60;      atimes.minutes++;	      if(atimes.minutes > 59) {	 atimes.minutes -= 60;	 atimes.hours++;		 if(atimes.hours > 23) {	    atimes.hours -= 24;	    atimes.day++;#ifdef ARCH_AVR	    if(atimes.day == pgm_read_byte(&MonthDayTable[atimes.month - 1])) {#else	    if(atimes.day == MonthDayTable[atimes.month - 1]) {#endif	       atimes.day = 1;	       atimes.month++;	       if(atimes.month == 13) {		  atimes.month = 1;		  atimes.year++;	       }//month	    }//day	 }//hour      }//minutes   }//seconds}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -