/*---------------------------------------------------------------------------------------------------------*/ int main(void) { //Initial System SYS_Init(); //Enable Timer0 clock and select Timer0 clock source CLK_EnableModuleClock(TMR0_MODULE); CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0SEL_HXT, 0); //Initial Timer0 to periodic mode with 2Hz TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 2); //Enable Timer0 interrupt TIMER_EnableInt(TIMER0); NVIC_EnableIRQ(TMR0_IRQn); //Initial 7-Segment Open_Seven_Segment(); //Start Timer0 TIMER_Start(TIMER0); while(1) { Show_Seven_Segment(TimerCounter / 10, 1); CLK_SysTickDelay(200); Show_Seven_Segment(TimerCounter % 10, 2); CLK_SysTickDelay(200); } }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { volatile uint32_t u32InitCount; /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); init_neuron_system(); init_block(); while(1) { // protocol. parse_uart0_recv_buffer(); flush_uart1_to_uart0(); flush_uart0_local_buffer(); // led poll_led_request(); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("+---------------------------------------+\n"); printf("| MINI58 System Driver Sample Code |\n"); printf("+---------------------------------------+\n"); /* Unlock protected registers for Brown-Out Detector settings */ SYS_UnlockReg(); /* Check if the write-protected registers are unlocked before BOD setting and CPU Reset */ if(SYS_IsRegLocked() == 0) { printf("Protected Address is Unlocked\n"); } /* Run PLL Test */ SYS_PLL_Demo(); printf("Exit\n"); while(1); }
int main(void) { uint32_t u32Item; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); do{ TestItem(); u32Item = getchar(); printf("%c\n",u32Item); switch(u32Item) { case '1': UART_FunctionTest(); break; case '2': IrDA_FunctionTest(); break; case '3': RS485_FunctionTest(); break; case '4': LIN_FunctionTest(); break; case '5': AutoFlow_FunctionTest(); break; case '6': LIN_FunctionTestUsingLinCtlReg(); break; default: break; } }while(u32Item != 27); }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %d Hz\n", SystemCoreClock); printf("+-------------------------------------------------------+\n"); printf("| GPIO Power-Down and Wake-up by PB.3 Sample Code |\n"); printf("+-------------------------------------------------------+\n\n"); /* Configure PB.3 as Input mode and enable interrupt by rising edge trigger */ GPIO_SetMode(PB, BIT3, GPIO_PMD_INPUT); GPIO_EnableInt(PB, 3, GPIO_INT_RISING); NVIC_EnableIRQ(GPAB_IRQn); /* Waiting for PB.3 rising-edge interrupt event */ while(1) { printf("Enter to Power-Down ......\n"); PowerDownFunction(); UART_WAIT_TX_EMPTY(UART0); printf("System waken-up done.\n\n"); } }
/*---------------------------------------------------------------------------------------------------------*/ int main (void) { /* Init System, IP clock and multi-function I/O */ SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register. /* Init UART for printf */ UART_Init(); printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("+-------------------------------------+ \n"); printf("| MINI51 GPIO Toggle Sample Code | \n"); printf("+-------------------------------------+ \n"); /*set P3.6 to output mode */ P3->PMD = (P3->PMD & ~0x3000) | (GPIO_PMD_OUTPUT << 12); P36 = 1; while(1) { P36 ^= 1; delay_loop(); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { uint32_t u32TrimInit; uint8_t Str[9]; /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); UART0_Init(); printf("\n"); printf("+--------------------------------------------------------+\n"); printf("| NuMicro USB Micro Printer Sample Code |\n"); printf("+--------------------------------------------------------+\n"); USBD_Open(&gsInfo, PTR_ClassRequest, NULL); /* Endpoint configuration */ PTR_Init(); USBD_Start(); #if CRYSTAL_LESS /* Backup init trim */ u32TrimInit = M32(TRIM_INIT); /* Enable USB crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); #endif NVIC_EnableIRQ(USBD_IRQn); PB->PMD = 0x5000; // PB.6, PB.7 output mode while(1) { #if CRYSTAL_LESS /* Re-start crystal-less when any error found */ if (SYS->HIRCTSTS & (SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk)) { SYS->HIRCTSTS = SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk; if((u32TrimInit < 0x1E6) || (u32TrimInit > 0x253)) /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (1 << SYS_HIRCTCTL_BOUNDARY_Pos); else /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); //printf("USB trim fail. Just retry. SYS->HIRCTSTS = 0x%x, SYS->HIRCTCTL = 0x%x\n", SYS->HIRCTSTS, SYS->HIRCTCTL); } #endif CLK_SysTickDelay(2000); // delay if(++Str[1] > 0x39) Str[1] = 0x30; // increase 1 to 10 than reset to 0 PB->DOUT ^= 0x40; // PB.6 } }
/** * * Initializes the clock system, board and USB. * Then runs the wireless task continuously. */ int main(void) { SYS_Init(); stdio_usb_init(); while (1) { } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); UART0_Init(); UART1_Init(); printf("\n\n"); printf("+------------------------------------------------------------+\n"); printf("| NuMicro USB Virtual COM Dual Port Sample Code |\n"); printf("+------------------------------------------------------------+\n"); USBD_Open(&gsInfo, VCOM_ClassRequest, NULL); /* Endpoint configuration */ VCOM_Init(); USBD_Start(); NVIC_EnableIRQ(USBD_IRQn); NVIC_EnableIRQ(UART0_IRQn); NVIC_EnableIRQ(UART1_IRQn); while(1) { VCOM_TransferData(); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { uint32_t au32Config[2]; /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); UART0_Init(); printf("\n\n"); printf("+-------------------------------------------------------------+\n"); printf("| NuMicro USB Virtual COM and MassStorage Sample Code |\n"); printf("+-------------------------------------------------------------+\n"); /* Enable FMC ISP function */ FMC_Open(); /* Check User Configuration. If not match, to re-define Data Flash size and to enable Data Flash function. */ FMC_ReadConfig(au32Config, 2); if(((au32Config[0] & 0x01) == 1) || (au32Config[1] != DATA_FLASH_BASE)) { FMC_EnableConfigUpdate(); FMC_Erase(FMC_CONFIG0_ADDR); au32Config[0] &= ~0x1; au32Config[1] = DATA_FLASH_BASE; if(FMC_WriteConfig(au32Config, 2) < 0) return -1; FMC_ReadConfig(au32Config, 2); if(((au32Config[0] & 0x01) == 1) || (au32Config[1] != DATA_FLASH_BASE)) { printf("Error: Program Config Failed!\n"); /* Disable FMC ISP function */ FMC_Close(); return -1; } /* Reset Chip to reload new CONFIG value */ SYS->IPRST0 = SYS_IPRST0_CHIPRST_Msk; } printf("NuMicro USB MassStorage Start!\n"); USBD_Open(&gsInfo, VCOM_MSC_ClassRequest, NULL); USBD_SetConfigCallback(MSC_SetConfig); /* Endpoint configuration */ VCOM_MSC_Init(); USBD_Start(); NVIC_EnableIRQ(USBD_IRQn); NVIC_EnableIRQ(UART0_IRQn); while(1) { VCOM_TransferData(); MSC_ProcessCmd(); } }
int main() { /* Unlock protected register */ SYS_UnlockReg(); SYS_Init(); UART_Init(); printf("\n\n"); printf("M451 FMC IAP Sample Code [LDROM code]\n"); /* Enable FMC ISP function */ FMC_Open(); printf("\n\nPress any key to branch to APROM...\n"); getchar(); printf("\n\nChange VECMAP and branch to LDROM...\n"); UART_WAIT_TX_EMPTY(UART0); /* Mask all interrupt before changing VECMAP to avoid wrong interrupt handler fetched */ __set_PRIMASK(1); /* Change VECMAP for booting to APROM */ FMC_SetVectorPageAddr(FMC_APROM_BASE); /* Lock protected Register */ SYS_LockReg(); /* Software reset to boot to APROM */ NVIC_SystemReset(); while(1); }
int main(void) { int i = 0; /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SYS_Init(); /* Init UART to 115200-8n1 for print message */ UART_Open(UART0, 115200); /*Initial Timer0 to periodic mode with 1Hz */ TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 1); /* Enable timer wake up system */ TIMER_EnableWakeup(TIMER0); /* Enable Timer0 interrupt */ TIMER_EnableInt(TIMER0); NVIC_EnableIRQ(TMR0_IRQn); /* Start Timer0 counting */ TIMER_Start(TIMER0); /* Unlock protected registers */ SYS_UnlockReg(); while(1) { CLK_PowerDown(); printf("Wake %d\n", i++); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART to 115200-8n1 for print message */ UART0_Init(); printf("\n\nCPU @ %dHz(PLL@ %dHz)\n", SystemCoreClock, PllClock); printf("PWM0 clock is from %s\n", (CLK->CLKSEL2 & CLK_CLKSEL2_PWM0SEL_Msk) ? "CPU" : "PLL"); printf("+------------------------------------------------------------------------+\n"); printf("| PWM Driver Sample Code |\n"); printf("| |\n"); printf("+------------------------------------------------------------------------+\n"); printf(" This sample code will output PWM0 channel 0~3 with different\n"); printf(" frequency and duty, enable dead zone function of all PWM0 pairs.\n"); printf(" And also enable/disable PWM output every 1 second.\n"); printf(" I/O configuration:\n"); printf(" waveform output pin: PWM0_CH0(PC.0), PWM0_CH1(PC.1), PWM0_CH2(PC.2), PWM0_CH3(PC.3)\n"); /*Set Pwm mode as complementary mode*/ PWM_ENABLE_COMPLEMENTARY_MODE(PWM0); // PWM0 channel 0 frequency is 100Hz, duty 30%, PWM_ConfigOutputChannel(PWM0, 0, 100, 30); SYS_UnlockReg(); PWM_EnableDeadZone(PWM0, 0, 400); SYS_LockReg(); // PWM0 channel 2 frequency is 300Hz, duty 50% PWM_ConfigOutputChannel(PWM0, 2, 300, 50); SYS_UnlockReg(); PWM_EnableDeadZone(PWM0, 2, 200); SYS_LockReg(); // Enable output of PWM0 channel 0~3 PWM_EnableOutput(PWM0, 0xF); // Enable PWM0 channel 0 period interrupt, use channel 0 to measure time. PWM_EnablePeriodInt(PWM0, 0, 0); NVIC_EnableIRQ(PWM0P0_IRQn); // Start PWM_Start(PWM0, 0xF); while(1); }
int32_t main (void) { /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SYS_Init(); /* Init UART to 115200-8n1 for print message */ UART_Init(); printf("\nThis sample code demonstrate using WDT in pollign mode\n"); // WDT register is locked, so it is necessary to unlock protect register befor configure WDT while(SYS->RegLockAddr != 1) { SYS->RegLockAddr = 0x59; SYS->RegLockAddr = 0x16; SYS->RegLockAddr = 0x88; } // WDT timeout every 2^14 WDT clock, enable system reset WDT->WTCR = WDT_TIMEOUT_2POW14 | WDT_WTCR_WTE_Msk | WDT_WTCR_WTRE_Msk | WDT_WTCR_WTIE_Msk; while(1) { // WDT timeout flag set if(WDT->WTCR & WDT_WTCR_WTIF_Msk) { // Reset WDT and clear time out flag WDT->WTCR |= WDT_WTCR_WTR_Msk; printf("Reset WDT counter\n"); } } }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS->REGWRPROT = 0x59; SYS->REGWRPROT = 0x16; SYS->REGWRPROT = 0x88; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS->REGWRPROT = 0x0; /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\n\nUART Sample Program\n"); /* UART RS485 sample master function */ RS485_9bitModeMaster(); while(1); }
void PDMA_Example() { uint8_t unItem; /* Init System, IP clock and multi-function I/O */ SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register. /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for PDMA test */ UART1_Init(); do { /* PDMA Sample Code: UART1 Tx/Rx Loopback */ // printf("\n\n"); printf("+------------------------------------------------------------------------+\n"); printf("| PDMA Driver Sample Code |\n"); printf("| |\n"); printf("+------------------------------------------------------------------------+\n"); printf("| [1] Using TWO PDMA channel to test. < TX1(CH1)-->RX1(CH0) > |\n"); printf("| [2] Using ONE PDMA channel to test. < TX1-->RX1(CH0) > |\n"); printf("+------------------------------------------------------------------------+\n"); unItem = uart_getchar(); IsTestOver =FALSE; if((unItem=='1') || (unItem == '2')) { PDMA_UART(unItem); // printf("\n\n PDMA sample code is complete.\n"); } }while(unItem!=0x27); // return 0; }
int main(void) { /* Unlock protected registers */ SYS->REGWRPROT = 0x59; SYS->REGWRPROT = 0x16; SYS->REGWRPROT = 0x88; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS->REGWRPROT = 0x0; /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\n\nUART Sample Program\n"); /* UART auto flow sample slave function */ AutoFlow_FunctionRxTest(); while(1); }
int32_t main (void) { /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SYS_Init(); /* Init UART to 115200-8n1 for print message */ UART_Open(UART0, 115200); printf("\nThis sample code demonstrate using WDT in polling mode\n"); // WDT register is locked, so it is necessary to unlock protect register before configure WDT SYS_UnlockReg(); // WDT timeout every 2^14 WDT clock, disable system reset, disable wake up system WDT_Open(WDT_TIMEOUT_2POW14, 0, FALSE, FALSE); while(1) { // WDT timeout flag set if(WDT_GET_TIMEOUT_INT_FLAG()) { // Reset WDT and clear time out flag WDT_CLEAR_TIMEOUT_INT_FLAG(); printf("Reset WDT counter\n"); } } }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\n\nUART Sample Program\n"); /* UART RS485 sample master function */ RS485_FunctionTest(); while(1); }
int main(void) { char strClearLine[15] = "ID: "; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); printf("CPU @ %dHz\n", SystemCoreClock); /* Init SPI0 and LCD */ LCD_Init(); LCD_EnableBackLight(); LCD_ClearScreen(); LCD_Print(0, "SPI Sample Code "); LCD_Print(1, "For Flash Test"); LCD_Print(2, "Press INT button"); /* Init P3.2 */ GPIO_Init(); SPIFLASH_Init(); sprintf(g_strBuf, "ID:%x ", SPIFLASH_ReadId()&0xFFFFUL); LCD_Print(3, strClearLine); LCD_Print(3, g_strBuf); while (!g_isPress); SpiTest(); return 1; }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { int32_t i; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); /* This is a simple sample code for LDROM in new IAP mode. The base address is 0x100000. The base address for function table is defined by FUN_TBL_BASE. */ printf("+------------------------------------------------------------------+\n"); printf("| M05xx Flash Memory Controller Driver Sample Code for LDROM |\n"); printf("+------------------------------------------------------------------+\n"); printf("\nCPU @ %dHz\n\n", SystemCoreClock); // Delay 3 seconds for(i = 0; i < 30; i++) { printf("."); SysTickDelay(10000); } printf("\n"); printf("Function table @ 0x%08x\n", g_funcTable); while(SYS->PDID)__WFI(); }
int main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf and testing */ UART0_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\n\nUART Sample Program\n"); /* UART sample function */ UART_FunctionTest(); }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { uint32_t u32IntCnts = 0; /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); printf("CPU @ %d Hz\n", SystemCoreClock); printf("+------------------------------------------+\n"); printf("| WDT Time-out Interrupt Sample Code |\n"); printf("+------------------------------------------+\n\n"); printf("# WDT Settings:\n"); printf(" - Clock source is 10 kHz \n"); printf(" - Time-out interval is 2^14 * WDT clock \n"); printf(" (around 1.6384 second) \n"); printf(" - Interrupt enable \n"); printf("# System will generate a WDT time-out interrupt event after around 1.6384 second.\n"); printf(" (Use PA.0 high/low period time to check WDT time-out interval)\n\n"); /* Use PA.0 to check time-out period time */ GPIO_SetMode(PA, BIT0, GPIO_PMD_OUTPUT); PA0 = 1; PA0 = 0; /* Because of all bits can be written in WDT Control Register are write-protected; To program it needs to disable register protection first. */ SYS_UnlockReg(); /* Select WDT time-out interval to 2^14 * WDT clock then start WDT counting */ g_u8IsWDTTimeoutINT = 0; WDT_Open(WDT_TIMEOUT_2POW14, 0, FALSE, FALSE); /* Enable WDT interrupt function */ WDT_EnableInt(); /* Enable WDT NVIC */ NVIC_EnableIRQ(WDT_IRQn); while(1) { /* Check if WDT time-out interrupt occurred or not */ while(g_u8IsWDTTimeoutINT == 0); g_u8IsWDTTimeoutINT = 0; PA0 ^= 1; printf("WDT time-out interrupt occurred. INT counts: %d \r", ++u32IntCnts); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART to 115200-8n1 for print message */ UART0_Init(); printf("+------------------------------------------------------------------------+\n"); printf("| PWM Driver Sample Code |\n"); printf("| |\n"); printf("+------------------------------------------------------------------------+\n"); printf(" This sample code will use PWM0 channel 0 to output waveform\n"); printf(" I/O configuration:\n"); printf(" waveform output pin: PWM0 channel 0(PA.12)\n"); printf("\nUse double buffer feature.\n"); /* PWM0 channel 0 waveform of this sample shown below: |<- CNR + 1 clk ->| CNR + 1 = 399 + 1 CLKs |<-CMR+1 clk ->| CMR + 1 = 199 + 1 CLKs |<- CNR + 1 ->| CNR + 1 = 99 + 1 CLKs |<CMR+1>| CMR + 1 = 39 + 1 CLKs __ ______________ _______ |______200_____| 200 |____60__| 40 |_____PWM waveform */ /* Configure PWM0 channel 0 init period and duty. Period is __HXT / (prescaler * clock divider * (CNR + 1)) Duty ratio = (CMR + 1) / (CNR + 1) Period = 12 MHz / (2 * 1 * (199 + 1)) = 30000 Hz Duty ratio = (99 + 1) / (199 + 1) = 50% */ // PWM0 channel 0 frequency is 100Hz, duty 30%, PWM_ConfigOutputChannel(PWM0, 0, 30000, 30); // Enable output of PWM0 channel 0 PWM_EnableOutput(PWM0, PWM_CH_0_MASK); // Enable PWM0 channel 0 period interrupt, use channel 0 to measure time. PWM_EnablePeriodInt(PWM0, 0, 0); NVIC_EnableIRQ(PWM0_IRQn); // Start PWM_Start(PWM0, PWM_CH_0_MASK); while(1); }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { int32_t i32Err; /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %d Hz\n", SystemCoreClock); printf("+-------------------------------------------------+\n"); printf("| PB.2(Output) and PC.1(Input) Sample Code |\n"); printf("+-------------------------------------------------+\n\n"); /* Configure PB.2 as Output mode and PC.1 as Input mode */ PB->PMD = (PB->PMD & (~GPIO_PMD_PMD2_Msk)) | (GPIO_PMD_OUTPUT << GPIO_PMD_PMD2_Pos); PC->PMD = (PC->PMD & (~GPIO_PMD_PMD1_Msk)) | (GPIO_PMD_INPUT << GPIO_PMD_PMD1_Pos); i32Err = 0; printf("GPIO PB.2(output mode) connect to PC.1(input mode) ......"); /* Use Pin Data Input/Output Control to pull specified I/O or get I/O pin status */ /* Pull PB.2 to Low and check PC.1 status */ PB2 = 0; if(PC1 != 0) { i32Err = 1; } /* Pull PB.2 to High and check PC.1 status */ PB2 = 1; if(PC1 != 1) { i32Err = 1; } if(i32Err) { printf(" [FAIL].\n"); } else { printf(" [OK].\n"); } /* Configure PB.2 and PC.1 to default Quasi-bidirectional mode */ PB->PMD = (PB->PMD & (~GPIO_PMD_PMD2_Msk)) | (GPIO_PMD_QUASI << GPIO_PMD_PMD2_Pos); PC->PMD = (PC->PMD & (~GPIO_PMD_PMD1_Msk)) | (GPIO_PMD_QUASI << GPIO_PMD_PMD1_Pos); while(1); }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { uint32_t u32TrimInit; /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); UART0_Init(); printf("\n"); printf("+--------------------------------------------------------------+\n"); printf("| NuMicro USB Virtual COM and HID Keyboard Sample Code |\n"); printf("+--------------------------------------------------------------+\n"); printf("If PB.15 = 0, just report it is key 'a'.\n"); /* Set PB.15 as Quasi-bidirectional mode */ PB->PMD = (PB->PMD & ~GPIO_PMD_PMD15_Msk) | (GPIO_PMD_QUASI << GPIO_PMD_PMD15_Pos); USBD_Open(&gsInfo, HID_ClassRequest, NULL); /* Endpoint configuration */ HID_Init(); USBD_Start(); #if CRYSTAL_LESS /* Backup init trim */ u32TrimInit = M32(TRIM_INIT); /* Enable USB crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); #endif NVIC_EnableIRQ(USBD_IRQn); NVIC_EnableIRQ(UART02_IRQn); while(1) { #if CRYSTAL_LESS /* Re-start crystal-less when any error found */ if (SYS->HIRCTSTS & (SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk)) { SYS->HIRCTSTS = SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk; if((u32TrimInit < 0x1E6) || (u32TrimInit > 0x253)) /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (1 << SYS_HIRCTCTL_BOUNDARY_Pos); else /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); //printf("USB trim fail. Just retry. SYS->HIRCTSTS = 0x%x, SYS->HIRCTCTL = 0x%x\n", SYS->HIRCTSTS, SYS->HIRCTCTL); } #endif VCOM_TransferData(); HID_UpdateKbData(); } }
/*---------------------------------------------------------------------------------------------------------*/ int main (void) { uint8_t u8Item = 0x0; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("+------------------------------------+\n"); printf("| NUC200 RTC Driver Sample Code |\n"); printf("+------------------------------------+\n"); printf("\n"); /* Initial RTC to make RTC leaving reset state */ _RTC_INIT(); while (1) { if (_RTC_IS_ACTIVE()) break; } /* Set RTC start-up Date/Time */ SetRTCStartupDateTime(); do { printf("+-------------------------------------------------+ \n"); printf("| Select an item to test | \n"); printf("+-------------------------------------------------+ \n"); printf("| [0] RTC Date/Time test | \n"); printf("| [1] RTC Tick Interrupt test | \n"); printf("| [2] RTC Alarm and waken-up from Power Down test | \n"); printf("| [ESC] Quit | \n"); printf("+-------------------------------------------------+ \n"); printf("\n"); u8Item = getchar(); switch (u8Item) { case '0': RTC_DateTimeTest(); break; case '1': RTC_TickInterruptTest(); break; case '2': RTC_AlarmAndWakeupTest(); break; } } while (u8Item != 27); printf("\nExit RTC Sample Code. \n"); return 0; }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { uint32_t u32TrimInit; /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); UART0_Init(); printf("\n"); printf("+--------------------------------------------------------+\n"); printf("| NuMicro USB HID Keyboard Sample Code |\n"); printf("+--------------------------------------------------------+\n"); printf("If PB.15 = 0, just report it is key 'a'.\n"); USBD_Open(&gsInfo, HID_ClassRequest, NULL); /* Endpoint configuration */ HID_Init(); USBD_Start(); #if CRYSTAL_LESS /* Backup init trim */ u32TrimInit = M32(TRIM_INIT); /* Enable USB crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); #endif NVIC_EnableIRQ(USBD_IRQn); /* start to IN data */ g_u8EP2Ready = 1; while(1) { #if CRYSTAL_LESS /* Re-start crystal-less when any error found */ if (SYS->HIRCTSTS & (SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk)) { SYS->HIRCTSTS = SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk; if((u32TrimInit < 0x1E6) || (u32TrimInit > 0x253)) /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (1 << SYS_HIRCTCTL_BOUNDARY_Pos); else /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); //printf("USB trim fail. Just retry. SYS->HIRCTSTS = 0x%x, SYS->HIRCTCTL = 0x%x\n", SYS->HIRCTSTS, SYS->HIRCTCTL); } #endif HID_UpdateKbData(); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); /* Init PWM0 for DAC */ PWM0_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\nSystem clock rate: %d Hz", SystemCoreClock); /* DAC function test */ DAC_FunctionTest(); /* Disable External Interrupt */ NVIC_DisableIRQ(DAC_IRQn); /* Reset PDMA module */ SYS->IPRST0 |= SYS_IPRST0_PDMARST_Msk ; SYS->IPRST0 &= ~SYS_IPRST0_PDMARST_Msk ; /* Reset DAC module */ SYS->IPRST2 |= SYS_IPRST2_DACRST_Msk ; SYS->IPRST2 &= ~SYS_IPRST2_DACRST_Msk ; /* Reset PWM0 module */ SYS->IPRST2 |= SYS_IPRST2_PWM0RST_Msk ; SYS->IPRST2 &= ~SYS_IPRST2_PWM0RST_Msk ; /* Disable PDMA module clock */ CLK->AHBCLK &= ~CLK_AHBCLK_PDMACKEN_Msk; /* Disable PWM0 IP clock */ CLK->APBCLK1 &= ~CLK_APBCLK1_PWM0CKEN_Msk; /* Disable DAC IP clock */ CLK->APBCLK1 &= ~CLK_APBCLK1_DACCKEN_Msk; printf("Stop DAC output and exit DAC sample code\n"); while(1); }
/*---------------------------------------------------------------------------------------------------------*/ int TIMER_Example(void) { SYS_Init() ; GPIO_Init() ; Timer0_Timer1_Timer2_Init() ; while(1){ } }