本帖最后由 quyifei 于 2013-6-8 17:42 编辑
grasswolfs 发表于 2013-6-8 16:48
我是说中断和主函数里面的 TimingDelay是同样的么?
是一样的。 我把程序贴出来,这样更加清楚。 延时用的是Delay_ms(1000),延时1秒。如果用Delay_ms(1000);上面注释掉的方法延时就没有问题。
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usb_lib.h"
#include "usb_pwr.h"
#include "hw_config.h"
#include <stdio.h>
/*private viariables declaration----------------------------------------------*/
__IO uint32_t TimingDelay;
static uint8_t USBData[]="Hello 21ic ";
/**
* @Breif Main program.
* @param None
* @retval None
*/
int main(void)
{
/*Configuration Systick as 1000Hz*/
if (SysTick_Config(SystemCoreClock / 1000))
{
while (1);
}
Set_System();
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
while (1)
{
if (bDeviceState == CONFIGURED)
{
UserToPMABufferCopy(USBData, ENDP1_TXADDR, 11);
SetEPTxCount(ENDP1, 11);
SetEPTxValid(ENDP1); //Valid ENDP1 to start sending "Hello 21ic " to PC
}
/*
volatile uint32_t tmp=0;
tmp=10000000;
while(tmp--); //delay 1s
*/
Delay_ms(1000); //delay 1s
}
}
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Inserts a delay time.
* @param nTime: specifies the delay time length, in milliseconds.
* @retval None
*/
void Delay_ms(uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/**
* @brief Decrements the TimingDelay variable. called by SysTick_Handler()
* @param None
* @retval None
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
|