📄 main.c
字号:
//*--------------------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*--------------------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*--------------------------------------------------------------------------------------
//* File Name : main file
//* Object :
//* Translator :
//* 1.0 02/Mar/05 JPP : Creation
//*--------------------------------------------------------------------------------------
#include "board.h"
#include "cdc_enumerate.h"
#define MSG_SIZE 1000
//* external function
extern void Usart_init ( void );
extern void AT91F_US_Put( char *buffer); // \arg pointer to a string ending by \0
extern void Trace_Toggel_LED( unsigned int led) ;
struct _AT91S_CDC pCDC;
//*----------------------------------------------------------------------------
//* \fn AT91F_USB_Open
//* \brief This function Open the USB device
//*----------------------------------------------------------------------------
void AT91F_USB_Open(void)
{
// Set the PLL USB Divider
AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ;
// Specific Chip USB Initialisation
// Enables the 48MHz USB clock UDPCK and System Peripheral USB Clock
AT91C_BASE_PMC->PMC_SCER = AT91C_PMC_UDP;
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_UDP);
// CDC Open by structure initialization
AT91F_CDC_Open(&pCDC, AT91C_BASE_UDP);
}
//*--------------------------------------------------------------------------------------
//* Function Name : main
//* Object :
//*--------------------------------------------------------------------------------------
int main ( void )
{
unsigned int fir =0;
char data[MSG_SIZE];
unsigned int length;
// Enable User Reset and set its minimal assertion to 960 us
AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24);
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, 1<<23);
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, 1<<23);
AT91F_USB_Open();
while (!pCDC.IsConfigured(&pCDC));
while (1)
{ // Loop
length = pCDC.Read(&pCDC, data, MSG_SIZE);
data[length]=0;
// 测试用的标志
//AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, 1);
if (fir==0)
{
pCDC.Write(&pCDC, data,length);
fir=1;
}
else
{
pCDC.Write(&pCDC, data,length);
fir=0;
}
//AT91F_PIO_SetOutput(AT91C_BASE_PIOA, 1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -