?? target.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 + -