⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 Mitsubishi M30245 SampleCode
💻 C
字号:
/*******************************************************************
 *
 *    DESCRIPTION: M30245 Mit_USB Demonstration Application
 *
 *    AUTHOR: Mitsubishi DEC-E
 *
 *    HISTORY: 0.5 5/30/02 Initial creation for NC30
 *			   1.0 6/18/02 First official release
 *			   1.1 6/27/02 Updated ISO routines
 *			   1.2 8/07/02 Updated for Rev B Starter Kit Board
 *
 *******************************************************************/

/** include files **/
#include "sfr245.h"
#include "globals.h"

// External Function References
extern void RegisterInit(void);
extern void TimerA1Init(void);
extern void InitAD(void);
extern void InitUART3(void);
extern void StartPll(void);
extern void USBCoreStart(void);
extern void USBEndpointInit(void);
extern void RequestType(void);
extern void ServiceEP1Out(void);
extern void LoadEP1IN(void);
extern void ServiceEP1IN(void);
extern void ServiceEP3IN(void);
extern void ServiceEP3OUT(void);

/*
 ** main
 *
 *  FILENAME: main.c
 *
 *  PARAMETERS: None
 *
 *  DESCRIPTION: Everything starts here. Device is setup and USB core is init'ed
 *				 ( if bit flag is set ) and loops until there's something to do.
 *
 *  RETURNS: Nothing
 *
 */
void main(void){
	asm("FSET I");

	RegisterInit();			// Function call mainly to setup Vbus detect
	TimerA1Init();			// Switch/AD monitor here
	InitAD();				// Initalize the AD converter
	InitUART3();			// Initalize the UART for ISO out data

	while(1){					// Device hangs here waiting for something to do
		if ( USBFlags.USBFirstStart ){	// Was cable plugged in for first time?
			StartPll();			// If so then start the PLL
			USBCoreStart();		// Now enable the usb core
			USBEndpointInit();	// And setup the endpoints
			
			attach = 1;			// and pullup D+ for host attachemnt

			USBFlags.USBFirstStart = 0;	// Clear out flag
		}

		if ( ep0csr2 ){			// Has a SETUP packet been received?
			RequestType();
		}
		
		if ( DataTransferFlags.NewEP2Data ){		// Check to send new interrupt data
			SendInterruptData();
		}

		if ( DataTransferFlags.BulkDataReceived ){	// Has BULK data been received?
			DataTransferFlags.BulkDataReceived = 0;
			ServiceEP1Out();
		}

		if ( DataTransferFlags.SendBulkData ){		// Do we send BULK data?
			DataTransferFlags.SendBulkData = 0;
			LoadEP1IN();
		}

		if ( DataTransferFlags.EP1DataTransmit ){	// Is there more BULK data to send?
			DataTransferFlags.EP1DataTransmit = 0;
			ServiceEP1IN();
		}

		if ( DataTransferFlags.EP3INReady ){		// Send ISO data?
			DataTransferFlags.EP3INReady = 0;		
			ServiceEP3IN();
		}

		if ( DataTransferFlags.EP3DataReceived ){	// Receive ISO data?
			DataTransferFlags.EP3DataReceived = 0;
			ServiceEP3OUT();
		}

		if(ti_u3)	{								// Send new UART3 data?
			if( disp_buffer[ disp_index ] != 0 ) {
	            while(ti_u3 == 0);	                // wait for previous transfer to complete
				u3tbl = disp_buffer[ disp_index ];	// put in UART Tx buffer
				disp_buffer[ disp_index ] = 0;		// Reset char location back to 0
				disp_index++;						// Increment to next location
				disp_index &= 0xFF;					// If > 255, this will reset to 0
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -