measure_freq.c

来自「51系列单片机实验课程:按键显示程序 (在数字键上按数字」· C语言 代码 · 共 88 行

C
88
字号
#include <AT89x52.h>

code unsigned char LedCode[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
code unsigned char LedPosit[] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned int freq;
unsigned char timeloop;

void delay (unsigned int Dat)
{
	unsigned int i;
	for(i=0;i<Dat;i++);
}

void SegLock (void)
{
	P1_3 = 1;
	P1_3 = 0;
}

void PositLock (void)
{
	P1_2 = 1;
	P1_2 = 0;
}

void nodisp (void)
{
	P0 = 0;
	P1_2 = 1;
	P1_2 = 0;
}

void Display (void)
{
	P0 = LedCode[freq/100];
	SegLock();
	P0 = LedPosit[5];
	PositLock();
	delay(200);
	nodisp();
	
	P0 = LedCode[(freq%100)/10];
	SegLock();
	P0 = LedPosit[6];
	PositLock();
	delay(200);
	nodisp();
	
	P0 = LedCode[freq%10];
	SegLock();
	P0 = LedPosit[7];
	PositLock();
	delay(200);
	nodisp();
}

void main (void)
{
	EA = 0;
	TMOD = 0x15;
	TL0=TH0 = 0;
	TL1 = 0x3c;
	TH1 = 0xb0;
	TR0 = 1;
	TR1 = 1;
	ET1 = 1;
	EA = 1;
	while (1)
		Display();
}

void T1_int (void) interrupt 3
{
	TR0 = 0;
	TR1 = 0;
	TH1 = 0x3c;
	TL1 = 0xb0;
	if (++timeloop == 20)
	{
		freq = TH0*256 + TL0;
		timeloop = 0;
		TH0 = 0;
		TL0 = 0;
	}
	TR0 = 1;
	TR1 = 1;
}

⌨️ 快捷键说明

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