Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.02 KB | None | 0 0
  1. //-------------------------------------------------------------------------------------------------------------
  2. //This part provide Project Description, key functions, and other project-related information
  3. //Project     :
  4. //Author      :
  5. //Date        :
  6. //Board       : Nu-LB-NUC140
  7. //MCU         : NUC140VE3CN
  8. //Functions   :
  9. //
  10. //
  11. //-------------------------------------------------------------------------------------------------------------
  12.  
  13.  
  14. #include <stdio.h>
  15. #include "NUC100Series.h"
  16. #include "MCU_init.h"
  17. #include "SYS_init.h"
  18.  
  19.  
  20. #define DELAYTIME 4000000
  21.  
  22. #define BUZZER_DURATION 400000
  23.  
  24. #define HXT_CLK 1ul<<0
  25.  
  26. #define CLK_SEL_MASK (~(0x07ul<<0))
  27.  
  28. #define PLL_CLK_SEL 0x02ul
  29.  
  30. #define HXT_STATUS 1ul<<0
  31.  
  32. #define PLL_STATUS 1ul<<2
  33.  
  34. #define PLLCON_FB_DV_MASK (~(0x01FFul << 0))
  35.  
  36. #define PLLCON_FB_DV_VAL 8
  37.  
  38. #define CPUCLOCKDIVIDE 1
  39.  
  40. void Delay_s(uint32_t count);
  41.  
  42. int main(void) {
  43.     uint32_t toggle = 0;
  44.     uint32_t i = 0;
  45.     SYS_UnlockReg(); // Unlock protected registers          
  46.     //Enable clock sources    
  47.     //HXT - External High frequency Crystal 12 MHz    
  48.     CLK->PWRCON |= HXT_CLK;    
  49.     while(!(CLK->CLKSTATUS & HXT_STATUS));          
  50.     //PLL configuration starts    
  51.     CLK->PLLCON &= ~(1ul<<19);   //0: PLL input is HXT 12MHz (default). 1: PLL input is HIRC 22MHz    
  52.     CLK->PLLCON &= ~(1ul<<16);  //0: PLL in normal mode. 1: PLL in power-down mode (default)    
  53.     CLK->PLLCON &= PLLCON_FB_DV_MASK;    
  54.     CLK->PLLCON |= PLLCON_FB_DV_VAL; //frequency: 1 MHz * (PLLCON_FB_DV_VAL+2)    
  55.     CLK->PLLCON &= ~(1ul<<18);  //0: enable PLL clock out. 1: disable PLL clock (default)        
  56.     while(!(CLK->CLKSTATUS & PLL_STATUS));    
  57.     //PLL configuration ends
  58.  
  59.  
  60.     //clock source selection    
  61.     CLK->CLKSEL0 &= CLK_SEL_MASK;    
  62.     CLK->CLKSEL0 |= PLL_CLK_SEL;              
  63.  
  64.     //clock frequency division    
  65.     CLK->CLKDIV &= ~0x0Ful;    
  66.     CLK->CLKDIV |= (CPUCLOCKDIVIDE-1);            
  67.  
  68.     SYS_LockReg();  // Lock protected registers      
  69.  
  70.     //PC->PMD &= ~(0x03ul)<< 24;    
  71.     //PC->PMD |= (0x01ul) << 24;
  72.     PB->PMD &= ~(0x03ul)<< 22;
  73.     PB->PMD |= (0x01ul) << 22;
  74.     //PB->PMD &= ~(0x03ul)<< 30;
  75.     //PB->PMD |= (0x01ul) << 30;
  76.  
  77.     while(1){        
  78.             if (!(PB->PIN & (0x01<<15))) {
  79.                     if (toggle == 0)
  80.                         toggle = 1;
  81.                     else
  82.                         toggle = 0;
  83.                     //toggle = !toggle;
  84.                 }
  85.             else if (toggle == 1) {
  86.                     for (i = 0; i < 3; i++) {
  87.                         if ((PB->PIN & (0x01<<15))) {
  88.                                 PB->DOUT ^= 1 << 11;
  89.                                 if ((PB->PIN & (0x01<<15)))
  90.                                     Delay_s(BUZZER_DURATION);
  91.                                 else
  92.                                     continue;
  93.                                 PB->DOUT ^= 1 << 11;
  94.                                 if (i != 2) {
  95.                                     if ((PB->PIN & (0x01<<15)))
  96.                                         Delay_s(BUZZER_DURATION);
  97.                                     else
  98.                                         continue;
  99.                                 }
  100.                             }
  101.                             else
  102.                                 continue;
  103.                         }
  104.                         if ((PB->PIN & (0x01<<15)))
  105.                             Delay_s(DELAYTIME - 400000);
  106.                         else
  107.                             continue;
  108.                 }
  109.                 Delay_s(400000);
  110.            
  111.     }
  112. }
  113.  
  114.  
  115. void Delay_s(uint32_t count){    
  116.     uint32_t n;    
  117.     for(n=0;n<count;n++);    
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement