Profile:
This section is mainly recorded in the tiny 6410 Development Board written in the bare Metal program key interrupt control LED light.
8 user-defined keys are configured in the Tiny6410, and KEY1 is used to control the LED1~LED4. The key and led circuits are as follows:
K1 corresponds to the external interrupt Eint0,led1~led4 configuration method as described in the article Embedded bootloader Development Six (Tiny 6410), no longer making statements, The main record of the external interrupt configuration method and how to use Vic for interrupt control and how to write bare metal interrupt handler.
In principle, the external interrupt is similar to the watchdog interrupt described in the previous article, except that there are some extra configurations for external interrupts, and the way to configure interrupt triggering can be divided into two main types: level triggering and edge triggering.
Level trigger can be divided into high and low level trigger, while the edge trigger can be divided into the rising edge, the descent along and up and down are triggered by the way. In addition, to configure the interrupt allow Register EINT0 enable, so that the hardware can emit interrupt signal, the specific configuration code as follows:
void Key_init (void)
{
Gpncon &= ~ (0x3);
Gpncon |= (0x2),//set to external interrupt gpnpud-&= (0x3
);//
Eint0con0 &= ~ (0x7)
; Eint0con0 |= 0x2;//falling-edge Trigger
eint0mask &= ~ (0x1);//enable EINT0
}
From the key to the circuit connection diagram can be seen when the key is not pressed when the high, pressed when low, so set it to drop along the trigger interrupt, in the interrupt processing function, print the corresponding information, control the LED lights out, while clearing the interrupt signal and interrupt processing function address register vic0address, the specific code is as follows:
ISR Entry
void Irq_handler (void)
{
__asm__ volatile (
"sub lr,lr, #4 \ n"//Modify return address
stmfd sp,{ r0-r14}\n "//Save Program execution field
" sub sp,sp, #60 \ n "//Modify SP pointer, if directly using STMFD Sp!,{r0-r14} will prompt warning
" mov lr,pc\n "// Set the return address of the interrupt handler
"LDR pc,=do_irq\n"//Call Interrupt handler function Do_irq
"LDMFD sp,{r0-r13,pc}^\n"//Interrupt processing complete, recovery program execution site
);
}
void Do_irq (void)
{
if (flag) {
flag=0;
LED_ON (0xE);
} else{
flag=1;
Led_off ();
}
Show ("Key1 entered!\n");
Eint0pend &= 0x1;//purge EINT0 interrupt
vic0address = 0;//Purge Interrupt handler interrupt
}
LED light control using a relatively simple method to achieve, global variable flag indicates whether the current to turn off or turn on the LED lights.