《tiny6410裸机程序》第九章:tiny6410按键控制蜂鸣器程序

====================================================================================================================================

还没有调通,先记录一下吧:

1.Startup.s

	preserve8  
	IMPORT  keymain        ; 声明C程序中的Main()函数  
	AREA    Start,CODE,READONLY ; 声明代码段Start  
	ENTRY               ; 标识程序入口  
	CODE32              ; 声明32位ARM指令  
  
	ldr r0, =0x70000000        
	orr r0, r0, #0x13  
	mcr p15,0,r0,c15,c2,4     ;256M(0x70000 0000~0x7FFF FFFF)ARM协处理器相关 告诉协处理器外设寄存器的基地址和地址空间


	ldr r0, =0x7E004000  
	mov r1, #0  
	str r1, [r0]              ;关闭看门狗  
  
	ldr sp, =8*1024           ;设置C堆栈  

PROC
	mrc p15,0,r0,c1,c0,0
	orr r0,r0,#(1<<24)
	mcr p15,0,r0,c1,c0,0  ;禁止MMU和Cache
	mov	pc,lr   ;使能VIC
ENDP
	;mrs	r0,cpsr
	;bic	r0,r0,#(1<<7)
	;msr	cpsr_cxsf,r0             
	;mov	pc,lr  ;使能IRQ


	bl keymain 
	END

2.key.c

//VIC总中端控制器
#define rVIC0INTENABLE (*(volatile u32 *)(0x71200000 + 0x10))
#define rVIC0INTENCLEAR (*(volatile u32 *)(0x71200000 + 0x14))
#define rVIC0INTSELECT (*(volatile u32 *)(0x71200000 + 0x0c))
#define rVIC0ADDR (*(volatile u32 *)(0x71200000 + 0xff))
#define rVIC0VECTADDR (*(volatile u32 *)(0x71200000 + 0x100))

//GPIO
#define rGPIOFCON (*(volatile u32 *)0x7f0080a0)  //连接蜂鸣器
#define rGPIOFDAT (*(volatile u32 *)0x7f0080a4)

#define rGPIONCON (*(volatile u32 *)0x7f008830)  //连接按键
#define rGPIONPUD (*(volatile u32 *)0x7f008838)

//外部子中断控制器
#define rEINT0CON0 (*(volatile u32 *)0x7f008900)
#define rEINT0MASK (*(volatile u32 *)0x7f008920)
#define rEINT0PEND (*(volatile u32 *)0x7f008924)

typedef unsigned long u32;

void __irq Isr_Eint(void);
void GPIOFinit(void);
void GPIONinit(void);
void GPIONinit1(void);
void EINT0init(void);
void ENABLEvic0(void);
void EINT0mask(void);

int keymain(void){

    //设置GPN0(连接KEY1)引脚为外部终端模式
  GPIONinit();
  GPIONinit1();

  //设置GPF14(连接蜂鸣器)引脚为输出模式
  GPIOFinit(); 
   

  //设置外部子中断控制器,即GPN0(EINT0)为低电平触发中断
  EINT0init();

  


  //解除外部子中断EINT0/GPN0的中断屏蔽
  EINT0mask();
  
    
    //初始化VIC总中断控制器
  //rVIC0INTENCLEAR = 0xffffffff;
  //rVIC0INTSELECT = 0x0;
  //rVIC0ADDR = 0;

  //设置总中断控制器中端服务程序入口地址
  rVIC0VECTADDR = ((unsigned)Isr_Eint);
  ENABLEvic0();
  
  while(1);
}

void __irq Isr_Eint(void){
  u32 i;
  rEINT0PEND = 0x1;  //清除中断
  rGPIOFDAT |= 0x1<<14;    //0000 0000 0000 0000 10000 0000 0000 0000
  for(i=0;i<3000*100;i++);
  rGPIOFDAT &= ~(0x1<<14);  //1111 1111 1111 1111 01111 1111 1111 1111
  for(i=0;i<3000*100;i++);
  rVIC0ADDR = 0x0;
}

void GPIOFinit(void){
  u32 fConValue;
  //设置GPF14(连接蜂鸣器)引脚为输出模式
  fConValue = rGPIOFCON;
  fConValue &= ~(0x3<<28); //1100 1111 1111 1111 1111 1111 1111 1111
  fConValue |= 0x1<<28;    //0001 0000 0000 0000 0000 0000 0000 0000
  rGPIOFCON = fConValue;
}

void GPIONinit(void){
  u32 nConValue;
  //设置GPN0(连接KEY1)引脚为外部终端模式
  //nConValue = rGPIONCON;
  nConValue &= ~(0x3);     //1111 1111 1111 1111 1111 1111 1111 1100
  nConValue |= 0x2;        //0000 0000 0000 0000 0000 0000 0000 0010
  rGPIONCON = nConValue;
}
void GPIONinit1(void){
  u32 n1ConValue;
  n1ConValue = rGPIONPUD;
  n1ConValue &= ~(0x3);     //1111 1111 1111 1111 1111 1111 1111 1100
  n1ConValue |= 0x0;        //0000 0000 0000 0000 0000 0000 0000 0000
  rGPIONPUD = n1ConValue;
}

void EINT0init(void){
  //设置外部子中断控制器,即GPN0(EINT0)为低电平触发中断 
  u32 eConValue;
  eConValue = rEINT0CON0;
  eConValue &= ~(0x7);     //1111 1111 1111 1111 1111 1111 1111 1000
  eConValue |= 0x0;        //0000 0000 0000 0000 0000 0000 0000 0000
  rEINT0CON0 = eConValue; 
  rEINT0PEND = 0x1;
}

void ENABLEvic0(void){
  u32 vConValue;
  vConValue = rVIC0INTENABLE;
  vConValue |= 0x1;        //0000 0000 0000 0000 0000 0000 0000 0001
  rVIC0INTENABLE = vConValue;	
}

void EINT0mask(void){
  u32 mConValue;
  mConValue = rEINT0MASK;
  mConValue &= ~(0x1);     //1111 1111 1111 1111 1111 1111 1111 1110
  rEINT0MASK = mConValue;
}
3.以下是基于Window下armcc编译器的Makefile

all:	
	armasm -o Startup.o Startup.s --debug --keep --cpu=ARM1176JZF-S
	armcc -c key.o key.c --debug --cpu=ARM1176JZF-S -O0	
	armlink -o mykey.axf Startup.o key.o --ro_base=0x50200000 --rw_base=0x50203000 --first=Startup.o(start) --entry=0x50200000
	fromelf -o mykey.bin --bin mykey.axf
clean:	
	del *.o *.axf *.bin




你可能感兴趣的:(《tiny6410裸机程序》第九章:tiny6410按键控制蜂鸣器程序)