?? main.c
字號:
/*------------------------------------------------------------------------------
main.c
Version:
March 22, 2005 - Version 1.0 - Initial Release.
Description: USB Reference Design - Flash Disk Application (read only)
This reference design enumerates as a USB flash disk making use of the USB Mass
Storage Device Class driver. It will appear as an available drive on the system
with read only content.
This reference design is intended to demonstrate USB functionality and provide
example code on using the USB module within the uPSD34xx.
Supported platforms:
DK3400
Notes:
(1) It is important to modify the FREQ_OSC setting in upsd3400_hardware.h
to match the oscillator frequency on the board being used.
(2) It is also important to change, as appropriate, the PLL setting in
the USBInitialize() function to match the MCU's oscillator in order for
USB to work properly.
Copyright (c) 2005 STMicroelectronics Inc.
This example demo code is provided as is and has no warranty,
implied or otherwise. You are free to use/modify any of the provided
code at your own risk in your applications with the expressed limitation
of liability (see below) so long as your product using the code contains
at least one uPSD product (device).
LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
------------------------------------------------------------------------------*/
#pragma NOAREGS
#include "upsd3400.h"
#include "upsd3400_hardware.h"
#include "upsd3400_usb.h"
#include "upsd3400_usb_desc.h"
#include "upsd3400_upsd_usb.h"
#include "upsd3400_usb_app.h"
#define RemoteWakeupEnable 0
//default values for file system, 2048 Bytes, user specific !!!
extern code unsigned char DefaultDiskInit[2048];
pdata unsigned char PageDataBuffer[64];
data unsigned char BankCurrent;
xdata PSD_REGS UPSD_xreg _at_ PSD_REG_ADDR;
data unsigned char ReconnectDemand;
extern unsigned char data usbState;
static data unsigned int g_debugUSB_INT_CNT = 0;
extern unsigned char volatile gbBulkPipeStage;
const unsigned char code RED_LED_PWM_TABLE[45] =
{
0,0,0,0,0,0,0,0,0,0,0,1,2,4,6,8,9,11,13,15,17,19,21,24,26,29,38,41,46,49,53,58,63,69,77,85,95,109,127,159,255,255,255,255,255
}
;
data unsigned char REDLED_Pointer;
bit RED_LED_UPDOWN_FLAG;
data unsigned char REDLED_PWM;
data unsigned char REDLED;
data unsigned int REDCNT;
extern unsigned char USB_ISR_Counter;
unsigned char Aux_USB_ISR_Counter;
void T0ISR (void) interrupt TF0_VECTOR using 1
/******************************************************************************
Function : void T0ISR ()
Parameters : (void)
Description: LED effects routine
******************************************************************************/
{
REDLED_PWM+=5;
if (REDLED_PWM<=REDLED)
{
UPSD_xreg.DATAOUT_D = 2;
}
else
{
UPSD_xreg.DATAOUT_D = 0;
}
REDCNT-= 1;
if (REDCNT == 0)
{
REDCNT = 300;
/* ***** RED LED service ***** */
if (RED_LED_UPDOWN_FLAG)
{
REDLED_Pointer++;
if (REDLED_Pointer >= sizeof(RED_LED_PWM_TABLE)-1)
{
RED_LED_UPDOWN_FLAG = ~RED_LED_UPDOWN_FLAG;
REDLED_Pointer = sizeof(RED_LED_PWM_TABLE)-1;
}
}
else
{
REDLED_Pointer--;
if (REDLED_Pointer == 0) RED_LED_UPDOWN_FLAG = ~RED_LED_UPDOWN_FLAG;
}
REDLED = ~RED_LED_PWM_TABLE[REDLED_Pointer];
}
}
void main(void)
/******************************************************************************
Function : void main()
Parameters : (void)
Description: The main routine
******************************************************************************/
{
data int i;
ReconnectDemand = 0;
// Copy the initial disk Dir&FAT content now
for (i=0;i<sizeof(DefaultDiskInit);i++)
{
((char volatile xdata *) 0x8000)[i] = ((char volatile code *) DefaultDiskInit)[i];
}
UsbInitialize();
// Enable DK3420_Lite_USB_PullUp
UPSD_xreg.DIRECTION_C |=128; // PC7=Out
UPSD_xreg.DRIVE_C &=127; // PC7=Push/Pull
UPSD_xreg.DATAOUT_C |=128; // PC7=1
UPSD_xreg.DIRECTION_D |= 2; // RED LED ON
UPSD_xreg.OUTENABLE_D |= 2;
UPSD_xreg.DATAOUT_D = 0;
REDLED_Pointer = 1; // RED LED EFFECT
RED_LED_UPDOWN_FLAG = 0;
REDLED_PWM = 0;
REDLED = 128;
REDCNT = 32;
//Timer0, blinking LEDs and SW PWM service
TR0 = 0; // stop timer 0
TMOD &= 0xF0; // clear timer 0 mode bits
TMOD |= 0x02; // put timer 0 into right mode
TH0 = -128; // 12MHz/12/-x
ET0 = 1; // enable timer 0 interrupt
TR0 = 1; // start timer 0
while (1)
{
}
}
/* *************************************************************************
*** ***
** *** End of File *** **
*** ***
************************************************************************* */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -