"Tiny6410 Bare Metal Program" nineth Chapter: tiny6410 Key Control Buzzer Program _ hardware-related

Source: Internet
Author: User
Tags volatile

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

There is no transfer, record it first:

1.startup.s

	Preserve8  
	IMPORT  Keymain        declares the main () function area start,code,readonly in the C program,    declares the code snippet Start  
	ENTRY               ; Identify the program entry  
	CODE32              Statement 32-bit ARM instruction  
  
	LDR r0, =0x70000000        
	Orr r0, R0, #0x13  
	mcr p15,0,r0,c15,c2,4     ; 256M (0x70000 0000~0X7FFF FFFF) Arm coprocessor tells the coprocessor the base address and address space of the peripheral registers


	Ldr r0, =0x7e004000  
	mov r1, #0  
	str R1, [r0]              ; Close the watchdog.  
  
	Ldr sp, =8*1024           ; set c stack  

PROC
	MRC p15,0,r0,c1,c0,0
	Orr r0,r0,# (1<<24)
	MCR p15,0, r0,c1,c0,0  prohibit MMU and cache
	mov	PC,LR   ; enable Vic
ENDP
	; Mrs	R0,CPSR
	; Bic	r0,r0,# (1<<7)
	; MSR	cpsr_cxsf,r0             
	; mov	PC,LR  ; enabling IRQ


	BL Keymain 
	End

2.key.c

Vic total midrange controller #define RVIC0INTENABLE (* (Volatile u32 *) (0x71200000 + 0x10)) #define RVIC0INTENCLEAR (* (Volatile u32 *) (0x712 00000 + 0x14)) #define RVIC0INTSELECT (* (Volatile u32 *) (0x71200000 + 0x0c)) #define RVIC0ADDR (* (Volatile u32 *) (0x712000 + 0xff) #define RVIC0VECTADDR (* (Volatile u32 *) (0x71200000 + 0x100))//gpio #define RGPIOFCON (* (volatile u32 *) 0x7f
0080A0)//Connection buzzer #define RGPIOFDAT (* (volatile u32 *) 0x7f0080a4) #define RGPIONCON (* (volatile u32 *) 0x7f008830)//Connect key #define RGPIONPUD (* (volatile u32 *) 0x7f008838)//External child Interrupt Controller #define REINT0CON0 (* volatile u32 *) 0x7f008900) #define Reint

0MASK (* (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) {//Set GPN0 (connection KEY1) PIN for external terminal mode Gpioninit ();

  GPIONinit1 (); Set GPF14 (connection buzzer) pin for output mode GPIOFinit ();

  


  Set the external child interrupt controller, i.e. GPN0 (EINT0) for low-level triggering interrupt eint0init ();
  
    
    Eint0/gpn0 Interrupt Shielding Eint0mask () for external child interrupts;
  Initialize VIC total interrupt controller//rvic0intenclear = 0xFFFFFFFF;
  Rvic0intselect = 0x0;

  rvic0addr = 0;
  Set the total Interrupt Controller midrange Service entry Address rvic0vectaddr = ((unsigned) isr_eint);
  
  ENABLEvic0 ();
while (1);
  } void __irq Isr_eint (void) {u32 i;  Reint0pend = 0x1;    Clear Interrupt Rgpiofdat |= 0x1<<14;
  0000 0000 0000 0000 10000 0000 0000 for (0000);  Rgpiofdat &= ~ (0x1<<14);
  1111 1111 1111 1111 01111 1111 1111 for (1111);
RVIC0ADDR = 0x0;
  } void Gpiofinit (void) {u32 fconvalue;
  Set GPF14 (connection buzzer) pin for output mode 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;
  } void Gpioninit (void) {u32 nconvalue;
  Set GPN0 (connection KEY1) PIN for external terminal mode//nconvalue = Rgpioncon; Nconvalue &= ~ (0x3);        1111 1111 1111 1111 1111 1111 1111 1100 nconvalue;
0000 0000 0000 0000 0000 0000 0000 = 0010 Rgpioncon;
  } void GPIONinit1 (void) {u32 n1convalue;
  N1convalue = Rgpionpud;     N1convalue &= ~ (0x3);        1111 1111 1111 1111 1111 1111 1111 1100 n1convalue;
0000 0000 0000 0000 0000 0000 0000 = 0000 Rgpionpud;
  } void Eint0init (void) {//Set external child interrupt Controller, i.e. GPN0 (EINT0) for low-level triggering interrupt u32 econvalue;
  Econvalue = Reint0con0;     Econvalue &= ~ (0x7);        1111 1111 1111 1111 1111 1111 1111 1000 econvalue; 
  0000 0000 0000 0000 0000 0000 0000 = 0000 Reint0con0;
Reint0pend = 0x1;
  } void ENABLEvic0 (void) {u32 vconvalue;
  Vconvalue = rvic0intenable;        Vconvalue |= 0x1;	
0000 0000 0000 0000 0000 0000 0000 = 0001 rvic0intenable;
  } void Eint0mask (void) {u32 mconvalue;
  Mconvalue = Reint0mask;     Mconvalue &= ~ (0x1); 1111 1111 1111 1111 1111 1111 1111 1110
  Reint0mask = Mconvalue; }
3. The following is a makefile based on the Windows ARMCC compiler

All:	
	armasm-o startup.o startup.s--debug--keep--cpu=arm1176jzf-s armcc-c key.o key.c--debug--cpu=ARM1176JZ
	F-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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.