1、将寄存器定义到ARM_LPC2000,并用 INCLUDE ARM_LPC2000.INC 包含到主程序文件开头,注意INCLUDE要顶格。
2、设置Targets Settings中Post-linker要选择 ARM fromELF,并在 ARM fromELF设置中使用二进制 plain binary.
3、设置Targets Settings中ARM Linker的Output页的Linktype为simple,并设 RO Base = 0x0, RW Base = 0x40000000
4、建立工程时要不要选择周立功的向导,直接用最上面第一项
以下是代码:
INCLUDE ARM_LPC2000.INC
GBLL TargetDowload
GBLL DebugTesting
; GBLL SecurePretect
GBLL PhaseLockLoop
;;===========================================================================================
u0_baud EQU 115200 ; 115200 = 0x1C200; 11059200 = 0xA8C000;
Fosc EQU 11059200 ; Crystal frequence:11059200/27648000/55296000。
Fcclk EQU (Fosc * 4 ) ; 系统频率,必须为Fosc的整数倍(1~32),且<=60MHZ。
Fcco EQU (Fcclk * 4) ; CCO频率,必须为Fcclk的2、4、8、16倍,范围为156MHz~320MHz。
Fpclk EQU (Fcclk / 4) * 1 ; VPB时钟频率,只能为(Fcclk / 4)的1、2、4倍。
; ===========================================================================================
SVC_STACK_LEGTH EQU 0
FIQ_STACK_LEGTH EQU 0
IRQ_STACK_LEGTH EQU 256
ABT_STACK_LEGTH EQU 0
UND_STACK_LEGTH EQU 0
; ===========================================================================================
; 程序部分:初始化及中断向量
;
; ===========================================================================================
AREA Initialize,CODE,READONLY ; AREA 段名(独立) CODE|DATA| 属性
ENTRY
CODE32 ; CODE32: 以下为 ARM 指令;CODE16: 以下为 THUMB 指令
; ===========================================================================================
Reset
LDR PC, Reset_Address ;; 0x00-复位异常向量
LDR PC, Undefine_Address ;; 0x04-未定义指令异常
LDR PC, SWI_Address ;; 0x08-SWI 异常
LDR PC, PrefetchAbort_Address ;; 0x0C-指令预取中止异常
LDR PC, DataAbort_Address ;; 0x10-数据预取中止异常
DCD 0xb9205f88 ;; 为使向量表所有32位数据累加和为零而补数,LPC2000系列仅校验0x00~0x1F
LDR PC, [PC,#-0x0FF0] ;; 0x18-IRQ 异常 PC执行完本指令后指向0x20,此时PC-#0xFF0=0xFFFFF030,正是VICVectAddr地址
LDR PC, FIQ_Address ;; 0x1C-FIQ 异常
Reset_Address DCD Reset_Initialize ;; 返回:BL => MOV PC,LR
Undefine_Address DCD Undefine_Handler ;; 返回:MOVS PC,R14_und
SWI_Address DCD SWI_Handler ;; 返回:MOVS PC,R14_svc
PrefetchAbort_Address DCD PrefetchAbort_Handler ;; 返回:SUBS PC,R14_abt,#04
DataAbort_Address DCD DataAbort_Handler ;; 返回:SUBS PC,R14_abt,#08
FIQ_Address DCD FIQ_Handler ;; 返回:SUBS PC,R14_fiq,#04
; ===========================================================================================
Undefine_Handler B .
SWI_Handler B SWI_Exception
PrefetchAbort_Handler B .
DataAbort_Handler B .
FIQ_Handler
STMFA SP!, {R0-R3, LR}
BL FIQ_Exception
LDMFA SP!, {R0-R3, LR}
SUBS PC, LR, #4
;;*******************************************************************************************
;;=============== SWI 调用 ===============
; MOV R0,#0x12
; MOV R1,#0x31 ;; 调用0x12(R0)号软中断的0x31(R1)号子功能。
; SWI 0 ;; 相当于 mov r0,#0x31; swi #0x12
SWI_Exception ;; SWI: CPU Mode exchanging!
MOV PC,LR
FIQ_Exception ;; FIQ: Winthin 27 clock!
MOV PC,LR
; ===========================================================================================
; InitStack & InitTarget
; ===========================================================================================
InitStack
MOV R0,LR
MSR CPSR_c,#0x000000D3
LDR R1,=SvcStackSpace
MOV SP,R1
MSR CPSR_c,#0x000000D2
LDR R1,=IrqStackSpace
MOV SP,R1
MSR CPSR_c,#0x000000D1
LDR R1,=FiqStackSpace
MOV SP,R1
MSR CPSR_c,#0x000000D7
LDR R1,=AbtStackSpace
MOV SP,R1
MSR CPSR_c,#0x000000Db
LDR R1,=UndtStackSpace
MOV SP,R1
MSR CPSR_c,#0x0000005F ;#0x000000DF修改,打开中断
LDR SP,=StackUSR
MOV PC,R0
InitTarget
ldr r0,=0xe01fc000
;; /* Set Up ReMap */
mov r1,#1 ;;1->#0xe01fc040: image to Flash,Boot loader; ;;0x02: image to RAM,User program
str r1,[r0,#0x40]
if :def: PhaseLockLoop ;;/////////////
;; /* Set system timers for each component */
mov r1,#1 ;; 1-enable
strb r1,[r0,#0x80] ;; Step1:Enable PLL by PLLCON(0xe01fc080)
if (Fpclk/(Fcclk/4)) = 1 ;; Step2:Setup reg_VPBDIV
mov r2,#0
strb r2,[r0,#0x100]
endif
if (Fpclk/(Fcclk/4)) = 2
mov r2,#2
strb r2,[r0,#0x100]
endif
if (Fpclk/(Fcclk/4)) = 4
mov r2,#1 ;; MEMVALB VPBDIV,0x00010001
strb r2,[r0,#0x100] ;; Fcclk/Fpclk 比值: =1:00,=2:10,=4:01; b7~4=b3~0
endif
if (Fcco/Fcclk) = 2 ;; Step3:Setup reg_PLLCFG
MEMVALB PLLCFG,((Fcclk/Fosc) - 1)|(0<<5)
endif
if (Fcco/Fcclk) = 4
mov r1,#0x23 ;; MEMVALB PLLCFG,((Fcclk/Fosc) - 1)|(1<<5)
strb r1,[r0,#0x84]
endif
if (Fcco/Fcclk) = 8
MEMVALB PLLCFG,((Fcclk/Fosc) - 1)|(2<<5)
endif
if (Fcco/Fcclk) = 16
MEMVALB PLLCFG,((Fcclk/Fosc) - 1)|(3<<5)
endif
mov r3,#0xaa
strb r3,[r0,#0x8c] ;; PLLFEED = 0xAA;
mov r12,#0x55 ;; PLLFEED = 0x55;
strb r12,[r0,#0x8c]
ldrh r1,[r0,#0x88] ;;PLLSTAT
tst r1,#0x400 ;; Test PLLSTAT_bit10 = 1?
beq {PC} - 12 ;; Step5:waiting until LOCK signal.
mov r1,#3 ;;PLLCON 3-connect
strb r1,[r0,#0x80] ;; Step6:Connect PLL
strb r3,[r0,#0x8c]
strb r12,[r0,#0x8c] ;; Step7:Feedback 0xaa,0x55 once more to avalid setting!
endif ;;/////////////
if :def: TargetDowload ;;////####
;; /* Set memory accelerater module*/
MEMVALB MAMCR,0x0000 ;; Step1:disable MAM.
if Fcclk < 20000000
MEMVALB MAMTIM,0x0001
else
if Fcclk < 40000000
MEMVALB MAMTIM,0x0002
else
MEMVALB MAMTIM,0x0003
endif
endif
MEMVALB MAMCR,0x0000 ;; Step2: enable MAM.
;----------- Set Up VIC:
mvn r0,#0 ;; r0 = 0xffffffff
mov r2,#0
str r0,[r2,#-0xfec] ;;VICIntEnClr = 0xffffffff
str r2,[r2,#-0xfd0] ;;VICVectAddr = 0x0
str r2,[r2,#-0xff4] ;;VICIntSelect= 0x0
endif ;;////####
mov pc,lr
; ===========================================================================================
Reset_Initialize
BL InitStack
BL InitTarget
B InitSystem
; ===========================================================================================
__user_initial_stackheap
LDR r0,=bottom_of_heap
; LDR r1,=StackUSR
MOV pc,lr
; ===========================================================================================
if :def: SecurePretect
if :def: EN_CRP ;; 芯片加密:向地址0x1FC处写0x87654321 便实现了ARM7加密,只能ISP擦除。
if . >= 0x1FC
INFO 1,"\nThe data at 0x000001fc must be 0x87654321."
endif
CrpData
while . < 0x1FC
NOP
wend
CrpData1 ;; 对于LPC2100系列ARM7核:
DCD 0x87654331 ;; When the Data is 0x87654321 on address_0x1FC,user code be protected.
endif
endif
; ===========================================================================================
; 设置 ARM Linker 类型:Simple image 的 RO Base: 0x00000000; RW Base: 0x40000300。
; 或 Command Line:-info totals -entry 0x00000000 -ro-base 0x00000000 -rw-base 0x40000300
AREA MyStacks, DATA, NOINIT, ALIGN=2 ;ALIGN=2 表示代码是04字节对齐的。
SvcStackSpace % SVC_STACK_LEGTH * 4 ;Stack spaces for Administration Mode 管理模式堆栈空间
IrqStackSpace % IRQ_STACK_LEGTH * 4 ;Stack spaces for Interrupt ReQuest Mode 中断模式堆栈空间
FiqStackSpace % FIQ_STACK_LEGTH * 4 ;Stack spaces for Fast Interrupt reQuest Mode 快速中断模式堆栈空间
AbtStackSpace % ABT_STACK_LEGTH * 4 ;Stack spaces for Suspend Mode 中止义模式堆栈空间
UndtStackSpace % UND_STACK_LEGTH * 4 ;Stack spaces for Undefined Mode 未定义模式堆栈
AREA Variable, DATA
BufferTxd SPACE 100 ;
BufferRxd SPACE 100 ;
BufferCurTime SPACE 16 ;
BufferI2CSlaveAddress % 1 ;包含 bit=0/1 读写信息
BufferI2CNumber % 1 ;
BufferI2CData % 0x100 ;
AREA Heap, DATA, NOINIT
bottom_of_heap SPACE 1
AREA Stacks, DATA, NOINIT
StackUSR SPACE 100
;;===========================================================================================
AREA MainProgram,CODE,READONLY
CODE32 ; CODE32: 以下为 ARM 指令;CODE16: 以下为 THUMB 指令
;;===========================================================================================
;; 从这里开始写你自己的程序
本人450元买的EasyARM2131开发板子,现在300元低价格转让,并可以适当指导,需要者和我联系:13044125591,艾和荣。