timer2.c

来自「NorFlash bootloader(SPANSION_S71WS256ND0」· C语言 代码 · 共 39 行

C
39
字号
#include <stdio.h>
#include "common.h"

#define TCTL2		0x10004000
#define TPRER2		0x10004004
#define TCMP2		0x10004008
#define TCR2		0x1000400C
#define TCN2		0x10004010
#define TSTAT2		0x10004014

void GPT2Init (void)
{
	*(volatile P_U32) TCTL2	= 0x00000000;		// disable timer1
	*(volatile P_U32) TSTAT2 = 0x00000000;		// clear any previous compare event
	*(volatile P_U32) TPRER2 = 0x00000000;		// Set timer prescaler

	*(volatile P_U32) TCTL2	= 0x1;
	*(volatile P_U32) TCTL2	|= 0x00008000;			// set SWR
	*(volatile P_U32) TCTL2	= 0x00000002;		// disable timer1

	*(volatile P_U32) TCMP2	= 	9-1;	// 1/8.3125M * 9 = 1.08us

	*(volatile P_U32) TCTL2	= 	0x00000003;		// bit 4 : enable timer interrupt
														// bit 3..1 : 100 Clock source = 32KHz
														// bit 0 : enable timer
}

void Delay1us (void)
{
	U32 i=1;
	while (i)
		if (*(volatile P_U32) TSTAT2 & 0x1)
		{
			*(volatile P_U32) TSTAT2 &= ~0x1;
			i--;
		}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?