⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于LCP21xx的频率测量程序
💻 C
字号:
#include <lpc21xx.h>
#include <stdio.h>

#define Fosc            11059200

#define BIT(bt)          (1<<bt)
#define T0CTCR          (*((volatile unsigned long *) 0xE0004070))
#define T1CTCR          (*((volatile unsigned long *) 0xE0008070))
#define RS				(1<<29)
#define RW				(1<<30)
#define EN				(1<<31)
#define DATA			(0xff<<16)

char t[50];
volatile unsigned int counter;

void __attribute__ ((interrupt)) Time0 ();    // Generate Interrupt
void	Delay();
void	Init();
void	LcdWrite(char dat,char cmd);
void	SetXY(char X, char Y);
void	LCDInit();
void	disp();

int main(void)
{
	Init();
	LCDInit();
	U0IER = 0x01;
	T0TCR = 0x01;
	T1TC=0;
	while(1)
	{
	sprintf(t,"CAP: %6dHz\n",counter*10);
	SetXY(0,0);
	disp(t);
	}
	return 0;
}



void	Delay(unsigned int i)
{
	while(i--)	 ;
}


void Init()
{

	PINSEL0=(1<<21);	

	VICIntSelect =0;

	T0TC=0;							//初值0
	T0PR=0;							//分频 0
	T0MCR=0x03;						//触发中断 复位
	T0MR0=Fosc/10;					//10Hz
		
	VICVectCntl1=0x20|4;
	VICVectAddr1=(int)Time0;
	VICIntEnable|=1<<4;


	T1TC=0;							//初值0
	T1PR=0;							//分频
	T1CTCR=1;						//捕捉 CAP1.0
	T1TCR = 0x01;					//使能
}

void LcdWrite(char dat,char cmd)
{
IO0CLR=RW|RS|EN;
IO1CLR=DATA;
IO1SET=dat<<16;
if(cmd==0)	IO0SET=EN;
else		IO0SET=RS|EN;
Delay(5000);
IO0CLR=EN;
}

void SetXY(char X, char Y) 
{
char address = (Y == 0) ? (0x80 + X) : (0xc0 + X);
	LcdWrite(address,0);
}
void LCDInit()
{
PINSEL1=0;
PINSEL2=0;	   
IO0DIR|=RW|RS|EN;
IO1DIR|=DATA;
LcdWrite(0x38,0);
LcdWrite(0x0C,0);
LcdWrite(0x01,0);
LcdWrite(0x06,0);
}
void disp(char *str)
{
	while (1)
	{
		if (*str == '\0')	break;		// 遇到结束符,退出
		LcdWrite(*str++,1);			// 发送数据
	}
}

 void __attribute__ ((interrupt)) Time0 (void)    // Generate Interrupt
{

	counter=T1TC;
	T1TC=0;
	T0IR=1;
	VICVectAddr = 0x00;			// 中断处理结束
}

⌨️ 快捷键说明

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