新唐ARM芯片NuMicro M051单片机的资料太少了,根本没有资料可以参考,只能根据数据手册对寄存器编程,定时器1跑了起来。经验证正确0603
#include "SmartM_M0.h"
unsigned char i;
VOID TMR1Init(VOID)
{
PROTECT_REG
(
APBCLK |= 0x08; //定时器1时钟使能
CLKSEL1 |= 0x4000; //定时器1时钟选择外部高速晶振0X000,内部22为0X4000
IPRSTC2 |= 0x40; //TIMER1先复位
IPRSTC2 &= 0xFB; //定时器1正常工作
TCSR1 &= 0x18FFFF00;//先清0
TCSR1 |= 0x6C000000; //赋值:计数开始、使能定时器中断、周期模式、重置预分频值、
TCMPR1 = 12000*50; //设置比较值 [0~16777215]
NVIC_ISER |= 0x0200; //TMR0_INT;
)
}
INT32 main(VOID)
{
// unsigned char i;
PROTECT_REG
(
PWRCON |= XTL12M_EN;
while((CLKSTATUS & XTL12M_STB) == 0);
CLKSEL0 = (CLKSEL0 & (~HCLK)) | HCLK_12M;
P2_PMD=0x5555;
P2_DOUT = 0xff;
)
TMR1Init();
while(1)
{
if(i>7)
i= 0;
}
}
VOID TMR1_IRQHandler(VOID)
{
TISR1 = 1;
P2_DOUT = ~(1UL<<i);
i++;
}