Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "NUC100Series.h"
- #include "MCU_init.h"
- #include "SYS_init.h"
- #define TIMER0_COUNT 5
- int main(void)
- {
- //System initialization start-------------------
- SYS_UnlockReg();
- CLK->PWRCON |= (1ul << 0); //12 MHz clock
- while(!(CLK->CLKSTATUS & (1ul << 0))); //wait for clock
- CLK->CLKSEL0 &= ~(0x07ul << 0); //set HCLK source as 12MHz clock
- CLK->CLKDIV &= ~(0xFul); //reset prescale
- //GPIO initialization start --------------------
- PC->PMD &= ~(0x03ul << 24);
- PC->PMD |= (0x01ul << 24); //GPIOC.12: output push-pull the LED
- //Setup GPIOB9 with timer1
- SYS->GPB_MFP |= (0x1ul<<9); //GPB[9] is 1
- SYS->ALT_MFP |= ~(0x1ul<<1); //ALT_MFP[1] is 0
- //Timer 1 initialization start--------------
- CLK->CLKSEL1 &= ~(0x07ul << 12);
- CLK->CLKSEL1 |= (0x02ul << 12); //select TMR1 to use HCLK
- CLK->APBCLK |= (0x01ul << 3); //configure APBCLK for TMR1
- TIMER1->TCSR &= ~(0xFFul << 0); //reset prescale
- TIMER1->TCSR |= 2; //TMR1 will use HCLK/3
- TIMER1->TCSR &= ~(0x3ul << 27);
- TIMER1->TCSR |= (3 << 27);
- TIMER1->TCSR |= (0x01ul << 26); //reset Timer1 count
- TIMER1->TCSR |= (0x1ul << 24); //enable timer counter mode (in order to use event counter)
- TIMER1->TCSR |= (0x01ul << 16); //TDR to be updated continuously while timer counter is counting
- TIMER1->TEXCON |= (0x1ul<<0); //1 = A rising edge of external count pin will be counted.
- TIMER1->TEXCON |= (0x01ul<<1); //01 = a 0 to 1 transition on TEX will be detected
- TIMER1->TEXCON |= (0x01ul<<3); //1 = The transition detected on the TEX pin will result in capture or reset of timer counter
- TIMER1->TEXCON &= ~(0x1ul<<4); //1: reset, 0: capture
- //TIMER1->TEXCON |= (0x1ul<<7); //Timer Counter Pin De-bounce Enable
- TIMER1->TCSR |= (1<<30); //start timer
- SYS_LockReg(); // Lock protected registers
- while(1){
- while((TIMER1->TDR)%5 != 0)); //while count not multiple of 5
- PC->DOUT ^= (0x1ul<<12); //toggle GPIOC12
- TIMER1->TCSR |= (0x01ul << 26); //reset Timer1 count
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement