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

📄 freescale

📁 Freescale 系列单片机常用模块与综合系统设计
💻
字号:
/** ###################################################################
**     Filename  : rtc.C
**     Project   : rtc
**     Processor : MC9S08JM60CLHE
**     Version   : Driver 01.11
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 2009-10-1, 16:36
**     Abstract  :
**         Main module.
**         This module contains user's application code.
**     Settings  :
**     Contents  :
**         No public methods
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2008
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/
/* MODULE rtc */


/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "TimeDate.h"
#include "SW1.h"
#include "SW2.h"
#include "SW3.h"
#include "SW4.h"
#include "LED.h"
#include "LCD_CONTROL.h"
#include "LCD_DATA.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "LCD1602.h"

dword counter;
byte result, pastday,  pastminute, adjustedhour;
byte OldSW1, OldSW2, OldSW3, OldSW4;
byte NewSW1, NewSW2, NewSW3, NewSW4;
byte SW4toggle, getmonth, getday, myhour, mymin;//, temp1, temp2;
word getyear;

  
void main(void)
{
  /* Write your local variable definition here */
   byte  a[] = "Date:";
   byte  b[] = "Time:";
   byte LEDarray[5] = {FALSE, FALSE,FALSE,FALSE,FALSE}, LEDcounter, i,j;
  byte c;
  TIMEREC Time;
  DATEREC Date;
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
  SW4toggle = FALSE;
  counter = 0;
  LEDcounter = 0;
  pastminute = 0;
  pastday = 0;
  
  /* Write your code here */
  for(;;) {
      //按键1按下,则显示日期
      result = TimeDate_GetDate( &Date );
      NewSW1 = SW1_GetVal();// >> 4;
      if (  (Date.Day != pastday) || (NewSW1 != OldSW1)  ) 
      {
        Lcd_Show_Line1(a, 6);
        
        if (NewSW1 == 0) 
        { 
             Lcd_Show_Line2(Date.Month);
             Lcd_Show_Line2(':');
             Lcd_Show_Line2(Date.Day);
             Lcd_Show_Line2(':');
             Lcd_Show_Line2(Date.Year);
        }
        else if	 (Date.Day != pastday)  
        {
             Lcd_Show_Line2(Date.Month);
             Lcd_Show_Line2(':');
             Lcd_Show_Line2(Date.Day);
             Lcd_Show_Line2(':');
             Lcd_Show_Line2(Date.Year);
        }
        pastday =  Date.Day;
        OldSW1 = NewSW1;
      }
      
      //按键2按下,则显示时间
      result = TimeDate_GetTime( &Time );
      NewSW2 = SW2_GetVal();
      if ((Time.Min != pastminute) || (NewSW2 != OldSW2) )	 
      {
          Lcd_Show_Line1(b, 6);
          
      		if ((NewSW2 == 0)) {	                //是否有按键按下?
              if (Time.Hour > 12)	
              {
                   Lcd_Show_Line2(Time.Hour-12);
                   Lcd_Show_Line2(':');
                   Lcd_Show_Line2(Time.Min);
                   Lcd_Show_Line2(':');
                   Lcd_Show_Line2(Time.Sec);
              }
              else			 
              {
                   Lcd_Show_Line2(Time.Hour);
                   Lcd_Show_Line2(':');
                   Lcd_Show_Line2(Time.Min);
                   Lcd_Show_Line2(':');
                   Lcd_Show_Line2(Time.Sec);
              }
      		} 
      		else if (Time.Min != pastminute)       //每分钟更新一次
      		{	 
              if (Time.Hour > 12)	
              {
                   Lcd_Show_Line2(Time.Hour-12);
                   Lcd_Show_Line2(':');
                   Lcd_Show_Line2(Time.Min);
                   Lcd_Show_Line2(':');
                   Lcd_Show_Line2(Time.Sec);
              }
              else			 
              {
                   Lcd_Show_Line2(Time.Hour);
                   Lcd_Show_Line2(':');
                   Lcd_Show_Line2(Time.Min);
                   Lcd_Show_Line2(':');
                   Lcd_Show_Line2(Time.Sec);
              }
      		}              
          pastminute =  Time.Min;
      		OldSW2 = NewSW2;
      } 
      
      //按键SW3按下时执行的功能
   		NewSW3  = SW3_GetVal();
   		if ( (NewSW3 != OldSW3) ) 
   		{
   		    if (  NewSW3 == 0 ) 
   		    {
       		    LED_PutVal(~LED_GetVal());
   		    }
       		OldSW3 = NewSW3;
   		}
   		
      //按键SW4按下时的处理程序
   		NewSW4 = SW4_GetVal();
   		counter = counter + 1;  
   		
   		if (NewSW4 == 0) 
   		{
   		  SW4toggle = ~SW4toggle & 1;
   		}
  	    if (  (NewSW4 != OldSW4) || (SW4toggle == TRUE) ) 
  	    {
   		    if (  counter >= 3000 ) 
   		    {
              	for (i=0; i <= 5; i++)  LEDarray[i] = FALSE;	 
                LEDarray[LEDcounter] = TRUE;  
                LED_PutBit(0, LEDarray[0])	;	
                LED_PutBit(1, LEDarray[1])	;
                LED_PutBit(2, LEDarray[2])	;
                LED_PutBit(3, LEDarray[3])	;
                LED_PutBit(4, LEDarray[4])	;
              	LEDcounter =  LEDcounter + 1;
              	if (LEDcounter >= 6) LEDcounter = 0;
                counter = 0;
   		    }
     		    
		    OldSW4 = NewSW4;  		
  	    }
  }
}
/* END rtc */
/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 3.03 [04.07]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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