,你可以对比一下。 (DSP2812和 DSP28335是差不多的)
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#define LED1_ON GpioDataRegs.GPASET.bit.GPIO0=1
#define LED1_OFF GpioDataRegs.GPACLEAR.bit.GPIO0=1
#define LED2_ON GpioDataRegs.GPASET.bit.GPIO1=1
#define LED2_OFF GpioDataRegs.GPACLEAR.bit.GPIO1=1
#define LED3_ON GpioDataRegs.GPASET.bit.GPIO2=1
#define LED3_OFF GpioDataRegs.GPACLEAR.bit.GPIO2=1
#define LED4_ON GpioDataRegs.GPASET.bit.GPIO3=1
#define LED4_OFF GpioDataRegs.GPACLEAR.bit.GPIO3=1
#define LED5_ON GpioDataRegs.GPASET.bit.GPIO4=1
#define LED5_OFF GpioDataRegs.GPACLEAR.bit.GPIO4=1
#define LED6_ON GpioDataRegs.GPASET.bit.GPIO5=1
#define LED6_OFF GpioDataRegs.GPACLEAR.bit.GPIO5=1
#define LED7_ON GpioDataRegs.GPBSET.bit.GPIO51=1
#define LED7_OFF GpioDataRegs.GPBCLEAR.bit.GPIO51=1
#define LED8_ON GpioDataRegs.GPBSET.bit.GPIO50=1
#define LED8_OFF GpioDataRegs.GPBCLEAR.bit.GPIO50=1
interrupt void ISRExint3(void)
interrupt void ISRExint4(void)
interrupt void ISRExint5(void)
interrupt void ISRExint6(void)
void configtestled(void)
Uint16 sign
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl()
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio() // Skipped for this example
InitXintf16Gpio()//zq
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
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()
// Interrupts that are used in this example are re-mapped to// ISR functions found within this file.
EALLOW // This is needed to write to EALLOW protected registers
PieVectTable.XINT3 = &ISRExint3
PieVectTable.XINT4 = &ISRExint4
PieVectTable.XINT5 = &ISRExint5
PieVectTable.XINT6 = &ISRExint6
EDIS // This is needed to disable write to EALLOW protected registers
PieCtrlRegs.PIECTRL.bit.ENPIE = 1 // Enable the PIE block
PieCtrlRegs.PIEIER12.bit.INTx1= 1
PieCtrlRegs.PIEIER12.bit.INTx2= 1
PieCtrlRegs.PIEIER12.bit.INTx3= 1
PieCtrlRegs.PIEIER12.bit.INTx4= 1
IER |= M_INT12 // Enable CPU int1
EINT // Enable Global interrupt INTM
ERTM // Enable Global realtime interrupt DBGM
configtestled()
sign = 0
while(1)
{
if(sign==0)
{ LED1_OFF
LED2_OFF
LED3_OFF
LED4_OFF
LED5_OFF
LED6_OFF
LED7_OFF
LED8_OFF
DELAY_US(50000)
LED1_ON
DELAY_US(50000)
LED2_ON
DELAY_US(50000)
LED3_ON
DELAY_US(50000)
LED4_ON
DELAY_US(50000)
LED5_ON
DELAY_US(50000)
LED6_ON
DELAY_US(50000)
LED7_ON
DELAY_US(50000)
LED8_ON
DELAY_US(50000) //NO XINT
}
if(sign==3)
{
LED1_OFF
LED2_OFF
LED3_OFF
LED4_OFF
LED5_OFF
LED6_OFF
LED7_OFF
LED8_OFF
DELAY_US(50000)
LED1_ON
LED2_ON
DELAY_US(50000)
LED3_ON
LED4_ON
DELAY_US(50000)
LED5_ON
LED6_ON
DELAY_US(50000)
LED7_ON
LED8_ON
DELAY_US(50000) // XINT3 COME
}
if(sign==4)
{ LED1_ON
LED2_ON
LED3_ON
LED4_ON
LED5_ON
LED6_ON
LED7_ON
LED8_ON
DELAY_US(50000)
LED1_OFF
DELAY_US(50000)
LED2_OFF
DELAY_US(50000)
LED3_OFF
DELAY_US(50000)
LED4_OFF
DELAY_US(50000)
LED5_OFF
DELAY_US(50000)
LED6_OFF
DELAY_US(50000)
LED7_OFF
DELAY_US(50000)
LED8_OFF
DELAY_US(50000) // XINT4 COME
}
if(sign==5)
{LED1_ON
LED2_ON
LED3_ON
LED4_ON
LED5_ON
LED6_ON
LED7_ON
LED8_ON
DELAY_US(50000)
LED1_OFF
LED2_OFF
DELAY_US(50000)
LED3_OFF
LED4_OFF
LED1_ON
LED2_ON
DELAY_US(50000)
LED5_OFF
LED6_OFF
LED3_ON
LED4_ON
DELAY_US(50000)
LED7_OFF
LED8_OFF
LED5_ON
LED6_ON
DELAY_US(50000) // XINT5 COME
}
if(sign==6)
{LED1_OFF
LED2_ON
LED3_OFF
LED4_ON
LED5_OFF
LED6_ON
LED7_OFF
LED8_ON
DELAY_US(50000)
LED1_ON
LED2_OFF
LED3_ON
LED4_OFF
LED5_ON
LED6_OFF
LED7_ON
LED8_OFF
DELAY_US(50000) // XINT5 COME
}
}
}
interrupt void ISRExint3(void)
{
PieCtrlRegs.PIEACK.all = PIEACK_GROUP12
sign=3
}
interrupt void ISRExint4(void)
{
PieCtrlRegs.PIEACK.all = PIEACK_GROUP12
sign=4
}
interrupt void ISRExint5(void)
{
PieCtrlRegs.PIEACK.all = PIEACK_GROUP12
sign=5
}
interrupt void ISRExint6(void)
{
PieCtrlRegs.PIEACK.all = PIEACK_GROUP12
sign=6
}
void configtestled(void)
{
EALLOW
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0// GPIO0 = GPIO0
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0// GPIO1 = GPIO1
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0// GPIO2 = GPIO2
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0// GPIO3 = GPIO3
GpioCtrlRegs.GPADIR.bit.GPIO3 = 1
GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0// GPIO4 = GPIO4
GpioCtrlRegs.GPADIR.bit.GPIO4 = 1
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0// GPIO5 = GPIO5
GpioCtrlRegs.GPADIR.bit.GPIO5 = 1
GpioCtrlRegs.GPBMUX2.bit.GPIO51 = 0// GPIO51 = GPIO51
GpioCtrlRegs.GPBDIR.bit.GPIO51 = 1
GpioCtrlRegs.GPBPUD.bit.GPIO51=0
GpioCtrlRegs.GPBMUX2.bit.GPIO50 = 0// GPIO50 = GPIO50
GpioCtrlRegs.GPBDIR.bit.GPIO50 = 1
GpioCtrlRegs.GPBPUD.bit.GPIO50=0
EDIS
}
//===========================================================================
// No more.
//===========================================================================
这可能跟你定时器设定的timer0执行频率有关,当count等于0时,while(count)还未得到执行就又被中断打断了可以在timer0中写:if ( count ) count--试试,或者在timer0中把中断关了就是
这是带插入汇编的C程序。其中asm(" ")是指直接插入并执行一个汇编指令,以便加速处理。这种加入汇编指令的办法仅仅适用于一些特定用途,不能随意使用,否则可能破坏程序参数。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)