28335 按键中断 控制LED灯


#include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File

// Prototype statements for functions found within this file.
interrupt void led_response(void);
void gpio_select(void);
void led_init();
void gpio48_init();
void key_pie_init();

unsigned int flag =1;

void main(void)
{

  // 设置cpu工作的时钟
   InitSysCtrl();


// 禁止INTM
   DINT;

// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
   InitPieVectTable();

   gpio_select();
   led_init();
   gpio48_init();
   key_pie_init();


// Enable global Interrupts and higher priority real-time debug events:
   EINT;   // Enable Global interrupt INTM
   ERTM;   // Enable Global realtime interrupt DBGM

// Step 6. IDLE loop. Just sit and loop forever (optional):
   for(;;);
}


void led_init()
{
	GpioDataRegs.GPBSET.bit.GPIO60 = 0x1;
}

void gpio48_init(){
	GpioDataRegs.GPBSET.bit.GPIO48 = 0x0;
}
void key_pie_init(){
	EALLOW;
	GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 12; //中断绑定gpio引脚
	XIntruptRegs.XINT1CR.bit.POLARITY = 0x00;//设置中断触发方式为下降沿

	XIntruptRegs.XINT1CR.bit.ENABLE = 0x1;//使能XINT1外设中断

	PieCtrlRegs.PIECTRL.bit.ENPIE =0x1;//使能PIE 中断
	PieCtrlRegs.PIEIER1.bit.INTx4 = 0x1;//使能PIE的IER

	PieVectTable.XINT1 =&led_response;//中断调用子程序入口绑定

	IER |= M_INT1;//使能CPU IER
	EDIS; //使能INTM
}
void gpio_select(){

	   EALLOW;
	   //LED
	   GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 0x0;
	   GpioCtrlRegs.GPBDIR.bit.GPIO60 = 0x1;

	   //key_r
	   GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0x0;
	   GpioCtrlRegs.GPADIR.bit.GPIO12 = 0x0;
	   GpioCtrlRegs.GPAPUD.bit.GPIO12 =0x1;

	   GpioCtrlRegs.GPACTRL.bit.QUALPRD1 =255;
	   GpioCtrlRegs.GPAQSEL1.bit.GPIO12 =2;

	   //key_c
	   GpioCtrlRegs.GPBMUX2.bit.GPIO48 =0x0;
	   GpioCtrlRegs.GPBDIR.bit.GPIO48 = 0x1;
	   EDIS;
}



void interrupt_delay(){
	unsigned long i;
	unsigned long j;
	for (j=0;j<10;j++){
		for (i=0;i<150000;i++);
	}
}
interrupt void led_response(void)
  {
	    interrupt_delay();
		//GpioDataRegs.GPBTOGGLE.bit.GPIO60 = 0x1;
		PieCtrlRegs.PIEACK.all =PIEACK_GROUP1;//清中断
		if(flag){
			GpioDataRegs.GPBSET.bit.GPIO60 = 0x1;
			flag =0;
		}
		else {
			GpioDataRegs.GPBCLEAR.bit.GPIO60 = 0x1;
			flag =1;
		}
		GpioDataRegs.GPBTOGGLE.bit.GPIO60 = 0x1;

  }

//===========================================================================
// No more.
//===========================================================================

你可能感兴趣的:(嵌入式硬件)