LPC23XX开发讲解.ppt_第1页
LPC23XX开发讲解.ppt_第2页
LPC23XX开发讲解.ppt_第3页
LPC23XX开发讲解.ppt_第4页
LPC23XX开发讲解.ppt_第5页
已阅读5页,还剩42页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

LPC23XX开发讲解,朱明富,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,2,LPC23XX开发讲解,简介 Keil开发工具 程序模板 应用程序设计 接口程序设计 硬件设计,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,3,LPC23XX简介,ARM 7TDMI-S, 72MHz 512kB Flash, ISP, IAP 64kB RAM + 16kB Enet + 8kB USB + 2kB RTC USB, Ethernet, UART, CAN, I2C, I2S, SPI, SSP GPIO, 10 Bit AD/DA, PWM, 4 Timer, Watch DOG, RTC JTAG, PLL, On-Chip crystal oscillator,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,4,LPC23XX序列型号,LPC2361/62/64/65/66/67/68 LPC2377/78 (144Pin) LPC2387 LPC2388 (144Pin),2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,5,LPC23XX开发工具,Keil ARM ADS NXP ISP软件FlashMagic,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,6,LPC23XX开发板及应用板,开发板-展示功能 应用板-实际应用,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,7,LPC23XX应用,选型考虑 是否一定要选择OS uCosII,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,8,Keil安装,mdk305.exe rtlarm305.exe License Management,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,9,Keil 软件工程,新建Keil工程 从模板程序建立工程 修改LPCTest2.Uv2 修改LPCTest2.Opt,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,10,Keil 中源代码管理,选Project-Manage-Components, ,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,11,Keil 中所支持的设备管理,File-Device Database,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,12,Keil 中应用程序选项管理,点快捷按钮Options for Target,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,13,Keil中仿真器,Segger的RDI接口 ULink ULink实际上是并口(打印机口) ULink上用了一颗USB转并口的芯片 ULink只能设单个断点 ULink的驱动程序安装,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,14,Keil的调试,设置断点 单步运行 关闭WatchDog,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,15,LPC23XX程序模板,新建Keil工程 说明:startup.s是汇编程序,完成如下功能: 主晶振起振 PLL配置 中断向量设置 堆栈设置 跳转到C主程序,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,16,一个简单的程序,在前面创建的程序中没有C主程序 这个例子是一个模板 编程规则 把代码文件分类 把代码文件按通用性分目录存放,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,17,程序模板解析,Main.c 主程序 Startup.s 启动文件 Target.c 目标板初始化 Irq.c IRQ处理接口 Swi_handler.s 软件中断处理,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,18,startup.s,文件说明 宏定义 中断向量 复位中断处理 跳转到C主程序 加密处理 内存段分配,Mode_USR EQU 0x10 Mode_FIQ EQU 0x11 Mode_IRQ EQU 0x12 Mode_SVC EQU 0x13 Mode_ABT EQU 0x17 Mode_UND EQU 0x1B Mode_SYS EQU 0x1F I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled ;/ Stack Configuration (Stack Sizes in Bytes) ;/ Undefined Mode ;/ Supervisor Mode ;/ Abort Mode ;/ Fast Interrupt Mode ;/ Interrupt Mode ;/ User/System Mode ;/ UND_Stack_Size EQU 0x00000000 SVC_Stack_Size EQU 0x00000100 ABT_Stack_Size EQU 0x00000080 FIQ_Stack_Size EQU 0x00000080 IRQ_Stack_Size EQU 0x00000600 USR_Stack_Size EQU 0x00000800 ;/ 说明: 当程序还有更多的RAM时, 可再增加用户Stack的大小 Stack_Size EQU (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + FIQ_Stack_Size + IRQ_Stack_Size + USR_Stack_Size) AREA STACK, NOINIT, READWRITE, ALIGN=3 Stack_Mem SPACE Stack_Size Stack_Top EQU Stack_Mem + Stack_Size,;/ Heap Configuration ;/ Heap Size (in Bytes) ;/ Heap_Size EQU 0x00000000 AREA HEAP, NOINIT, READWRITE, ALIGN=3 Heap_Mem SPACE Heap_Size ; Area Definition and Entry Point ; Startup Code must be linked first at Address at which it expects to run. AREA RESET, CODE, READONLY ARM ; Exception Vectors ; Mapped to Address 0. ; Absolute addressing mode must be used. ; Dummy Handlers are implemented as infinite loops which can be modified. Vectors LDR PC, Reset_Addr LDR PC, Undef_Addr LDR PC, SWI_Addr LDR PC, PAbt_Addr LDR PC, DAbt_Addr NOP ; Reserved Vector ; LDR PC, IRQ_Addr LDR PC, PC, #-0x0120 ; Vector from VicVectAddr LDR PC, FIQ_Addr,;/* ;* startup.s: startup file for NXP LPC230x Family Microprocessors ;* ;* Copyright(C) 2006, NXP Semiconductor ;* All rights reserved. ;* ;* History ;* 2006.09.01 ver 1.00 Prelimnary version, first Release ;* ;*/ PRESERVE8 ;/* ; * The STARTUP.S code is executed after CPU Reset. This file may be ; * translated with the following SET symbols. In uVision these SET ; * symbols are entered under Options - ASM - Define. ; * ; * REMAP: when set the startup code initializes the register MEMMAP ; * which overwrites the settings of the CPU configuration pins. The ; * startup and interrupt vectors are remapped from: ; * 0x00000000 default setting (not remapped) ; * 0x40000000 when RAM_MODE is used ; * ; * RAM_MODE: when set the device is configured for code execution ; * from on-chip RAM starting at address 0x40000000. ; */ ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs,Reset_Addr DCD Reset_Handler Undef_Addr DCD Undef_Handler SWI_Addr DCD SWI_Handler PAbt_Addr DCD PAbt_Handler DAbt_Addr DCD DAbt_Handler DCD 0xB9206E28 ; Reserved Address IRQ_Addr DCD IRQ_Handler1 FIQ_Addr DCD FIQ_Handler Undef_Handler B Undef_Handler ;MOVS PC, R14 SWI_Handler B SWI_Handler PAbt_Handler B PAbt_Handler DAbt_Handler ;B DAbt_Handler SUBS PC, R14, #8 IRQ_Handler B IRQ_Handler FIQ_Handler B FIQ_Handler,; Reset Handler EXPORT Reset_Handler Reset_Handler ; Setup Stack for each mode LDR R0, =Stack_Top ; Enter Undefined Instruction Mode and set its Stack Pointer MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit MOV SP, R0 SUB R0, R0, #UND_Stack_Size ; Enter Abort Mode and set its Stack Pointer MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit MOV SP, R0 SUB R0, R0, #ABT_Stack_Size ; Enter FIQ Mode and set its Stack Pointer MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit MOV SP, R0 SUB R0, R0, #FIQ_Stack_Size ; Enter IRQ Mode and set its Stack Pointer MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit MOV SP, R0 SUB R0, R0, #IRQ_Stack_Size ; Enter Supervisor Mode and set its Stack Pointer MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit MOV SP, R0 SUB R0, R0, #SVC_Stack_Size ; Enter User Mode and set its Stack Pointer MSR CPSR_c, #Mode_USR MOV SP, R0 SUB SL, SP, #USR_Stack_Size,; Enter the C code IMPORT TargetResetInit BL TargetResetInit IMPORT _main LOADCMAINFUNCTION LDR R0, =_main BX R0 NOP SUB R0, R0, R0 BX R0 NOP ; LPC23xx非典FLASHROM的中断向量表架构 IMPORT VIC_Vect_Addr0 IRQ_Handler1 STMFD SP!, R11, R12, LR;真保护R11R12, 假保护LR(用于运算) ;/ LDR R12, VIC_Vect_Addr ;取VICVectAddr物理地址 ;/ LDR R12, R12 ;取出取VICVectAddr内实际向量中断号(非地址) LDR R12, PC , #-0x14c ;取出取VICVectAddr内实际向量中断号(非地址) AND R12, #0x1f ;防止32个中断序号越界, ;在此可再做序号越界处理(可省略) LDR R11, =VIC_Vect_Addr0 LDR R12, R11, R12, LSL #2;散转到用户真正的向量中断地址 STR R12, SP, #0x08 ;将中断向量地址R12写入事先保存的那个LR空间 LDMFD SP!, R11, R12, PC ;恢复R11R12,同时PC跳入中断向量地址执行,; Encryption FLASH IF :DEF:EN_CRP IF . = 0x1fc INFO 1,“nThe data at 0x000001fc this line.“ ENDIF CrpData WHILE . 0x1fc NOP WEND CrpData1 ; 如果要加密, 请使用此行, 注释下一行 ; DCD 0x87654321 DCD 0x00000000 ENDIF ; 说明: 这里保留至4kFlash边界, 以避免VIC中断代码处于前4k范围内 ; 从而使得某些时候不能正常运行 WHILE . 0x0ff8 NOP WEND ;- ; User Initial Stack & Heap AREA |.text|, CODE, READONLY IMPORT _use_two_region_memory EXPORT _user_initial_stackheap _user_initial_stackheap LDR R0, = Heap_Mem LDR R1, = (Stack_Mem + USR_Stack_Size) LDR R2, = (Heap_Mem + Heap_Size) LDR R3, = Stack_Mem BX LR END,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,19,target.c,文件说明 TargetInit函数 GPIOResetInit ConfigurePLL TargetResetInit,/* * target.c: Target C file for NXP LPC23xx/24xx Family Microprocessors * * Copyright(C) 2006, NXP Semiconductor * All rights reserved. * * History * 2006.07.13 ver 1.00 Prelimnary version, first Release * */ #include “LPC23xx.h“ #include “type.h“ #include “irq.h“ #include “target.h“,/* * Function name: TargetInit * * Descriptions: Initialize the target board; it is called in a necessary * place, change it as needed * * parameters: None * Returned value: None * */ void TargetInit(void) /* Add your codes here */ return; ,/* * Function name: GPIOResetInit * * Descriptions: Initialize the target board before running the main() * function; User may change it as needed, but may not * deleted it. * * parameters: None * Returned value: None * */ void GPIOResetInit( void ) /* Reset all GPIO pins to default: primary function */ PINSEL0 = 0x00000000; PINSEL1 = 0x00000000; PINSEL2 = 0x00000000; PINSEL3 = 0x00000000; PINSEL4 = 0x00000000; PINSEL5 = 0x00000000; PINSEL6 = 0x00000000; PINSEL7 = 0x00000000; PINSEL8 = 0x00000000; PINSEL9 = 0x00000000; PINSEL10 = 0x00000000;,IODIR0 = 0x00000000; IODIR1 = 0x00000000; IOSET0 = 0x00000000; IOSET1 = 0x00000000; FIO0DIR = 0x00000000; FIO1DIR = 0x00000000; FIO2DIR = 0x00000000; FIO3DIR = 0x00000000; FIO4DIR = 0x00000000; FIO0SET = 0x00000000; FIO1SET = 0x00000000; FIO2SET = 0x00000000; FIO3SET = 0x00000000; FIO4SET = 0x00000000; SCS |= 0x00000001; return; ,/* * Function name: ConfigurePLL * * Descriptions: Configure PLL switching to main OSC instead of IRC * at power up and wake up from power down. * This routine is used in TargetResetInit() and those * examples using power down and wake up such as * USB suspend to resume, ethernet WOL, and power management * example * parameters: None * Returned value:None * */ void ConfigurePLL ( void ) DWORD MValue, NValue; if ( PLLSTAT /* select main OSC, 12MHz, as the PLL clock source */,PLLCFG = PLL_MValue | (PLL_NValue 16; while (MValue != PLL_MValue) ,/* * Function name: TargetResetInit * * Descriptions: Initialize the target board before running the main() * function; User may change it as needed, but may not * deleted it. * * parameters: None * Returned value:None * */ void TargetResetInit(void) #ifdef _DEBUG_RAM MEMMAP = 0x2; /* remap to internal RAM */ #endif #ifdef _DEBUG_FLASH MEMMAP = 0x1; /* remap to internal flash */ #endif #if USE_USB PCONP |= 0x80000000; /* Turn On USB PCLK */ #endif /* Configure PLL, switch from IRC to Main OSC */ ConfigurePLL();,/* Set system timers for each component */ #if (Fpclk / (Fcclk / 4) = 1 PCLKSEL0 = 0x00000000; /* PCLK is 1/4 CCLK */ PCLKSEL1 = 0x00000000; #endif #if (Fpclk / (Fcclk / 4) = 2 PCLKSEL0 = 0xAAAAAAAA; /* PCLK is 1/2 CCLK */ PCLKSEL1 = 0xAAAAAAAA; #endif #if (Fpclk / (Fcclk / 4) = 4 PCLKSEL0 = 0x55555555; /* PCLK is the same as CCLK */ PCLKSEL1 = 0x55555555; #endif /* Set memory accelerater module*/ MAMCR = 0; #if Fcclk 20000000 MAMTIM = 1; #else #if Fcclk 40000000 MAMTIM = 2; #else MAMTIM = 3; #endif #endif MAMCR = 2; GPIOResetInit(); init_VIC(); return; ,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,20,irq.c,文件说明 spurious_handler init_VIC install_irq,/* * irq.c: Interrupt handler C file for NXP LPC230x Family Microprocessors * * Copyright(C) 2006, NXP Semiconductor * All rights reserved. * * History * 2006.07.13 ver 1.00 Prelimnary version, first Release * */ #include “LPC23xx.h“ /* LPC23XX Peripheral Registers */ #include “type.h“ #include “irq.h“,/* * Function name: spurious_handler * * Descriptions: spurious interrupt handler . * parameters: None * Returned value: None * */ DWORD VIC_Vect_Addr0; void spurious_handler() _irq ,/* Initialize the interrupt controller */ /* * Function name: init_VIC * * Descriptions: Initialize VIC interrupt controller. * parameters: None * Returned value: None * */ void init_VIC(void) DWORD i = 0; DWORD *vect_addr, *vect_cntl; /* initialize VIC*/ VICIntEnClr = 0xffffffff; VICVectAddr = 0; VICIntSelect = 0; VICDefVectAddr=(unsigned long)spurious_handler; /* set all the vector and vector control register to 0 */ for ( i = 0; i VIC_SIZE; i+ ) vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + i*4); vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + i*4); *vect_addr = (unsigned long)spurious_handler; /0x0; *vect_cntl = 0xF; return; ,/* * Function name: install_irq * * Descriptions: Install interrupt handler * parameters: Interrupt number, interrupt handler address, * interrupt priority * Returned value:true or false, return false if IntNum is out of range * */ DWORD install_irq( DWORD IntNumber, void *HandlerAddr, DWORD Priority ) DWORD *vect_addr; DWORD *vect_cntl; VICIntEnClr = 1 = VIC_SIZE ) return ( FALSE ); else /* find first un-assigned VIC address for the handler */ vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + IntNumber*4); vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + IntNumber*4); *vect_addr = (DWORD)HandlerAddr; /* set interrupt vector */ *vect_cntl = Priority; VICIntEnable = 1 IntNumber; /* Enable Interrupt */ return( TRUE ); /* * End Of File */,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,21,swi_handler.s,文件说明及宏定义 SoftwareInterrupt IntEnable IntDisable,;/* ;* swi_handler.s: SWI handler file for NXP LPC230x Family Microprocessors ;* ;* Copyright(C) 2006, NXP Semiconductor ;* All rights reserved. ;* ;* History ;* 2006.09.01 ver 1.00 Prelimnary version, first Release ;* ;*/ PRESERVE8 SWI_IRQ_DIS EQU 0 SWI_IRQ_EN EQU 1 SWI_FIQ_DIS EQU 2 SWI_FIQ_EN EQU 3 I_Bit EQU 0x80 F_Bit EQU 0x40 ;The exported labels and functions EXPORT SoftwareInterrupt EXPORT IntEnable EXPORT IntDisable CODE32 AREA SWI_HANDLER,CODE,READONLY ENTRY,;* ;* SWI interrupt handler ;* Function : SoftwareInterrupt(SWI_Number) ;* The SWI_Number is 0 through 3 ;* See below “SwiFunction“ table below ;* Parameters: None ;* input : SWI_Number ;* output : None ;* SoftwareInterrupt CMP R0, #4 LDRLO PC, PC, R0, LSL #2 MOVS PC, LR SwiFunction DCD IRQDisable ;0 DCD IRQEnable ;1 DCD FIQDisable ;2 DCD FIQEnable ;3 IRQDisable MRS R0, SPSR ORR R0, R0, #I_Bit MSR SPSR_c, R0 MOVS PC, LR IRQEnable MRS R0, SPSR BIC R0, R0, #I_Bit MSR SPSR_c, R0 MOVS PC, LR FIQDisable MRS R0, SPSR ORR R0, R0, #F_Bit MSR SPSR_c, R0 MOVS PC, LR FIQEnable MRS R0, SPSR BIC R0, R0, #F_Bit MSR SPSR_c, R0 MOVS PC, LR,;* ;* Call SWI to enable IRQ * ;* Function : void IntEnable(void) * ;* Parameters: None * ;* input : None * ;* output : None * ;* IntEnable SWI SWI_IRQ_EN BX lr ; end of IntEnable ;* ;* Call SWI to disable IRQ * ;* Function : void IntDisable(void) * ;* Parameters : None * ;* input : None * ;* output : None * ;* IntDisable SWI SWI_IRQ_DIS BX lr ; end of IntDisable END ;/* ;* End Of File ;*/,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,22,应用程序设计,基于硬件的程序设计准则 LPC23XX程序主要流程,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,23,基于硬件的程序设计准则,软件与硬件分离 功能独立 功能分层 分时处理与实时处理 充分利用C语言的宏定义,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,24,LPC23XX程序主要流程,对于通用I/O端口 使用PINSELx定义端口作为通用I/O功能, 每个引脚可能有4个功能, 因此需要用2位来确定其功能 设置SCS寄存器第0位为1, 使其作为快速I/O端口 使用PINMODEx定义端口的模式, 分为上拉, 下拉, 浮空, 因此需要用2位来确定其模式 使用FIOxDIR来确定端口方向 使用FIOxMASK与FIOxCLR, FIOxSET, FIOxPIN联合来设置端口的值,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,25,LPC23XX程序主要流程,使用通用I/O端口模拟数据总线 由于通用I/O一般情况下方向是确定的, 通常或者为输入,或者为输出, 要模拟数据总线, 必须在需要的时候, 随时改变端口的方向, 可使用FIOxDIR寄存器完成此项工作。 实例:LCD控制 外部中断 除EXTINT0-EXTINT3外,端口0和端口2均可以作为外部中断源,它们共用EXTINT3这个外部中断。,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,26,LPC23XX程序主要流程,上拉与下拉 根据实际情况合理选用。主要对上电时的初始值。上拉或下拉都是弱的,有时也用外部分电阻上/下拉。 对于输入,上拉表示通用端口所连接的外部信号不存在时, 端口值为1, 下拉为0。 对于输出,如果没有更改时,上拉输出为高(1), 下拉输出为低(0)。 FIOxPIN总是可以读出端口的状态。 FIOxPIN对非通用I/O端口也可读出其状态。,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,27,LPC23XX程序主要流程,对于内置(片上)外设, 如UART, CAN, SPI等: 使用PINSELx定义端口作为特定外设。 通常情况作为外设的引脚的方向是确定的,如果可能,还会自动改变方向。 大多情况下,无须设置上拉或下拉模。 设置外设的参数 如果需要的话,安装中断服务程序 外设上电(有些外设默认是上电的,有些不是) 启动外设,2019/6/30,LPC23XX开发讲解 华中科技大学控制科技与工程系 朱明富,28,LPC23XX程序主要流程,对于内置(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论