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

📄 target.c

📁 M20xx-FNU20编程工程模板
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			target.c
** Last modified Date:	2004-09-17
** Last Version:		1.0
** Descriptions:		header file of the specific codes for LPC2200 target boards
**				Every project should include a copy of this file, user may modify it as needed
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2004-02-02
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			Chenmingji
** Modified date:		2004-09-17
** Version:				1.01
** Descriptions:		Renewed the template, added more compiler supports 
**
**------------------------------------------------------------------------------------------------------
** Modified by:         Ganda
** Modified date:       2005-06-15
** Version:			    1.02
** Descriptions:        Added code for copying vector
**
**------------------------------------------------------------------------------------------------------
** Modified by: 
** Modified date:
** Version:	
** Descriptions: 
**
********************************************************************************************************/

#define IN_TARGET
#include "config.h"
#include <stdlib.h>

#pragma import(__use_no_semihosting_swi)
#pragma import(__use_two_region_memory)

/*********************************************************************************************************
** Function name:			void UpsysTime(void)
**
** Descriptions:			Initialize the system time 
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				HuangQinNing
** Created Date:			2007/04/28
**-------------------------------------------------------------------------------------------------------
** Modified by:             
** Modified date:           
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void UpsysTime(void)
{
    uint8 Err;
    uint8 TimeBuff[10];
    uint8 IicAddr=0x02;
    uint8 i;

	I2cRead(0xA2, TimeBuff, &IicAddr, 1, 7);                             // 读取外部PCF8563时钟
	for(i=0; i<OS_TICKS_PER_SEC; i++)
	{
		Err = I2cGetFlag();
		if(Err==I2C_READ_END || Err==I2C_FINISH)
		{
		    break;
		}
		OSTimeDly(1); 
	}

	/* 内部RTC初始化 */
	CCR  = 0x00;                                                          // 关闭RTC
	PREINT  = Fpclk / 32768 -1;		                                      // 设置基准时钟分频器
	PREFRAC = Fpclk - (Fpclk / 32768) * 32768;
	

	SEC  = ((TimeBuff[0]&0x70)>>4)*10 + (TimeBuff[0]&0x0f);	              // 秒
	MIN  = ((TimeBuff[1]&0x70)>>4)*10 + (TimeBuff[1]&0x0f);	              // 分
	HOUR = ((TimeBuff[2]&0x30)>>4)*10 + (TimeBuff[2]&0x0f);	              // 小时
	
	DOW  = TimeBuff[4]&0x07;								              // 星期
	
	DOM  = ((TimeBuff[3]&0x30)>>4)*10 + (TimeBuff[3]&0x0f);	              // 日
	MONTH  = ((TimeBuff[5]&0x10)>>4)*10 + (TimeBuff[5]&0x0f);	          // 月
	
	if (TimeBuff[5]&0x80) 	                                              // 年为19XX
	{
		YEAR = ((TimeBuff[6]&0xf0)>>4)*10 + (TimeBuff[6]&0x0f) +1900;
	}
	else				                                                  // 年为20XX 
	{
		YEAR = ((TimeBuff[6]&0xf0)>>4)*10 + (TimeBuff[6]&0x0f) +2000;
	}

	CIIR = 0x01;				                                          // 设置秒值的增量产生一次中断
	ILR  = 0x03;                                                          // 清除RTC增量和报警中断标志
	CCR  = 0x01;		                                                  // 启动RTC
}


/*********************************************************************************************************
** Function name:			TargetInit
**
** Descriptions:			Initialize the target board before running the main() function; User may
**							change it as needed, but may not deleted it.
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:             Ganda
** Modified date:           2005/06/15
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void TargetInit(void)
{
    if (CheckVersion(CODE_VER, PRODUCTION_NAME) != TRUE)		// 版本验证:如果版本号和型号完全匹配,		返回TRUE;
    {															//			如果版本号和型号不匹配但兼容,	返回FALSE;
        /* 错误处理: ->  */										//			如果版本号和型号不兼容,			函数不返回,停止运行!!!
        // 点亮某个LED灯 或 ...
        while (1);
    }
    SysInit();    
    UpsysTime();                                                // 更新系统内部时钟
    
}

/*********************************************************************************************************/


/*********************************************************************************************************
**                  以下为一些与系统相关的库函数的实现
**                  具体作用请ads的参考编译器与库函数手册
**                  用户可以根据自己的要求修改        
********************************************************************************************************/
/*********************************************************************************************************
**                  The implementations for some library functions
**                  For more details, please refer to the ADS compiler handbook and The library 
**					function manual
**                  User could change it as needed       
********************************************************************************************************/

#include "rt_sys.h"
#include "stdio.h"

#pragma import(__use_no_semihosting_swi)
#pragma import(__use_two_region_memory)

#if 0
        int __rt_div0(int a)
{
    a = a;
    return 0;
}

        int fputc(int ch,FILE *f)
{
    ch = ch;
    f = f;
    return 0;
}

    int fgetc(FILE *f)
{
    f = f;
    return 0;
}


        int _sys_close(FILEHANDLE fh)
{
    fh = fh;
    return 0;
}

        int _sys_write(FILEHANDLE fh, const unsigned char * buf,
                      unsigned len, int mode)
{
    fh = fh;
    buf = buf;
    len =len;
    mode = mode;
    return 0;
}
        int _sys_read(FILEHANDLE fh, unsigned char * buf,
                     unsigned len, int mode)
{
    fh = fh;
    buf = buf;
    len =len;
    mode = mode;
    
    return 0;
}
#endif
       void _ttywrch(int ch)
{
    ch = ch;
}

#if 0
        int _sys_istty(FILEHANDLE fh)
{
    fh = fh;
    return 0;
}
        int _sys_seek(FILEHANDLE fh, long pos)
{
    fh = fh;
    pos = pos;
    return 0;
}
        int _sys_ensure(FILEHANDLE fh)
{
    fh = fh;
    return 0;
}

        long _sys_flen(FILEHANDLE fh)
{
    fh = fh;
    return 0;
}
       int _sys_tmpnam(char * name, int sig, unsigned maxlen)
{
    name = name;
    sig = sig;
    maxlen = maxlen;
    return 0;
}


        void _sys_exit(int returncode)
{
    returncode = returncode;
}

        char *_sys_command_string(char * cmd, int len)
{
    cmd = cmd;
    len = len;
    return 0;
}
#endif

/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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