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

📄 proj_6.c

📁 0-9999计数器--4位数数码管 单片机
💻 C
字号:


//ZC-51学习板实验源程序
//0-9999计数器--4位数数码管
//http://www.ednchina.com/blog/zhichengdz/
//E-mail: zhicheng_dz@163.com


#include <reg52.h>

#define uchar unsigned char
#define uint  unsigned int
#define ulong unsigned long

//74HC164
sbit SDA_164=P1^0;
sbit SCLK_164=P1^1;
sbit DIG1=P1^2;
sbit DIG2=P1^3;
sbit DIG3=P1^4;
sbit DIG4=P1^5;

uchar counter;
uint cout2;
bit b_disp,b_flash;

uchar code LedNumber[14]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80,0x00,0x04,0x5c};

void delay(int i,int j)
{
	int m;
	for(;i>0;i--)
	{
		m=j;
		for(;m>0;m--);
	}
}

void wirteByte_74164 (uchar ch)
{	
	uchar i;
	SCLK_164 = 0;
	for (i=0;i<8;i++)
	{
		SDA_164 = ch&0x80;
		SCLK_164 = 1;
		ch = ch<<1;
		SCLK_164 = 0;
	}
}


void led_display (uint m)
{	uchar ch;
	ch=(uchar) (m%10);
	wirteByte_74164 (LedNumber[ch]);
	DIG4 = 0;
	delay(20,10);
	DIG4 = 1;
	
	ch=(uchar) (m%100/10);
	wirteByte_74164 (LedNumber[ch]);
	DIG3 = 0;
	delay(20,10);
	DIG3 = 1;
	
	ch=(uchar) (m%1000/100);
	wirteByte_74164 (LedNumber[ch]);
	DIG2 = 0;
	delay(20,10);
	DIG2 = 1;

	ch=(uchar) (m%10000/1000);
	wirteByte_74164 (LedNumber[ch]);
	DIG1 = 0;
	delay(20,10);
	DIG1 = 1;
}

void Time0 (void) interrupt 1
{
	TH0=-(15000/256); 
	TL0=-(15000%256);
	b_disp = ~b_disp;
	counter++;
	if (counter>=25)
	{
		counter=0;
		cout2++;
		b_flash = ~b_flash;
	}

}

void main ()
{
	ET0=1;
	TMOD=0x01;
	EA=1;

	TH0=-(15000/256);
	TL0=-(15000%256);
	TR0=1;

	while (1)
	{	if (b_disp)
		{
			led_display (cout2);
		}
	}	
}

⌨️ 快捷键说明

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