📄 target.c
字号:
/***********************************************Copyright (c)*********************************************
** Guangzou ZLG-MCU Development Co.,LTD.
**
** http://www.zlgmcu.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name: target.c
** Last modified Date: 2007-09-20
** Last Version: 1.0
** Descriptions: header file of the specific codes for LPC2100 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: LiXiaoCheng
** Modified Date: 2007-09-25
** Version: 1.1
** Descriptions: 增加了中断寄存器保护功能,用户操作VIC必须通过库函数来操作
**
**--------------------------------------------------------------------------------------------------------
** Modified by: LiXiaoCheng
** Modified Date: 2007-09-27
** Version: 1.2
** Descriptions: 增加了管脚链接设置功能
**
*********************************************************************************************************/
#include "config.h"
/*********************************************************************************************************
** Function name: FIQ_Exception
** Descriptions: 快速中断服务函数,用户设置好快中后,在该函数中添加用户代码就可.
** Input parameters: NONE
** Output parameters: NONE
** Returned value: NONE
*********************************************************************************************************/
void FIQ_Exception (void)
{
/* 添加用户代码 */
}
/*********************************************************************************************************
** Function name: TargetResetInit
** Descriptions: 目标板初始化.
** Input parameters: NONE
** Output parameters: NONE
** Returned value: NONE
*********************************************************************************************************/
void TargetResetInit (void)
{
#ifdef __DEBUG_RAM
MEMMAP = 0x02; /* remap */
#endif
#ifdef __IN_CHIP
MEMMAP = 0x1; /* remap */
#endif
/*
* 设置系统各部分时钟
*/
PLLCON = 1;
#if (Fpclk / (Fcclk / 4)) == 1
VPBDIV = 0;
#endif
#if (Fpclk / (Fcclk / 4)) == 2
VPBDIV = 2;
#endif
#if (Fpclk / (Fcclk / 4)) == 4
VPBDIV = 1;
#endif
#if (Fcco / Fcclk) == 2
PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
#endif
#if (Fcco / Fcclk) == 4
PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
#endif
#if (Fcco / Fcclk) == 8
PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
#endif
#if (Fcco / Fcclk) == 16
PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
#endif
PLLFEED = 0xaa;
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0);
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
/*
* 设置存储器加速模块
*/
MAMCR = 0;
#if Fcclk < 20000000
MAMTIM = 1;
#else
#if Fcclk < 40000000
MAMTIM = 2;
#else
MAMTIM = 3;
#endif
#endif
MAMCR = 2;
/*
* 初始化VIC
*/
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;
VICIntSelect = 0;
VICProtection = 0x01; /* 禁止修改中断向量寄存器 */
/*
* 初始化P0管脚连接
*/
PINSEL0 = (P0_15_FNUC <<30)|(P0_14_FNUC <<28)|(P0_13_FNUC <<26)|(P0_12_FNUC <<24)|(P0_11_FNUC <<22)|
(P0_10_FNUC <<20)|(P0_09_FNUC <<18)|(P0_08_FNUC <<16)|(P0_07_FNUC <<14)|(P0_06_FNUC <<12)|
(P0_05_FNUC <<10)|(P0_04_FNUC << 8)|(P0_03_FNUC << 6)|(P0_02_FNUC << 4)|(P0_01_FNUC << 2)| P0_00_FNUC;
/* P0.00 -- P0.15 */
PINSEL1 = (P0_31_FNUC <<30)|(P0_30_FNUC <<28)|(P0_29_FNUC <<26)|(P0_28_FNUC <<24)|(P0_27_FNUC <<22)|
(P0_26_FNUC <<20)|(P0_25_FNUC <<18)|(P0_24_FNUC <<16)|(P0_23_FNUC <<14)|(P0_22_FNUC <<12)|
(P0_21_FNUC <<10)|(P0_20_FNUC << 8)|(P0_19_FNUC << 6)|(P0_18_FNUC << 4)|(P0_17_FNUC << 2)| P0_16_FNUC;
/* P0.16 -- P0.31 */
/* 添加自己的代码 */
}
/*********************************************************************************************************
以下为一些与系统相关的库函数的实现
具体作用请参考ads的编译器与库函数手册
用户可以根据自己的要求修改
*********************************************************************************************************/
/* #ifdef __TTY_SEMI */
#include <rt_sys.h>
#include <stdio.h>
#pragma import(__use_no_semihosting_swi)
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;
}
void _ttywrch(int ch)
{
ch = ch;
}
int _sys_istty(FILEHANDLE fh)
{
fh = fh;
return 0;
}
int _sys_seek(FILEHANDLE fh, long pos)
{
fh = fh;
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;
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -