请高人指点下怎样配置寄存器来操作定时器0的计数方式测脉冲宽度(调用函数库很影响速度在10US左右,所以要直接配置寄存器来操作),我按以下配置后无法使用,仿真时出现*** error 65: access violation at 0x4001000C : no 'read' permission
#include <stdio.h>
#include "NUC122.h"
#include "DrvGPIO.h"
void Delay(uint32_t delayCnt)
{
while(delayCnt--)
{
__NOP();
__NOP();
}
}
uint32_t GetTDR(void)
{
return TIMER0->TDR;
}
int32_t main (void)
{
uint32_t TEMP=0;
UNLOCKREG();
SYSCLK->PWRCON.XTL12M_EN = 1;
Delay(5000);
LOCKREG();
TIMER0->TCSR.DBGACK_TMR = 0;
NVIC_DisableIRQ(TMR0_IRQn); //Disable TIMER0 interrupt
outpw(&TIMER0->TCSR ,0 ); //Disable TIMER0
/* Step 1. Enable and Select Timer clock source */
SYSCLK->CLKSEL1.TMR0_S = 0; //Select =4(22Mhz) =0(12MHZ) for TIMER0 clock source
SYSCLK->APBCLK.TMR0_EN =1; //Enable TIMER0 clock source
/* Step 2. Select Operation mode */
TIMER0->TCSR.MODE=1; //Select periodic mode for operation mode
/* Step 3. Select Time out period = (Period of timer clock input) * (8-bit Prescale + 1) * (24-bit TCMP)*/
TIMER0->TCSR.PRESCALE=1; // Set Prescale [0~255]
TIMER0->TCMPR = 300000; // Set TCMPR [0~16777215]
// (1/12000000)*(1+1)*(3000000)= 500ms
/* Step 4. Enable interrupt */
// TIMER0->TCSR.IE = 1;
// TIMER0->TISR.TIF = 1; //Write 1 to clear for safty
// NVIC_EnableIRQ(TMR0_IRQn); //Enable TIMER0 Interrupt
/* Step 5. Enable Timer module */
TIMER0->TCSR.CRST = 1; //Reset up counter
TIMER0->TCSR.CEN = 1; //Enable TIMER0
TIMER0->TCSR.TDR_EN=1; // Enable TDR function
Delay(1000);
while(1)
{
TEMP = GetTDR(); //Get value of up counter
}
} |