?? 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 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: Chenmingji
** Modified date: 2004-09-17
** Version: 1.01
** Descriptions: Renewed the template, added more compiler supports
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#define IN_TARGET
#include "config.h"
/*********************************************************************************************************
** Function name: IRQ_Exception
**
** Descriptions: interrupt exceptional handler , change it as needed
**
** input parameters: None
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Chenmingji
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void __irq IRQ_Exception(void)
{
while(1); // change it to your code 這一句替換為自己的代碼
}
/*********************************************************************************************************
** Function name: FIQ_Exception
**
** Descriptions: Fast interrupt exceptional handler , change it as needed
**
** input parameters: None
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Chenmingji
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void FIQ_Exception(void)
{
while(1); // change it to your code 這一句替換為自己的代碼
}
/*********************************************************************************************************
** Function name: TargetInit
**
** Descriptions: Initialize the target board; it is called in a necessary place, change it as
** needed
**
** input parameters: None
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Chenmingji
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void TargetInit(void)
{
/* 添加自己的代碼 */
/* Add your codes here */
}
/*********************************************************************************************************
** Function name: TargetResetInit
**
** 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:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void TargetResetInit(void)
{
#ifdef __DEBUG_RAM
MEMMAP = 0x2; //remap
#endif
#ifdef __DEBUG_FLASH
MEMMAP = 0x1; //remap
#endif
#ifdef __IN_CHIP
MEMMAP = 0x1; //remap
#endif
/* 設置系統各部分時鐘 */
/* Set system timers for each component */
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;
/* 設置存儲器加速模塊 */
/* Set memory accelerater module*/
MAMCR = 0;
#if Fcclk < 20000000
MAMTIM = 1;
#else
#if Fcclk < 40000000
MAMTIM = 2;
#else
MAMTIM = 3;
#endif
#endif
MAMCR = 2;
/* 初始化VIC */
/* initialize VIC*/
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;
VICIntSelect = 0;
/* 添加自己的代碼 */
/* Add your codes here */
}
#define UART_BPS 115200 // 串口通訊波特率
/*
*********************************************************************************************************
** 函數名稱 :UART0_Init()
** 函數功能 :串口初始化,設置為8位數據位,1位停止位,無奇偶校驗,波特率115200。
** 入口參數 :無
** 出口參數 :無
*********************************************************************************************************
*/
void UART0_Init (void)
{
uint16 Fdiv;
PINSEL0 = (PINSEL0 & (~0x0F)) | 0x05; // 設置I/O連接到UART0
U0LCR = 0x83; // DLAB=1,允許設置波特率
Fdiv = (Fpclk / 16) / UART_BPS; // 設置波特率
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03;
}
/*
*********************************************************************************************************
** 函數名稱 :UART0_SendByte()
** 函數功能 :向串口發送字節數據,并等待發送完畢,查詢方式。
** 入口參數 :dat 要發送的數據
** 出口參數 :無
*********************************************************************************************************
*/
void UART0_SendByte (uint8 dat)
{
U0THR = dat;
while ((U0LSR & 0x40) == 0); // 等待數據發送完畢
}
/*
*********************************************************************************************************
** 函數名稱 :UART0_SendStr()
** 函數功能 :向串口發送一字符串
** 入口參數 :str 要發送的字符串的指針
** 出口參數 :無
*********************************************************************************************************
*/
void UART0_SendStr (char *str)
{
while (1)
{
if (*str == '\0') break; // 遇到結束符,退出
UART0_SendByte(*str++); // 發送數據
}
}
/*
*******************************************************************************************************
** 函數名稱 :PC_DispChar_LED()
** 函數功能 :向PC機LED窗口發送顯示字符。
** 入口參數 :x 顯示位置0~8,其中8為LED燈
** data 顯示的筆畫,其中1為點亮,0為熄滅
** 出口參數 :無
*******************************************************************************************************
*/
void PC_Disp_LED(uint8 x, uint8 data)
{
UART0_SendByte(0xff);
UART0_SendByte(0x80);
UART0_SendByte(x);
UART0_SendByte(data);
UART0_SendByte(0x00);
}
/*
*******************************************************************************************************
** 函數名稱 :PC_DispChar()
** 函數功能 :向PC機DOS窗口發送顯示字符。
** 入口參數 :x 顯示縱坐標
** y 顯示橫坐標
** chr 顯示的字符,不能為ff
** color 顯示的顏色
** 出口參數 :無
*******************************************************************************************************
*/
void PC_Disp_DOS(uint8 x, uint8 y,uint8 chr, uint8 color)
{
UART0_SendByte(0xff);
UART0_SendByte(x);
UART0_SendByte(y);
UART0_SendByte(chr);
UART0_SendByte(color);
}
/*
*******************************************************************************************************
** 函數名稱 :PC_DispChar_TIME()
** 函數功能 :向PC機TIME窗口發送顯示字符。
** 入口參數 :x 顯示位置0~14,分別對應于年,月,日,星期,時,分,秒
** data 顯示的筆畫,其中1為點亮,0為熄滅
** 出口參數 :無
*******************************************************************************************************
*/
void PC_Disp_TIME(uint8 x, uint8 data)
{
UART0_SendByte(0xff);
UART0_SendByte(0x81);
UART0_SendByte(x);
UART0_SendByte(data);
UART0_SendByte(0x00);
}
void PLL_Init (void)
{
PLLCON = 1; // 使能PLL
PLLCFG = 0x23; // 設置M為4,P為2,和掉電前一樣
PLLFEED = 0xaa; // 發送PLL饋送序列
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0); // 等待PLL鎖定
PLLCON = 3; // PLL使能和連接
PLLFEED = 0xaa; // 發送PLL饋送序列
PLLFEED = 0x55;
}
/*********************************************************************************************************
** 以下為一些與系統相關的庫函數的實現
** 具體作用請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)
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 Of File
********************************************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -