Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-------------------------------------------------------------------------------------------------------------
- //This part provide Project Description, key functions, and other project-related information
- //Project :
- //Author :
- //Date :
- //Board : Nu-LB-NUC140
- //MCU : NUC140VE3CN
- //Functions :
- //
- //
- //-------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #include "NUC100Series.h"
- #include "MCU_init.h"
- #include "SYS_init.h"
- #define DELAYTIME 4000000
- #define BUZZER_DURATION 400000
- #define HXT_CLK 1ul<<0
- #define CLK_SEL_MASK (~(0x07ul<<0))
- #define PLL_CLK_SEL 0x02ul
- #define HXT_STATUS 1ul<<0
- #define PLL_STATUS 1ul<<2
- #define PLLCON_FB_DV_MASK (~(0x01FFul << 0))
- #define PLLCON_FB_DV_VAL 8
- #define CPUCLOCKDIVIDE 1
- void Delay_s(uint32_t count);
- int main(void) {
- uint32_t toggle = 0;
- uint32_t i = 0;
- SYS_UnlockReg(); // Unlock protected registers
- //Enable clock sources
- //HXT - External High frequency Crystal 12 MHz
- CLK->PWRCON |= HXT_CLK;
- while(!(CLK->CLKSTATUS & HXT_STATUS));
- //PLL configuration starts
- CLK->PLLCON &= ~(1ul<<19); //0: PLL input is HXT 12MHz (default). 1: PLL input is HIRC 22MHz
- CLK->PLLCON &= ~(1ul<<16); //0: PLL in normal mode. 1: PLL in power-down mode (default)
- CLK->PLLCON &= PLLCON_FB_DV_MASK;
- CLK->PLLCON |= PLLCON_FB_DV_VAL; //frequency: 1 MHz * (PLLCON_FB_DV_VAL+2)
- CLK->PLLCON &= ~(1ul<<18); //0: enable PLL clock out. 1: disable PLL clock (default)
- while(!(CLK->CLKSTATUS & PLL_STATUS));
- //PLL configuration ends
- //clock source selection
- CLK->CLKSEL0 &= CLK_SEL_MASK;
- CLK->CLKSEL0 |= PLL_CLK_SEL;
- //clock frequency division
- CLK->CLKDIV &= ~0x0Ful;
- CLK->CLKDIV |= (CPUCLOCKDIVIDE-1);
- SYS_LockReg(); // Lock protected registers
- //PC->PMD &= ~(0x03ul)<< 24;
- //PC->PMD |= (0x01ul) << 24;
- PB->PMD &= ~(0x03ul)<< 22;
- PB->PMD |= (0x01ul) << 22;
- //PB->PMD &= ~(0x03ul)<< 30;
- //PB->PMD |= (0x01ul) << 30;
- while(1){
- if (!(PB->PIN & (0x01<<15))) {
- if (toggle == 0)
- toggle = 1;
- else
- toggle = 0;
- //toggle = !toggle;
- }
- else if (toggle == 1) {
- for (i = 0; i < 3; i++) {
- if ((PB->PIN & (0x01<<15))) {
- PB->DOUT ^= 1 << 11;
- if ((PB->PIN & (0x01<<15)))
- Delay_s(BUZZER_DURATION);
- else
- continue;
- PB->DOUT ^= 1 << 11;
- if (i != 2) {
- if ((PB->PIN & (0x01<<15)))
- Delay_s(BUZZER_DURATION);
- else
- continue;
- }
- }
- else
- continue;
- }
- if ((PB->PIN & (0x01<<15)))
- Delay_s(DELAYTIME - 400000);
- else
- continue;
- }
- Delay_s(400000);
- }
- }
- void Delay_s(uint32_t count){
- uint32_t n;
- for(n=0;n<count;n++);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement