本帖最后由 shukeli 于 2016-12-2 15:55 编辑
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
void StopPulse(void);//封锁脉冲
Uint16 *ExRamStart = (Uint16 *)0x100000;
void EPwmSetup();
Uint16 i;
int Sw ;
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();
GpioCtrlRegs.GPCPUD.bit.GPIO80 = 0;
GpioCtrlRegs.GPCMUX2.bit.GPIO80 = 0;
GpioCtrlRegs.GPCDIR.bit.GPIO80 = 1;
Sw = 0;
// 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.
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2833x_CpuTimers.c
// InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
//ConfigCpuTimer(&CpuTimer0, 150, 1000000);
//ConfigCpuTimer(&CpuTimer1, 150, 1000000);
//ConfigCpuTimer(&CpuTimer2, 150, 1000000);
// StartCpuTimer0();
// StopPulse();
for(; ;)
{
Sw = GpioDataRegs.GPCDAT.bit.GPIO80;
if(Sw==1 )
{
EPwmSetup();
}
else
{
StopPulse();//闭锁脉冲
}
}
}
void StopPulse(void)//闭锁脉冲
{
GpioDataRegs.GPACLEAR.bit.GPIO0=1;
GpioDataRegs.GPACLEAR.bit.GPIO1=1;
GpioDataRegs.GPACLEAR.bit.GPIO2=1;
GpioDataRegs.GPACLEAR.bit.GPIO3=1;
GpioDataRegs.GPACLEAR.bit.GPIO4=1;
GpioDataRegs.GPACLEAR.bit.GPIO5=1;
}
//===========================================================================
// No more.
//===========================================================================
一个简单的程序,我却出现如下几个问题:
1、Sw = GpioDataRegs.GPCDAT.bit.GPIO80;这句话如果放在for循环外面,就根本发不出波形。
2、按照如上的程序,我的本意是Sw=1的时候,即开关闭合时,发脉冲。否则,闭锁脉冲。但是最后示波器上显示出,当开关打开时,是有发脉冲,开关闭合,反而没有脉冲或者脉冲为1.
3、当把for循环里面的if(Sw==1)改为(Sw==0)时,能得到我大概想要的结果。但是整个程序的设计和我正好相反。。。。
不知道哪里错了???@zhangmangui 还有各位前辈 |