Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "NUC100Series.h"
  3. #include "MCU_init.h"
  4. #include "SYS_init.h"
  5.  
  6. #define TIMER0_COUNT 5
  7.  
  8. int main(void)
  9. {
  10. //System initialization start-------------------
  11. SYS_UnlockReg();
  12.  
  13. CLK->PWRCON |= (1ul << 0); //12 MHz clock
  14. while(!(CLK->CLKSTATUS & (1ul << 0))); //wait for clock
  15.  
  16. CLK->CLKSEL0 &= ~(0x07ul << 0); //set HCLK source as 12MHz clock
  17. CLK->CLKDIV &= ~(0xFul); //reset prescale
  18.  
  19. //GPIO initialization start --------------------
  20. PC->PMD &= ~(0x03ul << 24);
  21. PC->PMD |= (0x01ul << 24); //GPIOC.12: output push-pull the LED
  22.  
  23. //Setup GPIOB9 with timer1
  24. SYS->GPB_MFP |= (0x1ul<<9); //GPB[9] is 1
  25. SYS->ALT_MFP |= ~(0x1ul<<1); //ALT_MFP[1] is 0
  26.  
  27. //Timer 1 initialization start--------------
  28. CLK->CLKSEL1 &= ~(0x07ul << 12);
  29. CLK->CLKSEL1 |= (0x02ul << 12); //select TMR1 to use HCLK
  30. CLK->APBCLK |= (0x01ul << 3); //configure APBCLK for TMR1
  31.  
  32. TIMER1->TCSR &= ~(0xFFul << 0); //reset prescale
  33. TIMER1->TCSR |= 2; //TMR1 will use HCLK/3
  34.  
  35. TIMER1->TCSR &= ~(0x3ul << 27);
  36. TIMER1->TCSR |= (3 << 27);
  37. TIMER1->TCSR |= (0x01ul << 26); //reset Timer1 count
  38. TIMER1->TCSR |= (0x1ul << 24); //enable timer counter mode (in order to use event counter)
  39. TIMER1->TCSR |= (0x01ul << 16); //TDR to be updated continuously while timer counter is counting
  40.  
  41. TIMER1->TEXCON |= (0x1ul<<0); //1 = A rising edge of external count pin will be counted.
  42. TIMER1->TEXCON |= (0x01ul<<1); //01 = a 0 to 1 transition on TEX will be detected
  43. TIMER1->TEXCON |= (0x01ul<<3); //1 = The transition detected on TEX pin results in capture/reset of timer counter
  44. TIMER1->TEXCON &= ~(0x1ul<<4); //1: reset, 0: capture
  45. //TIMER1->TEXCON |= (0x1ul<<7); //Timer Counter Pin De-bounce Enable
  46.  
  47. TIMER1->TCSR |= (1<<30); //start timer
  48.  
  49. SYS_LockReg(); // Lock protected registers
  50.  
  51. while(1){
  52. //while(!(TIMER1->TDR==5)); //wait for interrupt generated when timer reaches TCMPR=5 //MAZEN LOOK AT THiS ILNE OF CODE
  53. PC->DOUT ^= (0x1ul<<12); //toggle GPIOC12
  54. TIMER1->TCSR |= (0x01ul << 26); //reset Timer1 count
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement