ARM笔记:汇编和C语言程序详解1
扫描二维码
随时随地手机看文章
本文纯属原创,为arm子程序模块,包含了汇编和C语言两种写法,后续将陆续完善。
ON1、关闭WATCHDOG,否则CPU会不断重启:
汇编:
disable_watch_dog:
@往WATCHDOG寄存器写0
mov r1,#0x53000000
mov r2,#0x0
str r2,[r1]
mov pc,lr //返回
C语言:
#define WTCON (*(volatile unsigned long *)0x53000000)
void disable_watch_dog(void)
{
WTCON=0;
}
ON2、存储控制器的使用
汇编:
.equ MEM_CTL_BASE,0x48000000
memsetup:
@ 设置存储控制器以便使用SDRAM等外设
mov r1,#MEM_CTL_BASE@ 存储控制器的13个寄存器的开始地址
adrlr2, mem_cfg_val@ 这13个值的起始存储地址
add r3,r1, #52@ 13*4 = 54
1:
ldr r4,[r2], #4@ 读取设置值,并让r2加4
str r4,[r1], #4@ 将此值写入寄存器,并让r1加4
cmp r1,r3@ 判断是否设置完所有13个寄存器
bne 1b@ 若没有写成,继续
mov pc,lr@ 返回
.align 4
mem_cfg_val:
@ 存储控制器13个寄存器的设置值
.long0x22011110@ BWSCON
.long0x00000700@ BANKCON0
.long0x00000700@ BANKCON1
.long0x00000700@ BANKCON2
.long0x00000700@ BANKCON3
.long0x00000700@ BANKCON4
.long0x00000700@ BANKCON5
.long0x00018005@ BANKCON6
.long0x00018005@ BANKCON7
.long0x008C07A3@ REFRESH
.long0x000000B1@ BANKSIZE
.long0x00000030@ MRSRB6
.long0x00000030@ MRSRB7
C语言:
#define MEM_CTL_BASE 0X48000000
//设置存储控制器以使用SDRAM
void memsetup(void)
{
unsigned longconstmem_cfg_val[]={ 0x22011110,//BWSCON
0x00000700,//BANKCON0
0x00000700,//BANKCON1
0x00000700,//BANKCON2
0x00000700,//BANKCON3
0x00000700,//BANKCON4
0x00000700,//BANKCON5
0x00018005,//BANKCON6
0x00018005,//BANKCON7
0x008C07A3,//REFRESH
0x000000B1,//BANKSIZE
0x00000030,//MRSRB6
0x00000030,//MRSRB7
};
inti = 0;
volatile unsigned long *p = (volatile unsigned long *)MEM_CTL_BASE;
for(; i < 13; i++)
p[i] = mem_cfg_val[i];
}
分享: