text1.c

来自「几个关于lpc2103开发板的keil例程」· C语言 代码 · 共 88 行

C
88
字号
#include<lpc2103.h>
#include<stdio.h>
#define f (15000000/115200/16)
void init()
{
	PINSEL0=0x5;			//设置串口
	U0FCR=0x7;
	U0LCR=0x83;
	U0DLL=f%256;
	U0DLM=f/256;
	U0LCR=0x3;

	CCR=0x10;				  //使用外部晶振  初始化
//	YEAR=2009;
//	MONTH=5 ;
//	DOW=2;
//	DOM=2	;
//	HOUR=10;
//	MIN=1;
//	SEC=0 ;
	CIIR=0x01;
	CCR=0x11;
}
void send(char q)
{
	U0THR=q;
	while((U0LSR&0x40)==0);
}
void gettime()
{
	unsigned int time,day, temp;
	char const numtable[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
	time=CTIME0;
	day=CTIME1;
	
	temp=(day>>16 )&0xfff;			//显示年
	send(numtable[temp/1000]);
	temp=temp%1000;
	send(numtable[temp/100]);
	temp=temp%100;
	send(numtable[temp/10]);
	send(numtable[temp%10]);
	send(0x2d);

	temp=(day>>8)&0x0f;				//显示月
	send(numtable[temp/10]);
	send(numtable[temp%10]);
		send(0x2d);

	temp=day&0x1f;					   //显示日期
	send(numtable[temp/10]);
	send(numtable[temp%10]);
		send(0x2d);

	temp=(time>>24)&0x07;				//显示星期
	 send(numtable[temp]);
	 	send(0x2d);

	 temp=(time>>16)&0x1f;				//显示小时
	 send(numtable[temp/10]);
	send(numtable[temp%10]);
		send(0x2d);

	temp=(time>>8)&0x3f;				 //显示分
	send(numtable[temp/10]);
	send(numtable[temp%10]);
		send(0x2d);

	temp=time&0x3f;
	send(numtable[temp/10]);			 //显示秒
	send(numtable[temp%10]);
		send(0x0a);
	


}
int main()
{
	 init();
	 while(1)
	 {
	 	while((ILR&0x01)==0);			//等待外部中断
		ILR=0x01;						//清除中断
		gettime();

	 }
	 return 0;
}

⌨️ 快捷键说明

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