📄 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:
** 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_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: Timer0_Exception
**
** Descriptions: Timer0 interrupt service function
**
** 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 Timer0_Exception(void)
{
OS_ENTER_CRITICAL();
VICIntEnClr = 1 << 4;
VICVectAddr = 0; // 通知中断控制器中断结束
T0IR = 0x01;
OSTimeTick();
VICIntEnable = 1 << 4;
OS_EXIT_CRITICAL();
}
/*********************************************************************************************************
** Function name: Timer0Init
**
** Descriptions: Initialize the Time0
**
** 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 Timer0Init(void)
{
T0IR = 0xffffffff;
T0TC = 0;
T0TCR = 0x01;
T0MCR = 0x03;
T0MR0 = (Fpclk / OS_TICKS_PER_SEC);
}
/*********************************************************************************************************
** Function name: VICInit
**
** Descriptions: Initialize the Interrupt Vevtor Controller
**
** 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 initVic(void)
{
extern void IRQ_Handler(void);
extern void Timer0_Handler(void);
extern void Uart0_Handler(void);
extern void ExternalINT1_Handler(void);
extern void IIC_Handler(void);
extern void SPI_Handler(void);
VICIntEnClr = 0xffffffff;
VICDefVectAddr = (uint32)IRQ_Handler;
VICIntSelect = 0x00000000; // 设置所有通道为IRQ中断
VICVectCntl0 = 0x24; // UART0中断通道分配到IRQ slot 0,即优先级最高
VICVectAddr0=(uint32)Timer0_Handler;
VICVectCntl1=0x26;
VICVectAddr1 = (uint32)Uart0_Handler; // 设置UART0向量地址
VICVectCntl2=0x29;
VICVectAddr2=(uint32)IIC_Handler; //设置IIC向量地址
VICVectCntl3=0x2F; //外部中断1向量
VICVectAddr3=(uint32)ExternalINT1_Handler;
VICVectCntl4=0X20|10;
VICVectAddr4=(uint32)SPI_Handler;
VICIntEnable=(1<<INTINDEXTIMER0)|(1<<INTINDEXUART0)|(1<<INTINDEXINT1)|(1<<INTINDEXIIC)|(1<<INTINDEXSPI0);
//VICIntEnable=(1<<INTINDEXTIMER0)|(1<<INTINDEXUART0)|(1<<INTINDEXIIC);
VICVectAddr = 0x00;
}
void initP0(void)
{
/***
功能分配
P00 P01 P02 P03 P04 P05 P06 P07 P08
TXD0 RXD0 SCL SDA SPICLK SPIMISO SPIMOSI BEEPCON SPICS
P04 P06 P08 用作普通IO模void hc595SendData(uint8 toSend)拟SPI时序操作 控制HC595
***/
/***
PINSEL0 1819
位 76 54 32 10 1 0
值 01 01 01 01
SDA SCL RXD0 TXD0 PWM6
***/
/***首先将P0端口至于GPIO模式***/
PINSEL0=0X00000000;
PINSEL1=0X00000000;
/******/
/***确定管教的分配***/
PINSEL0=(PINSEL0&0xFFFFFF00)|0x55|(0X00080000); // 设置串口0、I2C控制口有效\pwm6
PINSEL0|=0X20000000;//P014连接外部中断1
PINSEL1=0x01400000;// 设置P0.27、P0.28连接到AIN0、AIN1
//确定方向控制,如果是功能管脚则方向自动,所以只针对GPIO
IO0DIR|=(1<<BEEPCON)|(1<<SPICLK) |(1<<SPIMOSI) |(1<<SPICS);
IO0DIR|=(1<<BEEPCON);
IO0SET=1<<BEEPCON|1<<7;//停止蜂鸣器
}
/*********************************************************************************************************
** 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)
{
UARTMODE mode;
EXTERNALINTERRUPTCONFIG cfg;
OS_ENTER_CRITICAL();
Timer0Init();
cfg.mode=0x02;
cfg.polar=0x00;
cfg.wakeup=0x00;
initExternalInterrupt(cfg);
mode.datab = 8; /***8位数据位***/
mode.stopb = 1; /***1位停止位***/
mode.parity = 0; /***无奇偶校验***/
initVic();
initP0();
initUart0(19200,mode);
initIic(32000);
initSpi(0x80);
U0FCR = 0x81; /***使能FIFO,并设置触发点为8字节***/
//U0IER = 0x01; /***允许RBR中断,即接收中断***/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -