main.c

来自「arm芯片LPC2214下的实时时钟DS1302的源程序」· C语言 代码 · 共 94 行

C
94
字号
/****************************************Copyright (c)************************************************
**
**                              	  深圳托普林科技有限公司
**                                 http://www.sztopping.com
**
**----------------------------------------------------------------------------------------------------
名称:main.c
功能:实时时钟测试
作者:Albert
日期:2004-11-17
说明:
*****************************************************************************************************/ 

#include  "config.h"
#include  "RTC.h"

#define  BEEPCON	0x00040000		//P1.18	OUT
#define  RUN_LED	0x00080000		//P1.19	OUT


#define  BEEPCON_ON  IO1CLR = BEEPCON
#define  BEEPCON_OFF IO1SET = BEEPCON
#define  RUN_LED_ON  IO1CLR = RUN_LED
#define  RUN_LED_OFF IO1SET = RUN_LED


void delay_us(unsigned short int us)
{
	unsigned short int i,j;
	for (i=0;i<us;i++)
	{
		for (j=0;j<100;j++) ;
	}
}

void delay_ms(unsigned short int ms)
{
	unsigned short int i,j;
	for (i=0;i<ms;i++)
	{
		for (j=0;j<10000;j++) ;
	}
}



void InitDateTime(DateTimeType *DateTime)
{
	DateTime->year   = 0x04;
	DateTime->month  = 0x12;
	DateTime->week   = 0x04;
	DateTime->day    = 0x23;
	DateTime->hour   = 0x01;
	DateTime->minute = 0x40;
	DateTime->second = 0x10;
}


void InitBios(void)
{
	IO1DIR  =  0x01EC0000;	
	IO1SET  =  0x01AC0000;	
	IO2DIR  =  0x03EE0000;	
	IO2SET  =  0x03EE0000;
}	


//主函数
int main(void)
{
	DateTimeType *DateTime;
	uint8 second;
	
	InitBios();
	Init_RTC();
	InitDateTime(DateTime);
	
	RTC_SetClock(DateTime);
	
	while(1)
	{
		second = DateTime->second;
		RTC_GetClock(DateTime);
		if(DateTime->second != second)
		{
			if((IO1SET & RUN_LED) == 0)
				IO1SET = RUN_LED;
			else
				IO1CLR = RUN_LED;
		}
	}
	
	return(0);
}

⌨️ 快捷键说明

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